#### Archived

This topic is now archived and is closed to further replies.

# Vectors, rotations and some 3d.

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

## Recommended Posts

Ok, here is the thing. I''ve got two points in 3d, i get the vector between them (with the substraction), now I have an object (say a cylinder) on the origin, what i need is to rotate that object and translate it to point #1 and rotate it to fit the position of the vector, in other words rotate and translate the cylinder, so one face will be on one of the point and the other face in the second point. What im doing is: vector=point2-point1 vec2=vector projected on XY plane (so z becomes zero). angle=angle between vec2 and Y axis. rotate angle degrees about the Z axis. vec2=vector projected on YZ plane (so x becomes zero). angle=angle between vec2 and Y axis. rotate angle degrees about the X axis. translate to point1 and draw where vec, is the vector between my two points. I first project my vector in the XY plane, and get the angle, then rotate about the Z axis, the next step is project it into the YZ plane and do the same (now rotate about the X axis), then translate. but it doesnt work. Has any of you any idea how to make it work? I posted this message on OpenGL forum, but its not a debugging problem, is more like a math problem, so I came here to ask your help.

##### Share on other sites
i think you should look into rotating objects by an arbitrary axis by a specified amount.

make a vector pointing from the centre of the object to the point you want to align to somewhere, take the vector from the centre of the object to the point you want to align to, and then the general idea is, to take the normalised crossproduct of the two to get the axis to rotate around, and take the dot product of both normalised vectors to get the amount to rotate by. then use some formulas to be found in the tutorials section to get the matrix representing this exact rotation, and apply it to your orientation matrix, and voila...

the last tutorial under the section quaternions covers this all i believe.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 17
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632660
• Total Posts
3007698
• ### Who's Online (See full list)

There are no registered users currently online

×