MEL ClosestPointOnCurve

From scripting
Jump to: navigation, search

Best link ever.... http://www.gooroos.com/addframe.html?page=http://www.gooroos.com/closestPointOnCurve.html


// Create the closestPointOnCurve node.
    createNode -name "cp" closestPointOnCurve;

    // Create the curve.
    curve -p -5 -5 0 -p -5 -4 0 -p -3 0 0 -p -2 1 0
          -p 2 0 0 -p 4 -1 0 -p 5 -3 0;

    // Create the locator and move it into position.
    createNode locator;
    move -r -5 5 0;

    // Connect the curve's worldSpace geometry and
    // the locator's position to the
    // closestPointOnCurve node
    connectAttr curve1.worldSpace cp.inputCurve;
    connectAttr locator1.translate cp.inPosition;

    // Retrieve the position of the point on curve1
    // which is closest to locator1.
    getAttr cp.position;
    // Result: -2.302124 0.4814418 0 //

    // Retrieve the point's U parameter value along
    // the curve.
    getAttr cp.parameterU;
    // Result: 1.606581 //

    // Retrieve the distance between locator1 and curve1.
    getAttr cp.distance;
    // Result: 5.26269 //