NurbsSurfaceMesh.GetClosestSurfacePosition operator

Description

Returns the surface index, position of the point on it, UV values and squared distance from the given position.

Note: This method uses output arguments. C# and some scripting languages (such as JScript and PerlScript) don't support arguments passed by reference. However, there is a alternate version of this method which is considered safe to use with C#, JScript and PerlScript: NurbsSurfaceMesh.GetClosestSurfacePosition2.

C# Syntax

NurbsSurfaceMesh.GetClosestSurfacePosition( Object in_vPosition, Object& out_pvSurfaceIndex, Object& out_pvSquaredDistance, Object& out_pvUValue, Object& out_pvVValue, Object& out_pvPosition );

Scripting Syntax

NurbsSurfaceMesh.GetClosestSurfacePosition( Position, [Index], [SquaredDistance], [UValue], [VValue], [Position] );

Parameters

Parameter Type Description
Position SIVector3 or 1D Array of 3 elements A position expressed in the NurbsSurfaceMesh object frame of reference.
Index Long The surface index to which the position is the closest.
SquaredDistance Double The squared distance of the inputed position to the surface point.
UValue Double The corresponding UValue on the NurbsSurface
VValue Double The corresponding VValue on the NurbsSurface
Position SIVector3 (contains the position) The actual surface position at UV values.

Examples

VBScript Example

'
' This example shows how you can get the closest surface position using either a 
' vector of global positions or an array of local positions as the reference point
'
set oRoot = Application.ActiveSceneRoot
set oSphere = oRoot.AddGeometry("Sphere", "NurbsSurface")
' Translate the sphere
oSphere.Kinematics.Global.Parameters("posx").Value = oSphere.Kinematics.Global.Parameters("posx").Value + 13
' Set up a global array and a local vector (converted from global space) to use as references
set oGlobalPos = XSIMath.CreateVector3(0.0, 0.0, 0.0)
set oLocalPos = XSIMath.MapWorldPositionToObjectSpace(oSphere.Kinematics.Local.Transform, oGlobalPos) 
aPosition = Array(0.0, 0.0, 0.0)
' Get the closest surface position from the local vector
oSphere.ActivePrimitive.Geometry.GetClosestSurfacePosition oLocalPos, SurfaceIndex, _
	SquaredDistance, UValue,VValue, SurfacePosition
Application.LogMessage "The origin is closest to surface : " & SurfaceIndex & _
	" its distance from it is " & sqr(SquaredDistance)
Application.LogMessage "The UV values are U : " & UValue & " V :" & VValue
Application.LogMessage "The corresponding position is X : " & SurfacePosition.X & _
	" Y :" & SurfacePosition.Y & " Z :" & SurfacePosition.Z
' Get the closest surface position from the array of global positions
oSphere.ActivePrimitive.Geometry.GetClosestSurfacePosition aPosition, SurfaceIndex, _
	SquaredDistance, UValue,VValue, SurfacePosition
Application.LogMessage "The origin is closest to surface : " & SurfaceIndex & _
	" its distance from it is " & sqr(SquaredDistance)
Application.LogMessage "The UV values are U : " & UValue & " V :" & VValue
Application.LogMessage "The corresponding position is X : " & SurfacePosition.X & _
	" Y :" & SurfacePosition.Y & " Z :" & SurfacePosition.Z
' Expected results:
' INFO : The origin is closest to surface : 0 its distance from it is 9.00000000000229
' INFO : The UV values are U : 0.999999 V :4.000001
' INFO : The corresponding position is X : -3.99999999999839 Y :1.57058495219762E-06 Z :-3.13444650011652E-06
' INFO : The origin is closest to surface : 0 its distance from it is 3.99525855482537
' INFO : The UV values are U : 7.50000002810587 V :3.62719837982321
' INFO : The corresponding position is X : -1.51252820283502 Y :-0.583451828096254 Z :-3.65156587231083