How to get normal of Catmull Rom spline

454 Views Asked by At

I have a piece wise track made out of Catmull Rom splines. I originally crossed the tangent vector with (0,0,1), then the result of that crossed with the tangent to get the normal vector. However, this doesn't work when the track makes a loop because the normal flips whenever the axes it originally pointed in changes direction, or no normal at all when it's completely parallel to (0,0,1). I initially had the first cross product cross with the normal vector of the previous segment of track, and this worked wonderfully, but it can only change in one direction (|x|,z) or (|y|,z) or the previous normal will start rotating the next normal.