I have implemented Bezier Curve that complies to the mathematical rules, using de casteljau's algorithm. I have tested my implementation with other libraries, such as OpenNURBS, and our results match. However, when I create a bezier curve in maya, using the same control vertices, the curve is incorrect.
Example:
import maya.cmds as mc
mc.curve( d=3, p=[(-1,0,0), (-1,2,0), (0,1,0), (1,2,0), (1,0,0)] )
mc.nurbsCurveToBezier( )
To evaluate the curve, I created a locator and used a motion path constrain and set the U value to 0.5.
When this curve is evaluated for t=0.5, maya returns ( 0.0, 1.5, 0.0 )
, whereas the correct answer is { 0 , 1.375 , 0 }
.
Am I creating a bezier curve in maya properly? If so, why am I seeing different results?
Hmmm... you have specified a degree 3 curve, with 5 control points. I think you're actually wanting a degree 4 curve here? (Because if you've only implemented a naive bezier curve type, I'm going to guess you're raising everything to the 4th power when using 5 points?)
import maya.cmds as mc
# 4th power here perhaps?
mc.curve( d=4, p=[(-1,0,0), (-1,2,0), (0,1,0), (1,2,0), (1,0,0)] )
mc.nurbsCurveToBezier( )
I seem to have a vague recollection that Maya only supports degrees of 1, 3, 5, and 7? So I'm not sure if that code will actually work? (It might just be a limitation in the create curve tool, not sure?)