I’m trying to export (3D) bezier curves from Blender to my C++ program. I asked a related question a while back, where I was successfully directed to use De Casteljau’s Algorithm to evaluate points (and tangents to these points) along a bezier curve. This works well. In fact, perfectly. I can export the curves and evaluate points along the curve, as well as the tangent to these points, all within my program using De Casteljau’s Algorithm.
However, in 3D space a point along a bezier curve and the tangent to this point is not enough to define a “frame” that a camera can lock into, if that makes sense. To put it another way, there is no “up vector” which is required for a camera’s orientation to be properly specified at any point along the curve. Mathematically speaking, there are an infinite amount of normal vectors at any point along a 3D bezier curve.
I’ve noticed when constructing curves in Blender that they aren’t merely infinitely thin lines, they actually appear to have a proper 3D orientation defined at any point along them (as shown by the offshooting “arrow lines” in the screenshot below). I’d like to replicate what blender does here as closely as possible in my program. That is, I’d like to be able to form a matrix that represents an orientation at any point along a 3D bezier curve (almost exactly as it would in Blender itself).

Can anyone lend further guidance here, perhaps someone with an intimate knowledge of Blender’s source code? (But any advice is welcome, Blender background or not.) I know it’s open source, but I’m having a lot of troubles isolating the code responsible for these curve calculations due to the vastness of the program.
Some weeks ago, I have found a solution to this problem. I post it here, in case someone else would need it :
1) For a given point
P0, calculate the tangent vectorT0.One simple, easy way, is to take next point on the curve, subtract current point, then normalize result :
T0 = normalize(P1 - P0)Another, more precise way, to get tangent is to calculate the derivative of your bezier curve function.
Then, pick an arbitrary vector
V(for example, you can use(0, 0, 1))Make
N0 = crossproduct(T0, V)andB0 = crossproduct(T0, N0)(dont forget to normalize result vectors after each operation)You now have a starting set of coordinates (
P0,B0,T0,N0)This is the initial camera orientation.
2) Then, to calculate next points and their orientation :
Calculate
T1using same method asT0Here is the trick, new reference frame is calculated from previous frame :
N1 = crossproduct(B0, T1)B1 = crossproduct(T1, N1)Proceed using same method for other points. It will results of having camera slightly rotating around tangent vector depending on how curve change its direction. Loopings will be handled correctly (camera wont twist like in my previous answer)
You can watch a live example here (not from me) : http://jabtunes.com/labs/3d/webgl_geometry_extrude_splines.html