I have recently been working on Bezier curves and have come across a very interesting snippet of code relating to finding the normal of a Bezier curve. It is the only of its kind I can find and there were no comments left as to how it was derived. the code is as follows :
internal static Vector3 EvaluateSplineSegmentNormal (SplinePoint pointA, SplinePoint pointB, float t) {
// Evaluate the normal for value t between points A and B
return ((6.0f * (t * t)) - (6.0f * t)) * pointA.position
+ ((3.0f * (t * t)) - ((4.0f * t) + 1)) * pointA.GetHandle(Direction.Forward)
+ ((3.0f * (t * t)) - (2.0f * t)) * pointB.GetHandle(Direction.Backward)
+ ((-6.0f * (t * t)) + (6.0f * t)) * pointB.position;
}
Where the primary info in it is represented here :
NP0 = (6*t*t - 6*);
NC0 = (3*t*t - 4*t + 1);
NC1 = (3*t*t - 2*t);
NP1 = (-6*t*t + 6*t);
Where NP0, NC0, NC1, NP1 represent a similar concept as what P0,P1,P2,P3 are multiplied by respectively in this Wikipedia article. In the Hermite curve Article, the basis functions H00,H01,H10,H11 are a good analogy for NP0, NC0, NC1, NP1.
My question is how does this work, if it even does, and how was it derived so I can do the same for a Hermite curve as well. The go to answer for finding the normal would be to just use the vector given by the derivative and cross it with the up vector for example, I have yet to see any other instance where a separate set of polynomials were used to calculate normals, but that is exactly what I need in order to have a generalised function that can take any size vector/value in my program.
If it helps any, I will include the data I have to compute a point and the derivative in the same style as above, I know that the derivative is not usually represented as 4 distinct polynomials to multiply by, so I did some basic rearranging and have tested to confirm it works properly.
//Calculates curve position at t[0, 1]
P0 = (-1*t*t*t + 3*t*t - 3*t + 1);
C0 = (3*t*t*t - 6*t*t + 3*t);
C1 = (-3*t*t*t + 3*t*t);
P1 = (t*t*t);
//Calculates tangent at t[0, 1]
DP0 = (-3*t*t + 6*t - 3);
DC0 = (9*t*t - 12*t + 3);
DC1 = (-9*t*t + 6*t);
DP1 = (3*t*t);
The way to use these values to compute the point is as follows:
Point = P0*startPoint + C0*startHandle + C1*endHandle + P1*endPoint;
Any help would be appreciated, I have been going though countless scientific papers and code examples for so long that the word Bezier gives me ptsd-esque flashbacks at this point.