Results 1 to 4 of 4

Thread: Calculating Surface Normals

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2001
    Posts
    27

    Calculating Surface Normals

    Here's my situation:

    Let's say I have 3 verticies: v1,v2 and v3.

    how would I calculate a surface normal?

    assume that when the points are laballed counter-clockwise relative to you, the normal vector points towards you.

    example:


    v1

    v2

    v3

    the normal would be coming straight at you.

    how would I calculate the exact surface normal vector using the 3 sets of x,y, and z values?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2000
    Location
    Aurora, Illinois, USA
    Posts
    192

    Re: Calculating Surface Normals

    take the cross product... and by right hand rule the normal would face towards you.

    cross product can also be seen as the determinant of these three vectors:

    <i,j,k>
    <v2-v1>
    <v3-v1>

    correct me if I am wrong... it's been a little while
    Navreet Gill [img]/forum/images/%%GRAEMLIN_URL%%/smile.gif[/img]

  3. #3
    Junior Member Newbie
    Join Date
    May 2001
    Posts
    12

    Re: Calculating Surface Normals

    You simply do (in pseudocode) :

    rx1=v1x-v2x
    ry1=v1y-v2y
    rz1=v1z-v2z
    rx2=v3x-v2x
    ry2=v3y-v2y
    rz2=v3z-v2z

    nx=ry1*rz2-rz1*ry2
    ny=rz1*rx2-rx1*rz2
    nz=rx1*ry2-ry1*rx2

    Ok, now we have to normalize it (make length 1) :

    len=sqrt(nx*nx+ny*ny+nz*nz)
    if (len>0) {
    nx*=(1/len)
    ny*=(1/len)
    nz*=(1/len)
    } else {
    /* oops, you've got a problem */
    }


    That should be it. Enjoy

    Note : this might be for clockwise, I simply ripped it from some working code of mine. Simply invert the normal for counterclockwise if that's the case.

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2001
    Posts
    27

    Re: Calculating Surface Normals

    Thanks, guys!

    I actually just picked up an Algebra & Geometry textbook from my math teacher today, and got the necessary math from there. but thanks anyway!

Similar Threads

  1. Calculating normals.
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-05-2004, 11:24 PM
  2. Calculating normals
    By Vlasko in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-01-2003, 12:46 PM
  3. Calculating Normals
    By in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 02-27-2002, 11:08 PM
  4. Calculating Normals?
    By hooded paladin in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 11-12-2001, 11:33 PM
  5. Calculating Normals
    By Zadkiel in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 12-06-2000, 08:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean