Comments (2)
@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.
length
is a good idea. Thanks.
from bezierkit.
Related Issues (20)
- boundingBox vs boundingBoxOfPath follows opposite convention as CoreGraphics
- Hard to work with ends of simple, unclosed bezier path HOT 2
- Path and PathComponent hash and hashValue is simply memory address HOT 1
- Unknown references to BezierKit.min(...) and BezierKit.max(...) HOT 3
- Path.offset(distance:) hits assertion failure when called on a Path where all points are equal HOT 1
- Union of 2 overlapping paths returns an empty path HOT 4
- `union` with nonzero winding rule HOT 9
- Path.crossingRemoved() produces wrong result HOT 11
- `offset` seems to treat straight & curved segments differently HOT 3
- feature request: permit separate x and y inputs for scale, outline, reduce HOT 8
- this contour crashes `crossingsRemoved` HOT 9
- `crossingsRemoved` makes these two contours disappear HOT 12
- how to quiet the SwiftLint warning? HOT 2
- `crossingsRemoved` gets confused by coincident points HOT 3
- droots can have low precision in some cases, which could affect Path.contains(_ point:)
- Newton iteration may fail to converge, producing wrong results in curve.project()
- `offset` fatalError when all control points of segments are the same HOT 3
- Impossible to make closed PathComponent HOT 19
- Proposal: Use Sylvester Matrix for finding the intersection of cubic beziers HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bezierkit.