Each Placement3D has 2 read-write properties that describe its transformation:
The properties are represented by a 4x4 transformation matrix:
M11 M12 M13 M14
M21 M22 M23 M24
M31 M32 M33 M34
OffsetX OffsetY OffsetZ M44
Here is an example of setting transformation matrix to a 3D object:
| C# |
Copy Code
|
|---|---|
Vector3D oVector3D = new Vector3D(); oVector3D.X = 3.0; oVector3D.Y = 4.0; oVector3D.Z = 5.0; Quaternion oQuaternion = new Quaternion(oVector3D, 2.0); Matrix3D oMatrix3D = new Matrix3D(); oMatrix3D.Rotate(oQuaternion); oMatrix3D.Translate(new Vector3D(1.0, 2.0, 3.0)); oComponent1.AbsoluteTransformation = oMatrix3D; |
|
It is also possible to move a 3D object using the Move() method:
| C# |
Copy Code
|
|---|---|
oComponent1.Move(1.0, 2.0, 3.0); |
|
Sometimes it is necessary to calculate the local transformation, i. e. relative to a specified 3D object.
For example, it could be the position of components on a rail from its beginning:
To calculate the position of the handle, it is necessary to use the .RelativeTransformationOfMacro property:
| C# |
Copy Code
|
|---|---|
Matrix3D terminalTransformation = terminal.RelativeTransformationOfMacro; var x_coordinate = terminalTransformation.Transform(new Point3D()).X; |
|
For this purpose, please use the .Corners property. At first, please recognize whether a rail is horizontally placed or vertically by checking its position according to a base line mate:
| C# |
Copy Code
|
|---|---|
private bool isRailHorizontal(MountingRail rail) { var baseMate = rail.BaseMate; return Math.Abs(baseMate.StartPoint.X - baseMate.EndPoint.X) > Math.Abs(baseMate.StartPoint.Y - baseMate.EndPoint.Y); } var terminalPosition = isRailHorizontal(rail) ? Math.Abs( (terminal.Corners.LowerLeftBackAbsolute.X - rail.Corners.LowerLeftBackAbsolute.X)) : Math.Abs((terminal.Corners.LowerLeftBackAbsolute.Z - rail.Corners.LowerLeftBackAbsolute.Z)); |
|
It can also be useful to get information about how an item was rotated during insertion from Placement options dialog:
To calculate this rotation, there should be used the .RelativeTransformationOfMacro property:
| C# |
Copy Code
|
|---|---|
Matrix3D matrix = oPlacement3D.RelativeTransformationOfMacro;
double oRotationAngleZ = -1 * Math.Atan2(matrix.M21, matrix.M11) * (180.0 / Math.PI);
|
|