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: How to obtain normals?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2000
    Posts
    5

    How to obtain normals?

    I've got a simple question (and let's hope the answer will also be simple).
    Take 3 vertex that form a triangle.
    Vertex1=(1,1,1)
    Vertex2=(2,2,2)
    Vertex3=(3,3,3)
    What's the formula to obtain the normal of this plane? Thanks in advance and sorry for my bad english (i'm from Quebec)...

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: How to obtain normals?

    Hello

    You can calculate the normal by using cross products.

    p1, p2 and p3 is your three points in space.
    v1 is a vector from p1 to p2
    v2 is a vector from p1 to p3

    n is the normal calculated by using crosspruduct, v1 x v2.
    v1.x = p2.x - p1.x
    v1.y = p2.y - p1.y
    v1.z = p2.z - p1.z

    v2.x = p3.x - p1.x
    v2.y = p3.y - p1.y
    v2.z = p3.z - p1.z

    n.x = (v1.y * v2.z) - (v2.y * v1.z)
    n.y = (v1.z * v2.x) - (v2.z * v1.x)
    n.z = (v1.x * v2.y) - (v2.x * v1.y)

    You have to be carefull with how you cross the two vectors. If you cross them 'in the wrong order', your normal will be pointing the wrong way. You might have to swap v1 and v2. (v1 x v2) != (v2 x v1)

    Bob

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2000
    Posts
    5

    Re: How to obtain normals?

    Thanks! Exactly the kind of answer i was waiting for!

Posting Permissions

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