Skip to content

Instantly share code, notes, and snippets.

@benkoshy
Last active June 25, 2026 00:39
Show Gist options
  • Select an option

  • Save benkoshy/a0094adb0736dd7d078ffc5e671eedcc to your computer and use it in GitHub Desktop.

Select an option

Save benkoshy/a0094adb0736dd7d078ffc5e671eedcc to your computer and use it in GitHub Desktop.
Tekla API Matrix Transformations explained

Key Take Out

WorldCoordinateSystem

The world Coordinate system is a Coordinate System with Origin defined as (0,0,0) and the XAxis defined as (1,0,0) and the YAxis as: (0,1,0).

FromCoordinateSystem

FromCoordinateSystem(beamCS) is the same as ByCoordinateSystems(beamCS, worldCS)

true == MatrixFactory.FromCoordinateSystem(beamCS) == MatrixFactory.ByCoordinateSystems(beamCS, worldCS) == True
// use unit tests if you want to explore this avenue
  [Test]
  public void TestMatrixEquivalentsFrom()
  {
      CoordinateSystem beamCS = getCoordinateSystemFromBeam(new Point(0, 0, 0), new Point(-50, 100, 200)); // helper method but you can use your own
      CoordinateSystem worldCS = new CoordinateSystem();

      Matrix m1 = MatrixFactory.FromCoordinateSystem(beamCS);
      Matrix m2 = MatrixFactory.ByCoordinateSystems(beamCS, worldCS);

      for (int i = 0; i < 4; i++)
      {
          for (int j = 0; j < 3; j++)
          {
              ClassicAssert.AreEqual(m1[i, j], m2[i, j], Double.Epsilon);
          }
      }
  }
  

ToCoordinateSystem

And on the flip side:

ToCoordinateSystem(beamCS) is the same as: ByCoordinateSystems(worldCS, beamCS)

MatrixFactory.ToCoordinateSystem(beamCS) == MatrixFactory.ByCoordinateSystems(worldCS, beamCS) == True;
  [Test]
  public void TestMatrixEquivalentsTo()
  {
      CoordinateSystem beamCS = getCoordinateSystemFromBeam(new Point(0, 0, 0), new Point(-50, 100, 200)); // // helper method but you can use your own
      CoordinateSystem worldCS = new CoordinateSystem();

      Matrix m1 = MatrixFactory.ToCoordinateSystem(beamCS); // from world to BeamCS
      Matrix m2 = MatrixFactory.ByCoordinateSystems(worldCS, beamCS);

      for (int i = 0; i < 4; i++)
      {
          for (int j = 0; j < 3; j++)
          {
              ClassicAssert.AreEqual(m1[i, j], m2[i, j], Double.Epsilon);
          }                    
      }
  }

From the docs (which is plane wrong):

ToCoordinateSystem: Returns a coordinate transformation matrix defined by the given coordinate system. With the returned matrix points can be transformed from the current work plane coordinate system to the given coordinate system.
FromCoordinateSystem 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.

They are really transformations from and to the world coordinate system. (I checked the source code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment