V
V
Vadim Chernov2015-01-03 12:03:24
Mathematics
Vadim Chernov, 2015-01-03 12:03:24

By what formulas to calculate the new coordinates of an object in three-dimensional space with relative displacement?

Since last year, I have been tormented by the question, because my imagination is not enough.
Given:
The x, y, z coordinates of the object in space are absolute;
The rotation angles of the object along all three axes in degrees are rotations relative to an absolute vector, so to speak.
Task:
Calculate offsets along all axes in absolute coordinates for offsets in local deltas for the object: dX, dY, dZ.
As I understand it, this can be solved with the help of elementary knowledge in trigonometry, school sines and cosines. But that was a long time ago, my imagination does not hold three axes at the same time, etc.
I feel that matrices would solve all problems, and it's more convenient to store data about coordinates and a vector this way... But it's important to solve the problem at this level of abstraction: real coordinates and rotation angles in degrees.
We need an object method:

object->move(2 right, 1.5 up, 15 back)

Maybe something from the Qt library already knows how to solve such problems? (Alas, QTransform is only for 2D and QMatrix3x3 matrices).
public void moveRelativeBy(float deltaX, float deltaY, float deltaZ)
{
this->position.x += // ???
this->position.y += // ???
this->position.z += // ???
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
suslik2015, 2015-01-03
@suslik2015

Transferring a point with coordinates (x,y,z) to a vector (dx,dy,dz) is done by simply adding all the coordinates. That is, the result is (x+dx,y+dy,z+dz).
The rotation through the angle alpha around the Z axis is obvious:
x' = x*cos(alpha)-y*sin(alpha)
y' = x*sin(alpha)+y*cos(alpha)
z' =
z other axes of rotation (i.e. Ox, Oy). Rotation about an arbitrary axis passing through the origin can be done using these rotations - rotate about Ox so that the axis of rotation becomes perpendicular to Oy, then rotate about Oy so that the axis of rotation coincides with Oz, make the actual rotation, and then reverse rotations about Oy and Ox. You can even derive formulas for such a rotation and see that they are very cumbersome. That is why matrices are used. In addition, matrices provide significant optimization.
In general, it is better to use quaternions right away. Euler angles have a serious drawback - the so-called hinged lock.

X
xmoonlight, 2015-01-03
@xmoonlight

matrix transposition read...

M
Mrrl, 2015-01-03
@Mrl

First you need to clearly define what the "Angles of rotation of the object along all three axes" are. Since the rotations do not commute, then specifying a rotation by several angles is always a sequence of rotations about some axes by a certain angle (or a rotation around one vector - but this is already a quaternion representation). For example, Euler angles are a sequence of rotations about OZ, OX, and again OZ.
If you have an object obtained from a base object by a sequence of rotations (OX, a), (OY, b), (OZ, c) (a, b, c - angles in radians), and there is a vector (dx, dy, dz) in the local coordinate system of the rotated object, then you can get the shift of the object by this vector in the global coordinate system as follows:
dy1=cos(a)*dy+sin(a)*dz; dz1=-sin(a)*dy+cos(a)*dz; // rotation relative to OX
dx1=cos(b)*dx-sin(b)*dz1; dz2=sin(b)*dx+cos(b)*dz1; // rotation relative to OY
dx2=cos(c)*dx1+sin(c)*dy1; dy2=-sin(c)*dx1+cos(c)*dy1; // rotation relative to OZ
Then (dx2,dy2,dz2) is the desired shift vector.
If the angles are in degrees, they are converted to radians by multiplying by pi/180.
As a general rule, the coordinate transformation that was used to move an object from its base state to its current state is the same transformation that is used to translate coordinates from the object's current local coordinate system to the global coordinate system.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question