# Rotating to "sit" a unit on a triangle

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

## Recommended Posts

Hi guys, I'm trying to figure out how to rotate a unit model (RTS game) to "sit" on a triangle of any orientation. I have the 3 points that make the current triangle up, how do I work out how much to rotate on x/y/z to align properly on it? Maths isn't my strong point, and I have to keep hammering away at things like this to figure it out, so any help would be appreciated! :)) Thanks a lot

##### Share on other sites
Naive suggestion...

Take the surface normal of the triangle and the "up" vector.
Dot product gives the angle between the two vectors.
Cross product gives a rotation axis.

If the dot product is close to zero, do nothing.

Otherwise, normalize the result of the cross product, then do an arbitrary-axis rotation using acos(dot product) as the amount of rotation. Depending upon ordering of the cross product, you might need to negate the angle.

Or as pseudo code:
float angle = dotProduct(surfaceNormal, upVector);
if (angle > 0.001) {
vector axis = crossProduct(surfaceNormal, upVector);
}

Caveat: I'm a programmer, not a mathematician, so at no time do I know what I'm talking about.

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 10
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631751
• Total Posts
3002088
×