# Python: Up-Vector math for Curve

I've been working on python Curve Deformation tool. I need some help with the math. Possibly someone can help here. I cannot find correct UpVec for my custom curve.

Here are the screens which explain the problem:

Here is my tool in action: https://youtu.be/Nxu6-0xm3Io

Here is the code I did but it's buggy in some angles. It inverts to 180 degrees on some angles: https://github.com/mifth/mifthtools/blob/96e73eb3a2613b3f1396ddd7c4bdd9d0419ca5e3/blender/addons/mira_tools/mi_curve_guide.py#L515-L537

All I do is just cross direction of the point to global X and Y axis. Any help will be appreciated to get the quality of upVec as in Blender Curves.

And you can get the tool here: https://github.com/mifth/mifthtools http://blenderartists.org/forum/showthread.php?366107-MiraTools

Thanks.

• perhaps an intereting read: rollercoasters-and-normals by freek hoekstra. (a blog post about exactly this problem) – zeffii May 8 '15 at 10:42
• Do you want to find the tilt as shown in the viewport? or calculate it from your own bezier data? – ideasman42 May 8 '15 at 10:46
• ideasman42 - i need the same tilt for my custom python curve. Here is "deform_lines" array of all points of the curve and all their directions. github.com/mifth/mifthtools/blob/… – mifth May 8 '15 at 11:09

There are 3 ways for upVec to be found:

2 and 3 versions were suggested by mano-wii from here http://blenderartists.org/forum/showthread.php?361154-Coordinates-of-resolution-points-of-a-Bezier-Curve

I choosed Cross vec for my approach for the upVec searching. You can comment/uncomment any of approaches and try testing.

Also,I found another issue: One direction can has different upVecs. http://i.imgur.com/itANWG6.png

To fix this issue I have to pick first point upVec and then check all points after. If a current upVecAngle is more than 90 degrees - we need to invert upVec. Here is the code to fix this issue: https://github.com/mifth/mifthtools/blob/6b0469faea18d3375c3f3257963d7c85f327c44c/blender/addons/mira_tools/mi_curve_guide.py#L504-L509

And you can see the result of my custom curve in editmode here: https://www.youtube.com/watch?v=VXWSUwOul-s