# Move and Rotate a point around a new origin

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• Jan 27th 2011, 09:29 AM
Liger
Move and Rotate a point around a new origin
I'm trying to do something like this:
Attachment 20612

The pyramid is linked to the box. I have the positions and rotations of both the green box and the green pyramid. The axis intersecting the green box is at (0, 0, 0) with a rotation of (0, 0, 0). I want to move and rotate this group to the new axis centered in the purple box. I have the position and rotation of the purple box. What I need to know is how to calculate the new rotation and position of the red pyramid.

It's been quite a while since I've done stuff like this, so if someone could help me with formulas and how to use them to calculate the new rotation and position, I would appreciate it.

Here's an example if it would help:
Green box position: (0, 0, 0)
Green box rotation: (0, 0, 0)
Green pyramid position: (-24.81, 43.0345, 4)
Green pyramid rotation: (0, -0.22, 0.64)

Purple box position: (49.4771, 90.9461, 61.0026)
Purple box rotation: (-0.12217, -0.2967, 0.38397)
Red pyramid position: (?, ?, ?)
Red pyramid rotation: (?, ?, ?)

I'm working on this for a game.
If I use the mission editor, I can get the location and rotation of the red pyramid, and it is:
Red pyramid position: (10.6201, 120.922, 52.3397)
Red pyramid rotation: (-0.274722, -0.386207, 1.01696)

Unfortunately, there is no way to access the function the mission editor uses to rotate the group, so I need math formulas so I can manually do it.

Thanks,
Liger
• Jan 27th 2011, 10:25 AM
Ackbeet
I have a few questions for you.

1. It appears possible that you could rotate first and then translate. Is that correct? I mention it because the order matters.
2. I have no idea what your rotation vector is. Is that a rotation about the x, y, and z axes, respectively? Or Euler rotations?

What might help to determine the answer to question 2, if you don't already know the answer, is, if you have the option of querying the mission editor, to put in, say, a 90 degree rotation about the x axis with no translation, then one about the y axis with no translation, and finally one about the z axis with no translation. Then I can see better whether you're working in radians or degrees, and what each number means. Does that make sense?
• Jan 27th 2011, 10:38 AM
Liger
Quote:

1. It appears possible that you could rotate first and then translate. Is that correct? I mention it because the order matters.
Yes, the pyramid can be rotated first, and then moved.

Quote:

2. I have no idea what your rotation vector is. Is that a rotation about the x, y, and z axes, respectively? Or Euler rotations?
The rotations are in radians, and are x, y, and z axes respectively. The positions are also, x, y, and z axes respectively.
• Jan 27th 2011, 10:50 AM
Ackbeet
Ok, here's the question I am now asking myself: why isn't the red pyramid's rotation the same as the purple box's rotation? For that matter, why isn't the green pyramid's rotation the same as the green box's rotation (zero)?
• Jan 27th 2011, 11:13 AM
Liger
The image is just an example to help explain the situation. In actuality, the green pyramid is slightly rotated. I can get an actual picture if that will help.
• Jan 27th 2011, 11:30 AM
Ackbeet
The actual picture wouldn't hurt, I'm sure. One more question: are these rotations happening "in place"? That is, does the rotation of a pyramid, say, affect its position, or not? Perhaps you can visualize in your mind the difference between rotating a cylinder centered at the origin about any axis (thus, not changing its position but merely its orientation), and rotating a cylinder that is not centered at the origin about any axis (which will affect its position).
• Jan 27th 2011, 11:38 AM
Liger
Here's the image:
http://img375.imageshack.us/img375/9610/rotated.png

The left side correlates to the green box and green pyramid.
The right side correlates to the purple box and red pyramid.

The big base is the box, and the antenna with the green dot is the pyramid.

I took the base and antenna, and moved it to a new location with a new rotation as well. The bases and antennas have the same values as posted in the initial post.
• Jan 27th 2011, 11:46 AM
Ackbeet
So I take it the antenna's position is fixed relative to the base. Correct? And the rotation you're actually doing with the antenna is sort of "about its long axis", right? Like a periscope?
• Jan 27th 2011, 12:01 PM
Liger
Quote:

Originally Posted by Ackbeet
So I take it the antenna's position is fixed relative to the base. Correct?

Yes

Quote:

Originally Posted by Ackbeet
And the rotation you're actually doing with the antenna is sort of "about its long axis", right? Like a periscope?

I select both objects and rotate them as a group, that way the antenna does not leave that spot on the base.
• Jan 27th 2011, 12:06 PM
Ackbeet
So is the antenna always facing the same direction relative to the base? Forget the base rotation for second: it looks like you're rotating the antenna on its spot. It's revolving, like a revolving door. Is that rotation happening? Or is the antenna's direction always fixed relative to the base?
• Jan 27th 2011, 12:11 PM
Liger
It is physically attached to the building and cannot move from that spot. The game does not know this, so I must place it there manually.
• Jan 27th 2011, 12:15 PM
Ackbeet
Ok, got that, but what I'm really after is whether the antenna can rotate about its fixed spot. Think of the antenna as a spinning top, spinning in place. Is that kind of rotation allowed?
• Jan 27th 2011, 12:20 PM
Liger
Yes, it has a Z-axis that would allow such a rotation. I can rotate the antenna however I want. I just need it to look like it hasn't moved in the end result.
• Jan 27th 2011, 01:52 PM
Ackbeet
Ok. I think I've got my mind wrapped around this problem. You're going to need a number of translations and rotations. You can do rotations with rotation matrices. But those rotations are only valid for rotations about the normal x, y, and z axes. They are not valid for rotations about an arbitrary axis. Therefore, in order to use them properly, you're going to have to translate and rotate until things are lined up correctly. Here's the algorithm as I see it:

1. Translate the base-antenna system until the base of the antenna is at the origin.
2. If necessary, rotate the base-antenna system until the antenna is lined up with either the x, y, or z axes.
3. Rotate the antenna by itself about its now-aligned axis until its orientation relative to the base is correct.
4. Rotate the base-antenna system as desired.
5. Translate the base-antenna system as desired.

That should do it. Do you need more details, or is this enough to be going on with?
• Jan 27th 2011, 02:33 PM
Liger
How do I mathematically compute each of those? There is no means to "rotate by", only to assign world coordinates and rotations. So I need to be able to calculate the new location (x,y,z) and rotation (i,j,k) of the antenna based on the initial offset from the origin and by knowing the new position and rotation of the new base's coordinates and rotation.
Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last