GetClosestCurvePosition2 (NurbsCurveList) *
Description
Returns the curve index, position of the point on it, U value and squared distance from the given position. The data is returned in a 1-dimensional array and is ordered the same as for the NurbsCurveList.GetClosestCurvePosition method output arguments.
Note: This method must be used with scripting languages that don't support arguments passed by reference such as JScript and PerlScript. For more information on getting output arguments, see About Output Argument Arrays.
Scripting Syntax
NurbsCurveList.GetClosestCurvePosition2( Position )
C# Syntax
Object NurbsCurveList.GetClosestCurvePosition2( Object in_vPosition );Parameters
|
Parameter |
Type |
Description |
|
Position |
A position expressed in the NurbsCurveList object frame of reference. |
Return Value
Array containing the curve index (Long), squared distance from the given position (Double), U value (Double) and the position of the point on the curve (SIVector3).
Examples
1. JScript Example
// This example shows how to retrieve the control points returned by // NurbsSurface.GetClosestSurfacePosition2 var oRoot = Application.ActiveProject.ActiveScene.Root; var oArc = oRoot.AddGeometry( "Arc", "NurbsCurve" ); // Translate the sphere oArc.Kinematics.Global.Parameters("posx").value = oArc.Kinematics.Global.Parameters("posx").value + 13; var oPosition = XSIMath.CreateVector3(); oPosition.Set( 0.0, 0.0, 0.0 ); // convert VB array to JScript array var vbArgs = new VBArray(oArc.ActivePrimitive.Geometry.GetClosestCurvePosition2(oPosition)); var args = vbArgs.toArray(); LogMessage( "The origin is closest to curve : " + args[0] + " its distance from it is " + Math.sqrt(args[1]) ); LogMessage( "The U values are U : " + args[2] ); LogMessage( "The corresponding position is X: " + args[3].X + " Y: " + args[3].Y + " Z: " + args[3].Z );
2. JScript Example
/* This example demonstrates how to work with curve lists. Of particular interest is how to use the (object model) equivalents of EvaluateCurveAt. */ NewScene( null, false ); // Create a NurbsCurveList var oSpine = SICreateCurve( "crvlist", 3, 0 ); SIAddPointOnCurveAtEnd( "crvlist", -10, 0, -3, false, 0 ); SIAddPointOnCurveAtEnd( "crvlist", 10, 0, -3, false, 0 ); var oUKnots = oSpine.ActivePrimitive.Geometry.Curves(0).Knots LogMessage( "Start Knot " + oUKnots.item(0 ) ) LogMessage( "End Knot " + oUKnots.item( oUKnots.Count - 1 ) ) var xxx = 0; var vP = XSIMath.CreateVector3(); var n; for ( var i=-10; i<=10; i+=0.2 ) { LogMessage( "----------------" ); vP.Set( i,0,-3 ); var Args = oSpine .ActivePrimitive.Geometry.GetClosestCurvePosition2( vP ).toArray(); uClosest = Args[2]; var atmp = oSpine.ActivePrimitive.Geometry.Curves( 0 ).EvaluatePosition( uClosest ).toArray(); LogMessage( "Closest U Value " + uClosest ) var ZeValues = atmp[0] LogMessage( ZeValues.x ); // this is the null that corresponds to the closest point found n = ActiveSceneRoot.AddNull(); n.Kinematics.Global.Parameters( "posx" ).Value = ZeValues.x; // parallel null n = ActiveSceneRoot.AddNull(); n.Kinematics.Global.Parameters( "posx" ).Value = i; n.Kinematics.Global.Parameters( "posy" ).Value = -3; // this value steadily increases!!! DiffFromLast = uClosest - xxx; LogMessage( uClosest + " diff from last: " + DiffFromLast ); xxx = uClosest; } // output: //INFO : Start Knot 0 //INFO : End Knot 1 //INFO : ---------------- //INFO : Closest U Value 0 //INFO : -10 //INFO : 0 diff from last: 0 //INFO : ---------------- //INFO : Closest U Value 0.0033442415690163336 //INFO : -9.80001579492262 //INFO : 0.0033442415690163336 diff from last: 0.0033442415690163336 //INFO : ---------------- //INFO : Closest U Value 0.006710593551987059 //INFO : -9.60006026699216 //INFO : 0.006710593551987059 diff from last: 0.0033663519829707257 //INFO : ---------------- // etc. //INFO : ---------------- //INFO : Closest U Value 0.7842420051901503 //INFO : 9.79912278091057 //INFO : 0.7842420051901503 diff from last: 0.05569420207796605 //INFO : ---------------- //INFO : Closest U Value 0.999999999999987 //INFO : 10 //INFO : 0.999999999999987 diff from last: 0.2157579948098367
See Also
Autodesk Softimage v7.5