Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "PolyCubicSpline2d" #98

Open
prange opened this issue May 12, 2019 · 2 comments
Open

Add "PolyCubicSpline2d" #98

prange opened this issue May 12, 2019 · 2 comments

Comments

@prange
Copy link

prange commented May 12, 2019

When drawing svg it is often the case that we want to draw smooth lines using Bezier curves. It would really be handy with a function to convert a polyline to a list of Bezier curves that are connected and where the control points make sense (based on some smoothing parameter perhaps)

and of course it would be really cool to have a corresponding function to render such a datatructure to svg.

What do you think?

@ianmackenzie
Copy link
Owner

Hey @prange! I've thought for a while it would be good to have a function in elm-geometry for constructing centripetal Catmull-Rom splines, which are a series of smoothly-connected cubic splines through a set of points. The API would probably be something likely

CubicSpline2d.centripetalCatmullRom : List Point2d -> List CubicSpline2d

although it might have to be a bit more complex to allow for different end conditions (free, clamped, closed etc.) Does that seem close to what you're looking for?

@ianmackenzie
Copy link
Owner

Or if we want to be a bit more opinionated, something like:

CubicSpline2d.interpolate : List Point2d -> List CubicSpline2d

CubicSpline2d.closed : List Point2d -> List CubicSpline2d

CubicSpline2d.interpolateWith : 
    { start : BoundaryCondition, end : BoundaryCondition }
    -> List Point2d
    -> List CubicSpline2d

-- zero curvature at the boundary
free : BoundaryCondition

-- fixed first derivative at the boundary
fixed : Vector2d -> BoundaryCondition

which you could use as

-- Create a centripetal Catmull-Rom curve through
-- the given points, with free ends
splines1 =
    CubicSpline2d.interpolate points

-- Create a closed-loop Catmull-Rom curve
-- through the given points
splines2 =
    CubicSpline2d.closed points

splines3 =
    CubicSpline2d.interpolateWith
        { start = CubicSpline2d.fixed v1, end = CubicSpline2d.free }
        points

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants