Coder Social home page Coder Social logo

simplifying a curve? about bezierkit HOT 2 CLOSED

hfutrell avatar hfutrell commented on August 19, 2024
simplifying a curve?

from bezierkit.

Comments (2)

hfutrell avatar hfutrell commented on August 19, 2024

@mbutterick what I believe is going on here is that in the the second image the tangent lines / derivatives match, but I think what you want is to scale those tangent lines so that the curvatures match at the endpoints.

The curvature is given by the first and second derivatives

k = | x' y'' - y' x'' | / (x'^2 + y'^2)^(3/2)

https://en.wikipedia.org/wiki/Curvature#Curvature_from_arc_and_chord_length

BezierKit doesn't have explicit support for this, and only has support for getting the first derivative. The second derivative for a cubic curve is linear, which can be obtained by taking the difference between the control points twice. Something like this

let d0 = curve.p1 - curve.p0
let d1 = curve.p2 - curve.p1
let d2 = curve.p3 - curve.p2
let dd0 = d1 - d0
let dd1 = d2 - d1
let secondDerivative = LineSegment(p0: 1.0 / 6.0 * dd0, p1: 1.0 / 6.0 * dd1)

A simpler approach that may work well enough would be to scale the length of the tangent lines by the ratio of the length of the new vs old curves. That way if the new curve is larger as in your example, it would get longer tangent lines. You could do that by comparing curve.length()

from bezierkit.

mbutterick avatar mbutterick commented on August 19, 2024

length is a good idea. Thanks.

from bezierkit.

Related Issues (20)

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.