Calcite | Level 5

## How to convert world coordinates to local coordinates, relative to forward vector?

Hello, I'm trying to find an optimal solution for a problem I'm having. I'm looking for 3D solution.

I'm trying to convert a Point from world coordinates to the local coordinates of a specific Object, so that when the Object rotates/changes position, I would still be able to find new coordinate for the Point, that would be have the same relation (position/rotation) to the Object as during the initial state.

I have the Forward, Right, Up vector of this Object; its position in world coordinates as well as the position of the Point in world coordinates.

I was thinking I could get the difference in angles between the vector from Object's origin to Point's origin and the Forward vector of the Object, and then rotate by this difference from the Forward vector backwards to get the direction of the desired vector, but that is unreliable. So I'm assuming I will have to use some transformation Matrix for this.

What are the maths for my exact situation, where I'd be using a custom axis (the Forward vector of my object) and to do the conversion from world to local coordinates?

2 REPLIES 2
Super User

## Re: How to convert world coordinates to local coordinates, relative to forward vector?

Do you have some sort of digital elevation model data set with elevation associated with a geographic coordinate system?

That would be the first thing to look for. Free data of that sort is not very widespread.

I would, because many years ago I had some training with this software, start at https://grass.osgeo.org/ as the pure SAS solutions in SAS/GIS require additional license.

GIS software for 3d spatial problems generally.

## Re: How to convert world coordinates to local coordinates, relative to forward vector?

Hello @squad4 and welcome to the SAS Support Communities!

(...) I have the Forward, Right, Up vector of this Object; its position in world coordinates as well as the position of the Point in world coordinates. (...)

What are the maths ... to do the conversion from world to local coordinates?

So your "local coordinates" are defined by three (column) vectors f ("forward"), r ("right") and u ("up") forming an orthonormal basis of R³ and a vector c to the origin of the object's coordinate system. Then the transformation from local to "world coordinates" is easy: If x is a vector ("point") in local coordinates, use the transformation matrix T:=(f, r, u) and the translation vector c to obtain the corresponding vector x in world coordinates: x = Tx + c.

Now the inverse transformation, i.e. from world to local coordinates, is not difficult either: Remembering that the inverse of an orthogonal matrix (such as T) is just its transpose (T'), we obtain

`x = T'(x-c)`

When the object "rotates/changes position," matrix T and vector c change correspondingly.

Discussion stats
• 2 replies
• 245 views
• 0 likes
• 3 in conversation