MEL How-To #73 | ||
| ||
How do I determine the length of a NURBS curve?Using 'arclen'The ‘ string $curve = `curve -d 1 -p -2.1 0.0 -2.0 -p 0.5 1.0 -3.2 -p 1.4 0.3 -1.2 -k 0 -k 1 -k 2`; // Result: curve1 // float $curveLength = `arclen $curve`; // Result: 5.335323 // If the ‘ string $curveInfo = `arclen -ch true $curve`; // Result: curveInfo1 // getAttr ( $curveInfo + ".arcLength" ); // Result: 5.335323 // move -r -os -wd 0 0 1.0 ( $curve + ".cv[1]" ); getAttr ( $curveInfo + ".arcLength" ); // Result: 4.309423 // Using 'arcLengthDimension'Create an " string $curve = `curve -d 3 -p -5.4 0.0 -5.5 -p -6.0 0.0 4.1 -p 3.4 0.0 -4.7 -p 7.8 0.0 -0.7 -p 0.3 0.0 2.3 -k -2 -k -1 -k 0 -k 1 -k 2 -k 3 -k 4`; // Determine the U range for this curve. float $maxU = `getAttr ( $curve + ".maxValue" )`; // Create an arcLengthDimension node, attached downstream of this curve. string $arcLD = `arcLengthDimension ( $curve + ".u[" + $maxU + "]" )`; float $arcLength = `getAttr ( $arcLD + ".arcLength" )`; // Result: 1246.701327 // NOTE: This will return the arc length in centimeters regardless of your UI Unit Preference. This method has the added advantage for querying the length along the curve at any parameter value. setAttr ( $arcLD + ".uParamValue" ) 1.0; $arcLength = `getAttr ( $arcLD + ".arcLength" )`; // Result: 784.586627 // setAttr ( $arcLD + ".uParamValue" ) 0.7071; $arcLength = `getAttr ( $arcLD + ".arcLength" )`; // Result: 539.611324 // The " string $transform[] = `listRelatives -parent $arcLD`; delete $transform[0]; Acknowledgements
Related How-To'sWednesday, October 10, 2001 | ||
Copyright ©2005 by Bryan Ewert, maya@ewertb.com Maya is a Registered Trademark of Alias |