Rotating an object around another object in all axis

say if I have an object at a certain position and i want to go to a certain position in another object by going around the object instead, how do i do that?

i mean situation like this is simple
i can just rotate the point around the pivot object center position (blue) and uses (0, 1, 0) as my axis as it only rotates around the Y axis.

my problem is say the original position is somewhere with x, y and z values, that means i need to rotate it in all axis. such as this drawing

Now i need to figure out the axis to rotate to, and i am confuse on how to compute this rotate axis to get the new position.

one idea i have is to get the difference between each axis, and use it as an angle and rotate them individualy using each axis.

angleX = targetX - origX
angleY = targetY - origY
angleZ = targetZ - origZ

new X position = rotate in axis (1,0,0) with angleX
new Y position = rotate in axis (0,1,0) with angleY
new Z position = rotate in axis (0,0,1) with angleZ

Anyone got better idea or something to help?

You can also orbit things around other things using quaternions. To just make the orbiting object jump to a target position:

1. Create the â€śplanetâ€ť to orbit around.
2. Create a group and place it at the same position as the â€śplanetâ€ť.
3. Create the â€śmoonâ€ť object and add it to the group - then move the â€śmoonâ€ť within the group away from the origin point to create the orbit radius.
4. Use Object3D.lookAt to point the group from point 2 towards the target position - effectively placing the â€śmoonâ€ť at the target position.

Alternatively, for a smooth movement:

1. Create the â€śplanetâ€ť.
2. Create a group and place it at the same position as the â€śplanetâ€ť.
3. Create and add the â€śmoonâ€ť object to the group - then move the â€śmoonâ€ť within the group away from the origin point to create the orbit radius.
4. Create a second group / empty Object3D - an invisible mock - and place it at the same location as the â€śplanetâ€ť.
5. Use Object3D.lookAt to point the mock towards the target point / position you want the â€śmoonâ€ť to be at next. That will set the quaternion of the mock to point at the target position.
6. Use Quaternion.slerp to smoothly transition quaternion of the group from point 2 to the target position.

Example

4 Likes