Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: please help me on this rotation!

  1. #1
    Intern Newbie
    Join Date
    Aug 2001
    Posts
    30

    please help me on this rotation!

    I have a triangle P1( 5,6,7) p2(-3,6,8) p3(1,3,7). I need to rotate this triangle, such that the triangle has a nomaln=(2,0,1).

    how do I perform this rotation?


    Many thanks!

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    587

    Re: please help me on this rotation!

    Create two vectors for two of the sides of the triangle and take the cross product:

    (p1 - p2) x (p1 - p3) = (3, -4, 24)

    This gives the (unnormalised) normal to the triangle. Take the cross product to the normal you want:

    axis[3] = (3, -4, 24) x (2, 0, 1) = (-4, 45, 8)/sqrt(2105) (normalised)

    which gives a vector orthogonal to both normals (the axis to rotate around). Calculate the following:

    angle = arccos( (3, -4, 24).(2, 0, 1)/(sqrt((3, -4, 24).(3, -4, 24)) * sqrt((2, 0, 1).(2, 0, 1))) ) = (approx.) 56.82 degrees

    which gives the angle to rotate. Pass this in as glRotatef(angle, axis[0], axis[1], axis[2]) == glRotatef(56.82, -4/sqrt(2105), 45/sqrt(2105), 8/sqrt(2105)). I hope that's all correct.

    Hope that helps.

  3. #3
    Intern Newbie
    Join Date
    Aug 2001
    Posts
    30

    Re: please help me on this rotation!

    Thanks,buddy!

    but should I move the world coordinate origin to the triangle?


    Originally posted by ffish:
    Create two vectors for two of the sides of the triangle and take the cross product:

    (p1 - p2) x (p1 - p3) = (3, -4, 24)

    This gives the (unnormalised) normal to the triangle. Take the cross product to the normal you want:

    axis[3] = (3, -4, 24) x (2, 0, 1) = (-4, 45, 8)/sqrt(2105) (normalised)

    which gives a vector orthogonal to both normals (the axis to rotate around). Calculate the following:

    angle = arccos( (3, -4, 24).(2, 0, 1)/(sqrt((3, -4, 24).(3, -4, 24)) * sqrt((2, 0, 1).(2, 0, 1))) ) = (approx.) 56.82 degrees

    which gives the angle to rotate. Pass this in as glRotatef(angle, axis[0], axis[1], axis[2]) == glRotatef(56.82, -4/sqrt(2105), 45/sqrt(2105), 8/sqrt(2105)). I hope that's all correct.

    Hope that helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •