Aligning 2 Coordinate Systems to get a matrix that maps from one to another?

Hi Folks

I have 2 “coordinate systems”.

Coordinate system 1 : has origin, x,y,z axes as defined by a world coordinate system.
Coordinate system 2 : is the same as the above, except the “origin” and axes are completely different.

I need a transformation matrix to get me from one system to another. For example, I might have a point in coordinate system 1, that I want translated / rotated so that it is in the same spot relative to coordinate system 2.

Not sure if I’m making any sense?

Let us assume that no scaling is happening.

Was hoping this is a common problem that someone might be able to suggest a pointer:

e.g. this one seems to suggest you can rotate but then I would have to do it for each axis, then apply a translation to properly align the coordinate system

Is there any easier way / alternative? Any pointers would be appreciated.

Thank you!

Geom::Transformation.axes — SketchUp Ruby API Documentation

The axes method creates a transformation that goes from world coordinates to an arbitrary coordinate system defined by an origin and three axis vectors.

1 Like

Thank you! @DanRathbun

Presumably you would multiply the two matrices to get from one coordinate system to another?

tr_1 = Geom::Transformation.axes(ORIGIN, x, y, z)
tr_2 = Geom::Transformation.axes(another_origin, another_x, another_y, another_z )

# to transform from tr_1 to tr_2 you would do:
final_transformation = tr_2 * tr_1

am i doing it wrong?

It looks okay. Test it out and see.

Hey Thanks @DanRathbun .

Perhaps I am missing something: is the Transformation.axes method available for viewing? I was expecting to find a gem where i could include it in a script and test out the method locally to see if it works: perhaps in a ruby console.

I could not for the life of me find it’s implementation online. all i could find are stubs.

any pointers would be well appreciated?

If you mean the underlying code, then no, SketchUp core code is proprietary and closed source.

The stubs are for either Intellisense with an IDE or for generating your own API documentation locally with YARD.

Do not have great expectations with regard to gems and SketchUp.

SketchUp has a shared ObejctSpace that all extensions and authors use.

Ruby gems are written for standalone Ruby processes and often modify core Ruby classes that can affect other extensions in a shared Ruby process. That said, some of the standard libraries are now delivered as gems bundled with SketchUp Ruby’s. These should be used going forward instead of installing other versions from the rubygems server.

There are guidelines here (in this category) for when an extension needs to deliver gem code with the extension. Basically, it needs to be rewrapped with the extension’s namespace so as not to affect other extensions.

I suggest installing @thomthom’s Transformation Inspector extension:

1 Like