Nov
02

curve length

When I first started to learn how to script in mel, I had the hardest time trying to figure out the length of a spline curve. This is super easy, when a line is composed of purely straight lines. But, when a curve starts to bend, it gets extremely complicated. I wanted to understand exactly how a curve was shaped based on its degree and control points. I ran into good amount of websites and journals that explain spline curves with math formulas. I never figured out how to find out a curve length using script through pure math. However, I ended up learning a lot about spline curves, and this was probably the most helpful article that I ran into: Arc Length Parameterization of Spline Curves.

After a while of trying to figure this thing out, I found out about the arc length tool -__- And, also found a script that extracts the measurement from the arc length node. I modified the script a tiny bit and made it into a function, which looks like this:

ArcLength

proc float getCurveLength( string $curve )
{
string $arcLenNode = `createNode arcLengthDimension`;
connectAttr -f ( $curve + “.worldSpace[0]” ) ( $arcLenNode + “.nurbsGeometry” );

setAttr ( $arcLenNode + “.uParamValue” ) `getAttr ( $curve + “.maxValue” )`;

float $curveLength = `getAttr ( $arcLenNode + “.arcLength” )`;

string $parent[] = `listRelatives -p $arcLenNode`;
delete $parent;

return $curveLength;
}

No comments found... but you can be first to write one.

Leave a Reply