Pomax / BezierInfo-2

The development repo for the Primer on Bézier curves, https://pomax.github.io/bezierinfo
https://pomax.github.io/bezierinfo
Other
2.32k stars 289 forks source link

Add section on merging curves #306

Open Pomax opened 3 years ago

Pomax commented 3 years ago

you can iteratively merge the segments because you have all the information required already encoded in the segments:

image

For every 2 segments you're merging, all we need to know is the t value, which is a/(a+b) (where a is the length of the first segment's end point to its associated control point and b is the length of the second segment's start point to its associated control point). Now all you have to do is scale the first segment's first control point, and the second segment's second control point along their respective tangents, to correct for their t value. If the length of the first segment's start-control is l then the length in the merged curve is (a+b)*l/a, and if the length of the second segment's control-end is k then the length in the merged curve is (a+b)*k/b.

And for a curve that got reduced to more than 2 segments, you simply iteratively repeat this process.