dronir / bezier.jl Goto Github PK
View Code? Open in Web Editor NEWBezier curves in Julia
Bezier curves in Julia
Hi,
I was looking to implementing Bézier curves into one my projects and came across this project, which I see is already included on Pkg.jl
I see it uses Bernstein polynomials, and therefore the number of control points is limited. Maybe using the de Casteljau formula one can improve this limitation. Also, the de Casteljau method allows to easily extend to Bézier patches (I have a preliminary version of this).
Also, it might be a good idea to add dependency to GeometryBasics.jl (from JuliaGeometry) to handle the type of control points and return points. It has the advantage that plotting a vector of points is already implemented (see example below). Hence, I would propose:
using GeometryBasics
struct BezierCurve
control_points::Vector{Point}
end
function (curve::BezierCurve)(t::Real)
# Bezier curve using the de Casteljau algorithm
b = copy(curve.control_points)
while length(b) > 1
br = copy(b)
b = [(1-t)*br[i] + t*br[i+1] for i in 1:(length(br)-1)]
end
return b[1]
end
A MWE of use:
using Plots
control_points = Vector{Point}(undef,4)
control_points[1] = Point(0.0,1.0)
control_points[2] = Point(0.0,0.0)
control_points[3] = Point(2.0,0.0)
control_points[4] = Point(3.0,3.0)
curve = BezierCurve(control_points)
plot(curve.control_points, color=:gray,label="")
scatter!(curve.control_points, color=:gray,label="Control points")
points = [curve(t) for t in 0.0:1e-2:1.0]
plot!(points, color=:blue,label="Bezier curve")
There is the following warning (which should be resolved)
WARNING: using Plots.BezierCurve in module Main conflicts with an existing identifier.
Indeed Plots.jl already implements plotting Bézier curves with curves
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.