2
$\begingroup$

My Current Setup:

Let's assume we have these 3 axes in 3d space.

3D Axes Let's also assume that x = blue; y = red; green = z;

To calculate a rotation on the x axis, i.e., from point A->E, we can calculate that by doing

p1 = A
p2 = Origin (Gray)
p3 = E

XAngleInRads Formula

This would also work for A->C, however, to get the circular behavior we want, we need to do

enter image description here

All of this works great :)

Now for,

The Problem:

So far, I have my X-Axis Rotation down perfectly. I am looking to rotate the Y and Z axis in such a manner that I NEVER rotate the INITIAL Z axis.

Let's say I have 2 objects, object O and object P as noted on the picture. The goal is that as O translates and rotates, that P will only rotate to face O. However, we do NOT want the orientation of P to follow the orientation of O.

Test Cases:

Assume all rotations occur from Origin, so if we rotate O, then it moves. If we rotate P, it just turns.

Let's start O at position A and P at position Origin. If we orient (rotate about Z) by 90 degrees, we do NOT want P to move.

O Rotation (0, 0, 90) -- P Rotation (0, 0, 0)

Let's now rotate O from position A->E.

O Rotation (-90, 0, 0) -- P Rotation (-90, 0, 0)

Now, let's go from E-> B. This is a rotation about the Z axis, but we DO want to move, because if we rotate the orientation of O, it is not the Y axis that we do NOT want to rotate.

O Rotation (-90, 0, 90) -- P Rotation (-90, 0, 90)

Now let's get back to point A by reversing the rotations.

O Rotation (0, 0, 0) -- P Rotation (0, 0, 0)

Now let's rotate A->B but also rotate O 90 degrees about Z. Because the rotation orientation is now back to the Z axis, we do NOT want P to rotate about the Z. So we have

O Rotation (0, 90, 90) -- P Rotation (0, 90, 0).

Let's go back to point A

O Rotation (0, 0, 0) -- P Rotation (0, 0, 0)

Now, let's go 45 degrees from A->E so we have

O Rotation (45, 0, 0) -- P Rotation (45, 0, 0)

Now rotate from currentPosition->B. This rotation requires that part of Z and part of Y are both part of orientation. It is half. So, we don't rotate both Y or Z by 90 degrees, we rotate each by 45 degrees, since it X rotation is in between Y and Z axis.

O Rotation (45, 45, 45) -- P Rotation (45, 45, 45)

Final Problem:

So, I am in search of a formula to help me keep the "Initial Z Axis" locked, such that the orientation of P never changes at any rotation of X, Y, Z. You can see that I cannot just lock the Z axis for orientation, as at 90 and 270 degrees, the Z axis then becomes the Y axis, in terms of orientation. Any help in creating a formula as to rotate object O and P such that P rotates to follow O, however, if O rotates about orientation (spin), that P does not follow.

Edit1:

I have come up with the ratio of how much y (yRatio) and how much z (zRatio) according to the current xAngleInRadians. I'm just not sure what to do with these variables. I just know how much of Z and how much of Y we WANT to rotate. If O is at A, then we want 0(zero) Z rotation. If O is at E, then we want 0(zero) Y rotation. However, if O is 45 degrees between A and E, then we want 1/2 rotation for Y and Z.

(ZRatio, YRatio) for picture sake.

Ratio of Y and Z

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.