Coder Social home page Coder Social logo

r4333 / bezier.py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from torresjrjr/bezier.py

0.0 0.0 0.0 22 KB

➰ Create Bezier curves in Python [Mirror]

Home Page: https://sr.ht/~torresjrjr/Bezier.py/

License: GNU General Public License v3.0

Python 100.00%

bezier.py's Introduction

Bezier.py

Create Bezier curves in Python

Preview plots with matplotlib

An assortment of Bezier curves plotted with matplotlib.pyplot

14-point 3D Bezier curve:

14-point 3D Bezier curve

Usage

Save the main file Bezier.py into your local directory to import into your python code. Import Bezier and numpy and use. Bezier only has 1 class for now, so you can use this snippet:

from Bezier import Bezier
import numpy as np

Create a Bezier curve with parameter t and a numpy array of inital points points1 of any dimension. Here's a 2D example:

t_points = np.arange(0, 1, 0.01) #................................. Creates an iterable list from 0 to 1.
points1 = np.array([[0, 0], [0, 8], [5, 10], [9, 7], [4, 3]]) #.... Creates an array of coordinates.
curve1 = Bezier.Curve(t_points, points1) #......................... Returns an array of coordinates.

You can plot your creations with matplotlib.

import matplotlib.pyplot as plt

plt.figure()
plt.plot(
	curve1[:, 0],   # x-coordinates.
	curve1[:, 1]    # y-coordinates.
)
plt.plot(
	points1[:, 0],  # x-coordinates.
	points1[:, 1],  # y-coordinates.
	'ro:'           # Styling (red, circles, dotted).
)
plt.grid()
plt.show()

The result:

The resulting plot

See examples.py for more.

bezier.py's People

Contributors

torresjrjr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.