Sometimes it’s necessary to transform world coordinates of one component to local coordinates relative to another component.

Let’s assume you have two shafts and you want to attach a user component to the second shaft. The insertion point or local root of your user component is relative to the second shaft, because it will be a child object of the second shaft. Furthermore your user component should be located at the insertion point of the front car door of the second shaft.

This requires a transformation of the car door’s world coordinates to the local coordinate system of the second shaft. The following VB.NET code snippet shows how to do this by using the (very handy for all kinds of 3D manipulations) classes and functions attached to this post:

Private Sub Calculate_Transformation(ByRef ldDoc As LDX.LDXDocument)

If (ldDoc Is Nothing) OrElse (ldDoc.Shafts.Count < 2) _

OrElse (ldDoc.Shafts(1).Car.GetDoor(1) Is Nothing) Then Return

Dim csLocalMatrixShaft As dpHideCS

Dim vLocalRootCarDoor As dpHideVec

Dim vWorldRootCarDoor As dpHideVec

csLocalMatrixShaft = New dpHideCS(ldDoc.Shafts(1).Comp.LocalMatrix)

vWorldRootCarDoor = _

New dpHideVec(ldDoc.Shafts(1).Car.GetDoor(1).Comp.WorldMatrix.R)

vLocalRootCarDoor = _

csLocalMatrixShaft.ReTransform(vWorldRootCarDoor)

Debug.WriteLine(“—– local root —–“)

Debug.WriteLine(“x: “ & vLocalRootCarDoor.X)

Debug.WriteLine(“y: “ & vLocalRootCarDoor.Y)

Debug.WriteLine(“z: “ & vLocalRootCarDoor.Z)

End Sub

The result of the transformation is simply printed to Visual Studio’s output window, but you might want to use the resulting coordinates to position your user component. Of course this also works with any other component/object that require transformation.

Download TransformationSample