MatrixFactoryFromCoordinateSystem Method |
Returns a coordinate transformation matrix defined by the given coordinate system.
With the returned matrix points can be transformed from the given coordinate system to
the current work plane coordinate system.
Namespace: Tekla.Structures.Geometry3d
Assembly: Tekla.Structures (in Tekla.Structures.dll) Version: 2023.0.3
Syntax
Parameters
- CoordSys
- Type: Tekla.Structures.Geometry3dCoordinateSystem
The coordinate system to transform points from.
Return Value
Type: MatrixThe transformation matrix defined by the given coordinate system.
Examples
This example shows the extremes of the beam in the current work plane coordinate system.
using System; using System.Globalization; using Tekla.Structures.Geometry3d; using Tekla.Structures.Model; using Tekla.Structures.Model.UI; public class Example { private readonly Model _Model = new Model(); private static GraphicsDrawer GraphicsDrawer = new GraphicsDrawer(); private readonly static Color TextColor = new Color(1, 0, 1); //Shows the beam's extremes in the current work plane coordinates private void ShowExtremesInCurrentCoordinates(Beam Beam) { //Set the transformation plane to be in another location than global //Comment these lines out if you have done that already TransformationPlane CurrentTP = _Model.GetWorkPlaneHandler().GetCurrentTransformationPlane(); _Model.GetWorkPlaneHandler().SetCurrentTransformationPlane(new TransformationPlane(Beam.GetCoordinateSystem())); //Update the beam's extremes to the new transformation plane Beam.Select(); Point LocalStartPoint = Beam.StartPoint; Point LocalEndPoint = Beam.EndPoint; _Model.GetWorkPlaneHandler().SetCurrentTransformationPlane(CurrentTP); //Get the matrix to transform the coordinates from local to current Matrix TransformationMatrix = MatrixFactory.FromCoordinateSystem(Beam.GetCoordinateSystem()); //Transform the points from local to the current work plane coordinate system Point CurrentStartPoint = TransformationMatrix.Transform(LocalStartPoint); Point CurrentEndPoint = TransformationMatrix.Transform(LocalEndPoint); //Display results DrawCoordinateSystem(new CoordinateSystem()); GraphicsDrawer.DrawText(CurrentStartPoint, FormatPointCoordinates(CurrentStartPoint), TextColor); GraphicsDrawer.DrawText(CurrentEndPoint, FormatPointCoordinates(CurrentEndPoint), TextColor); } //Draws the coordinate system in which the values are shown private static void DrawCoordinateSystem(CoordinateSystem CoordinateSystem) { DrawVector(CoordinateSystem.Origin, CoordinateSystem.AxisX, "X"); DrawVector(CoordinateSystem.Origin, CoordinateSystem.AxisY, "Y"); } //Draws the vector of the coordinate system private static void DrawVector(Point StartPoint, Vector Vector, string Text) { Color Color = new Color(0, 1, 1); const double Radians = 0.43; Vector = Vector.GetNormal(); Vector Arrow01 = new Vector(Vector); Vector.Normalize(500); Point EndPoint = new Point(StartPoint); EndPoint.Translate(Vector.X, Vector.Y, Vector.Z); GraphicsDrawer.DrawLineSegment(StartPoint, EndPoint, Color); GraphicsDrawer.DrawText(EndPoint, Text, Color); Arrow01.Normalize(-100); Vector Arrow = ArrowVector(Arrow01, Radians); Point ArrowExtreme = new Point(EndPoint); ArrowExtreme.Translate(Arrow.X, Arrow.Y, Arrow.Z); GraphicsDrawer.DrawLineSegment(EndPoint, ArrowExtreme, Color); Arrow = ArrowVector(Arrow01, -Radians); ArrowExtreme = new Point(EndPoint); ArrowExtreme.Translate(Arrow.X, Arrow.Y, Arrow.Z); GraphicsDrawer.DrawLineSegment(EndPoint, ArrowExtreme, Color); } //Draws the arrows of the vectors private static Vector ArrowVector(Vector Vector, double Radians) { double X, Y, Z; if(Vector.X == 0 && Vector.Y == 0) { X = Vector.X; Y = (Vector.Y * Math.Cos(Radians)) - (Vector.Z * Math.Sin(Radians)); Z = (Vector.Y * Math.Sin(Radians)) + (Vector.Z * Math.Cos(Radians)); } else { X = (Vector.X * Math.Cos(Radians)) - (Vector.Y * Math.Sin(Radians)); Y = (Vector.X * Math.Sin(Radians)) + (Vector.Y * Math.Cos(Radians)); Z = Vector.Z; } return new Vector(X, Y, Z); } //Shows the point coordinates with only two decimals private static string FormatPointCoordinates(Point Point) { string Output = String.Empty; Output = "(" + Point.X.ToString("0.00", CultureInfo.InvariantCulture) + ", " + Point.Y.ToString("0.00", CultureInfo.InvariantCulture) + ", " + Point.Z.ToString("0.00", CultureInfo.InvariantCulture) + ")"; return Output; } }
See Also