Constructing a cubic Bezier that passes through four points
Created on 2024-08-26T05:33:57-05:00
An interesting note is you could use these to make pretty lines for noodle graphs. Placing the tangents or phantom points in the right places will result in a line that curves to the entry and exit of the nodes.
Mathy notation is in this card. Points are vectors in practice but presented as symbols in the formulas.
Beziers
A bezier curve has Points P1 and P2. There are also tangent points T1 and T2.
bezier(t) = P1 * (1-t)^3 + T1 * 3 * (1-t)^2 * t + T2 * 3 * (1-t) * t^2 + P2 * t^3
Spline (four points) to tangents
Catmull-Rom curve is a spline defined by four points. This can be solved to convert it to a bezier.
T1 = (d_1^2 * P2 - d_2^2 * P0 + (2*d_1^2 + 3 * d1 * d2 + d_2^2) * P1) / (3 * d1 * (d1 + d2))
T2 = (d_3^2 * P1 - d_2^2 * P3 + (2*d_3^2 + 3 * d3 * d2 + d_2^2) * P2) / (3 * d3 * (d3 + d2))
di = |Pi - P_i-1|^a
Where 'a' is the constant alpha determining the tightness of a curve.
a = 0: uniform
a = 0.5: centripetal
a = 1: chordal
The spline formula accepts four points and produces tangents only for the middle points. You have to use "phantom" points (or previous points on the line.)