Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benkoshy/32cb8ebcafabde24d9067c8dbefbc7c1 to your computer and use it in GitHub Desktop.
Save benkoshy/32cb8ebcafabde24d9067c8dbefbc7c1 to your computer and use it in GitHub Desktop.
Demonstrates how the ByCoordinateSystems method works using the Tekla Open API

Please review the MatrixFactory.ByCoordinateSystems Method in order to get the most out of this post. Particularly:

Returns a coordinate transformation matrix defined by two coordinate systems. With the returned matrix points can be transformed from the first coordinate system to the second coordinate system. The ByCoordinateSystems method is meant for transforming points between coordinate systems asked in the same work plane.

            //
            //
            // Example 1:
            CoordinateSystem cs1 = new CoordinateSystem();
            CoordinateSystem cs2 = new CoordinateSystem(new Point(100, 100, 0), 
                                                        new Vector(1, 0, 0), 
                                                        new Vector(0, 1, 0));

            Matrix transformationMatrix = MatrixFactory.ByCoordinateSystems(cs1, cs2);

            Point testPoint = new Point(200, 100, 0); 
            // remember, think about testPoint as if it is defined by the cs1 coordinate system.

            // transform that contourPoint:
            Point newPoint = transformationMatrix.Transform(testPoint);
            
            // What is the newPoint?
            //// new contourPoint is: 100,0,0
            
            // But why?
            // testPoint is 100 units to the right of cs2. That's how I think about it.            
            // The key is to closely scrutinise in which direction the coordinate system is being transformed.

Try another example:

            //
            //            
            // Example 2:

            CoordinateSystem cs1 = new CoordinateSystem(new Point(0, -100, 0), new Vector(1, 0, 0), new Vector(0, 1, 0));
            CoordinateSystem cs2 = new CoordinateSystem(new Point(100, 100, 0), new Vector(1, 0, 0), new Vector(0, 1, 0));

            Matrix transformationMatrix = MatrixFactory.ByCoordinateSystems(cs1, cs2);

            Point testPoint = new Point(200, 100, 0); // new point as defined in the cs1 coordinate system!

            // transform that contourPoint:
            Point newPoint = transformationMatrix.Transform(testPoint);
            
            // Before seeing the answer, what do you think newPoint will be.
            // Hint: 
            // We want to transform from the first coordinate system to the second.
            // This would be like the example about, except we have to displace the result
            // by 100 units down, because cs1 is 100 units below. That's how i think about it.
            //// {(100.000, -100.000, 0.000)}
            
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment