Sign in to follow this  

3D object rotate

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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:

 

start with your direction vector pointing out from the origin.

 

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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this