DigiPara Liftdesigner LDX API
Loading...
Searching...
No Matches
Using Matrices and Vectors

API method: ILDXHideCS5.TransformPoint

 ' from Samples/Src/LDXAPIExamples/Example_LDXHideCS.vb

    <APIHelpAttribute(APIHelpModes.None, {APIHelpModes.InputParaLDXApp}, "", "LDXHideCS~TransformPoint", "Using Matrices and Vectors")>
 Public Shared Sub UseMatrixAndVector(ByRef ldxApplication As DigiPara.LDX.LDXApplication)
     Dim ldxFactory = ldxApplication.Factory

     Dim ldxMatrix = ldxFactory.CreateMatrix(Nothing)
     Dim ldxPoint = ldxFactory.CreateVector(Nothing)
     ldxPoint.Y = 1

     ' set matrix to 90 degree rotation around z axis and a translation by 3 along the z axis
     ldxMatrix.SetXy(0, 1, 0, -1, 0, 0)
     ldxMatrix.R.Z = 3
     System.Diagnostics.Debug.Assert(ldxMatrix.R.Z = 3)
     System.Diagnostics.Debug.Assert(ldxMatrix.X.Y = 1)
     System.Diagnostics.Debug.Assert(ldxMatrix.Y.X = -1)

     ' transform point in place
     ldxMatrix.TransformPoint(ldxPoint)
     System.Diagnostics.Debug.Assert(ldxPoint.X = -1)
     System.Diagnostics.Debug.Assert(ldxPoint.Y = 0)
     System.Diagnostics.Debug.Assert(ldxPoint.Z = 3)

     ' transform it back
     ldxMatrix.ReTransformPoint(ldxPoint)
     System.Diagnostics.Debug.Assert(ldxPoint.X = 0)
     System.Diagnostics.Debug.Assert(ldxPoint.Y = 1)
     System.Diagnostics.Debug.Assert(ldxPoint.Z = 0)

     ' if you need to keep both the original point and ints transform, you can use the Get... variant of the functions
     Dim ldxTransformedPoint = ldxMatrix.GetTransformedPoint(ldxPoint)
     System.Diagnostics.Debug.Assert(ldxTransformedPoint.X = -1)
     System.Diagnostics.Debug.Assert(ldxTransformedPoint.Y = 0)
     System.Diagnostics.Debug.Assert(ldxTransformedPoint.Z = 3)
     System.Diagnostics.Debug.Assert(ldxPoint.X = 0)
     System.Diagnostics.Debug.Assert(ldxPoint.Y = 1)
     System.Diagnostics.Debug.Assert(ldxPoint.Z = 0)

     ' direction vectors should be transformed using the Rotate() family of functions, they ignore the translation component of the matrix
     Dim ldxDirection = ldxFactory.CreateVector(Nothing)
     ldxDirection.X = 1

     ' The same variants exist. Rotate in place
     ldxMatrix.RotateDirection(ldxDirection)
     System.Diagnostics.Debug.Assert(ldxDirection.X = 0)
     System.Diagnostics.Debug.Assert(ldxDirection.Y = 1)
     System.Diagnostics.Debug.Assert(ldxDirection.Z = 0)

     ' rotate it back
     ldxMatrix.ReRotateDirection(ldxDirection)
     System.Diagnostics.Debug.Assert(ldxDirection.X = 1)
     System.Diagnostics.Debug.Assert(ldxDirection.Y = 0)
     System.Diagnostics.Debug.Assert(ldxDirection.Z = 0)

     Dim ldxRotatedDirection = ldxMatrix.GetRotatedDirection(ldxDirection)
     System.Diagnostics.Debug.Assert(ldxRotatedDirection.X = 0)
     System.Diagnostics.Debug.Assert(ldxRotatedDirection.Y = 1)
     System.Diagnostics.Debug.Assert(ldxRotatedDirection.Z = 0)
     System.Diagnostics.Debug.Assert(ldxDirection.X = 1)
     System.Diagnostics.Debug.Assert(ldxDirection.Y = 0)
     System.Diagnostics.Debug.Assert(ldxDirection.Z = 0)

     ' a matrix can be inverted
     Dim ldxInverseMatrix = ldxMatrix.GetInverse()
     System.Diagnostics.Debug.Assert(ldxInverseMatrix.R.Z = -3)
     System.Diagnostics.Debug.Assert(ldxInverseMatrix.X.Y = -1)
     System.Diagnostics.Debug.Assert(ldxInverseMatrix.Y.X = 1)

     ' transforming/rotating a vector by the inverse is the same as retransforming/reortating it by the original
     ldxInverseMatrix.RotateDirection(ldxRotatedDirection)
     System.Diagnostics.Debug.Assert(ldxRotatedDirection.X = 1)
     System.Diagnostics.Debug.Assert(ldxRotatedDirection.Y = 0)
     System.Diagnostics.Debug.Assert(ldxRotatedDirection.Z = 0)

     ' test self assignment
     ldxInverseMatrix._Set = ldxInverseMatrix
     System.Diagnostics.Debug.Assert(ldxRotatedDirection.X = 1)
     System.Diagnostics.Debug.Assert(ldxRotatedDirection.Y = 0)
     System.Diagnostics.Debug.Assert(ldxRotatedDirection.Z = 0)
 End Sub