Location, Orinetation, Frames blog

Everything DG Kernel: Technical discussions and issues
Post Reply
Nick
Site Admin
Posts: 20
Joined: Fri Jun 14, 2024 12:35 am

Location, Orinetation, Frames blog

Post by Nick »

Hello friends

This is a restoration of another important thread containing informal discussion of frames. It is likely will be done is several passes.

In DGK we use Frame notion to represent and manipulate the very important location and orientation. Other software often use quaternions and/or matrixes for the same thing. We chose frames because of its intuitive nature.

A 3D frame is a set of 3D axes defined by a 3D location and orientation. Orientation is defined by a set of mutually perpendicular vectors for each axis. IFrame_DG is the interface.

We think of 3D space as defined relative to a single set of main axes called global. By default, any frame is global. This means its origin coincides with the origin of the global axes (all coordinates are zero) and axes are: (1,0,0), (0,1,0), (0,01).

IFrame_DG.Translate*() methods modify the location only. IFrame_DG.Rotate*() methods modify the orientation only.

When we say a point has coordinates pt(x,y,z) without mentioning anything else, we mean the coordinates are relative to the global axes. When we have another frame fr, we can define coordinates of the same point relative to this new frame. They will be different, of course. fr.ToLocal(pt) returns coordinates relative to fr. IFrame_DG.ToGlobal() does the reverse.

Notice that vectors have their own implementation of these operations.
Nick
Site Admin
Posts: 20
Joined: Fri Jun 14, 2024 12:35 am

Converting coordinates from frame to frame

Post by Nick »

If you have two different frames fr0, fr1 and a point pt relative to fr0, use

Code: Select all

PointDg ptGlob = fr0.ToGlobal(pt);
PointDg ptInFr1 = fr1.ToLocal(pt);
The same for all other basic types: vectors, lines and planes.
Nick
Site Admin
Posts: 20
Joined: Fri Jun 14, 2024 12:35 am

Multiplication of frames

Post by Nick »

We have defined a frame as a point and three vectors, so if you have a frame fr. and another frame frOther, you can construct a new frame by applying fr.ToGlobal() to the elements of frOther.

This is what IFrame_DG IFrame_DG.ToGlobal(IFrame_DG frame) does.

This is considered as multiplication of frames. Sadly, there is no operators for interfaces. It would be nice to write in code

Code: Select all

IFrame_DG frProduct = fr * frOther;
This operation is not commutative: fr * frOther is not always the same as frOther * fr

The global frame (let us denote it I) is identity wrt this multiplication: I * fr == fr * I == fr for any fr.

Any frame has an inverse, such that product with the inverse is the identify. It can be computed using IFrame_DG.Invert(). This means that any two frames can be divided.
Nick
Site Admin
Posts: 20
Joined: Fri Jun 14, 2024 12:35 am

Frames and Transformations

Post by Nick »

Every frame defines an affine transformation of 3D space:

For a given frame fr, the transformation transforms each point pt(x,y,z) into the point, which has the same (x,y,z) coordinates relatively to fr.

Transformations can be multiplied, of course: (A*B)(x) = B(A(x)). This definition agrees with the multiplication operation defined above.

The global frame I mentioned above is mapped to identity transformation. Sometimes we mix things up and call the global frame identity frame
Nick
Site Admin
Posts: 20
Joined: Fri Jun 14, 2024 12:35 am

Frames and matrixes

Post by Nick »

Matrixes are tables of numbers. If we consider only orientation of a frame and ignore the origin (location), fames can be mapped to size three square matrixes with determinant of 1.0.

To convert a frame f to matrix M one needs to take coordinates of the first, etc. axis of f and make it the first, etc. column of M.

Generally, a frame with an arbitrary location is mapped to 4x4 matrix, bult similarly to the above (use zero for the last element in each column) and the fourth column should contain three coordinates of the origin and be extended with 1.0 as the last element. Determinant of such 4x4 matrix will still be 1.0.

Matrixes can be multiplied. The above mapping preserves multiplication of frames the way we have defined in the previous post.

This is written in little nicer notation in this document: FramesVsMatrices.pdf
Post Reply