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 5 of 5

Thread: Rotating to position...

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2004
    Location
    Campinas, SP, Brazil
    Posts
    6

    Rotating to position...

    Hi,
    I have a triangle with normal vector (nx,ny,nz),

    i want to rotate this triangle such that
    the normal vector be aligned with (0,1,0).
    i.e., after the rotation, all the vertices
    of the triangle will have the same
    y coordinate.

    how can i do this ?

    thanks in advance,
    [],

  2. #2
    Member Regular Contributor
    Join Date
    May 2000
    Location
    Philadelphia
    Posts
    285

    Re: Rotating to position...

    It may not be simpliest, but here you go:
    1) Find the angle, a, between (nx, ny, nz) and (0, 1, 0) using dot product,
    2) If a is zero, then stops
    3) if a is 180 degrees, then rotate the triangle by 180 degrees.
    4) Else, find the cross product of (nx, ny, nz) and (0, 1, 0)
    5) Rotate triangle around the cross product by a.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2004
    Location
    Campinas, SP, Brazil
    Posts
    6

    Re: Rotating to position...

    Thanks,
    it worked,

  4. #4
    Intern Newbie
    Join Date
    Oct 2003
    Location
    Russia, Moskow
    Posts
    38

    Re: Rotating to position...

    By the way, if I have a "(0,1,0)-normaled" triangle, and I want to face it to (nx, ny, nz)-normal, what should I do?

  5. #5
    Member Regular Contributor
    Join Date
    May 2000
    Location
    Philadelphia
    Posts
    285

    Re: Rotating to position...

    Originally posted by Freelancer:
    By the way, if I have a "(0,1,0)-normaled" triangle, and I want to face it to (nx, ny, nz)-normal, what should I do?
    Same thing except (nx, ny, nz) becomes (0, 1, 0) and (0, 1, 0) becomes (nx, ny, nz).

Posting Permissions

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