0
\$\begingroup\$

Lets say I have a triangle defined by 3 vertices and a center point, how do I rotate the triangle so its normal is looking at a specified point?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Given points A, B and C of a triangle, the normal of the triangle is the cross product AB×AC (or possibly AC×AB depending on the vertex order). If the point on the triangle is M and the point towards which to look is P, you then have an infinite number of rotations that cause AB×AC to be in the direction of MP. The shortest rotation of them all can be computed using a quaternion from two vectors method. The final tranformation is therefore:

  • subtract M from all triangle points so that the triangle centre is at the origin
  • rotate all points using the quaternion described above
  • re-add M to all triangle points

In pseudocode:

tranform = translate(OM) * rotate(quaternion(cross(AB,AC), MP) * translate(MO)
\$\endgroup\$
2
  • \$\begingroup\$ Could you explain translate(OM)? Im new to game dev and unity! \$\endgroup\$
    – MarsYeti
    May 9, 2016 at 0:49
  • \$\begingroup\$ It is a translation along OM, which is a vector that goes from the origin to M. If these are difficult concepts for you, I suggest starting with some simple Unity3D tutorials. \$\endgroup\$ May 9, 2016 at 6:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .