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.35k stars 290 forks source link

Curve fitting with boundary conditions #367

Open victorsalit opened 2 years ago

victorsalit commented 2 years ago

Hi Pomax,

first of all many thanks for your time and efforts! I would like to ask about how to implement the known end slopes boundary conditions into the curve fitting using the least squares. Suppose I have a collection of points and I would like to best fit a Bezier curve of a given degree to these points. Suppose, also, I would like to treat the first and the last point as actual first and last control points. Starting from the error definition in matrix notation E(C) = (P - TMC)^T (P - TMC) d(E(C))/dC = -2(TM)^T (P - TMC) <--- your equation lacks M^T after rearrangement and abbreviating TM as b, we get b^T bC = b^T P. Let's define b^T b => B and b^T P => A, such that we now have BC = A. If C(1) and C(end) are known, we get B(2:end-1, 2:end-1)C(2:end-1) = A(2:end-1) - C(1)B(2:end-1,1) - C(end)B(2:end-1,end) and finally C(2:end-1) = B(2:end-1, 2:end-1)C(2:end-1)^-1 [A(2:end-1) - C(1)B(:,1) - C(end)B(:,end)] This works like a charm. However, I don't understand how to derive/implement the slope conditions (let say in the form of unit tangents) at the first and last points...

Would really appreciate your thoughts on this. Victor

victorsalit commented 1 year ago

Any thought/comments?