Giter VIP home page Giter VIP logo

bezier.jl's People

Contributors

dronir avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

bezier.jl's Issues

Changing from Bernstein polynomials to the de Casteljau algorithms

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

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.