# 3D object rotate

This topic is 1041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone ,

not sure if this should be in this forum or the maths but basically i have two objects in my scene and i want to connect them with a cube , so i understand how to position the object in between the two points and i can scale the z axis to the distance between them i get that part

my problem is i need to know how to work out the rotation in order for this cube to align with the two points and i have looked all over the internet and nothing is working for me

essentially i have a rotationx,y,z so i need to know these values in order to put them in , unless i should be using a different method in order to rotate?

any advice would be great please and i am more than happy to show any code needed in order to help explain more

my two points are situated at (-10,0,0) and then (10,0,0) so in theory i should end up with x = 0 , y = 0/180, and z = 0 but i cannot get this work

Thanks

##### Share on other sites

two approaches:

1. the local origin of the cube is in the center of the cube. you place it half way between the two points you want to connect, and rotate appropriately.

2. the local origin of the cube is in the middle of the bottom of the cube. you place it at the first point, then point the local Y (up) axis of the cube at the second point. this tends to be easier.

for the first approach, lets see, its still the same basic case - you point the cube's local up axis at the second point

odds are, what you want is the algo to convert a direction vector into XR and YR global euler rotations:

in your case, this would mean moving the direction vector going from the cube center to point 2, to the origin.

project the vector onto the x-z plane. determine the angle between the projection and the z axis. this is your YR euler angle amount.

un-rotate the vector around Y by this amount, so it lies in the Y-Z plane. use "transform point by rotation matrix" for this.

determine the angle between the un-rotated vector and the Z axis. this is your XR euler angle.

note that ZR, (IE roll) is up to you, with "no roll" being the typical solution.

Edited by Norman Barrows

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633765
• Total Posts
3013730
×