#### Archived

This topic is now archived and is closed to further replies.

# Normal Vector of a polygon

This topic is 5806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How can we get a normal vector of a polygon consisting Point1-n ?? I''m sorry but I seem to misunderstood between normal vector and normal point ?? Can someone explain it to me ? Thanks..

##### Share on other sites
CrossProduct(points[2]-points[1],points[0]-points[1]);

[edited by - sjelkjd on November 21, 2002 1:34:41 AM]

##### Share on other sites
Well...if its a 3 pointed polygon(doesnt have to be) then you need to attain 2 vectors from the actual polygon.

I personally would do this after rotating the vertices but BEFORE projecting the vertices onto the screen.

So, like I said, get 2 vectors

vector1 from point 0 to 1(below)

Vector1X = Polygon(point0 , x) - Polygon(point1 , x)
Vector1Y = Polygon(point0 , y) - Polygon(point1 , y)
Vector1Z = Polygon(point0 , z) - Polygon(point1 , z)

vector2 from point 1 to 2(below)

Vector2X = Polygon(point1 , x) - Polygon(point2 , x)
Vector2Y = Polygon(point1 , y) - Polygon(point2 , y)
Vector2Z = Polygon(point1 , z) - Polygon(point2 , z)

Right, excellent! We have the 2 vectors!
BTW, the points have to be unique(i.e. between these 2 vectors, they required 3 UNIQUE vertices(0X0Y0Z , 1X1Y1Z and 2X2Y2Z were all unique)

The next part depends on what you want to do with the polygons in question...

if you want to use the normal for back-face culling, (and I''ll assume this is all you want to do with it right now)

then your next step is in getting the actual Normal:-

NormalX = (Vector1Y * Vector2Z) - (Vector1Z * Vector2Y)
NormalY = (Vector1Z * Vector2X) - (Vector1X * Vector2Z)
NormalZ = (Vector1X * Vector2Y) - (Vector1Y * Vector2X)

There you have it...The 3 Normal(N) variables above contribute to make the 3D Normal of the polygon...

You may also have wanted to use this normal to check for lightsourcing, in which case you would have needed to NORMALISE the normal(i.e. setting its length to 1)

You still need to do one other thing tho, in order to use the Normal for back face culling...you need to get an additional vector from the cameraXYZ to the first point in your polygon(i.e. Polygon(Point0 , n), like so...)

NewVector1X = Polygon(point0 , x) - camx
NewVector1Y = Polygon(point0 , y) - camy
NewVector1Z = Polygon(point0 , z) - camz

Yay...so we have 2 Normals(or vectors) one facing away from you sitting at your computer, and one looking away from the polygon!

Next, the finishing calculation is:

If (NormalX * NewVectorX) + (NormalY * NewVectorY) + (NormalZ * NewVectorZ) > 0

Your Polygon is looking AWAY from you!

ELSE

Your camera CAN see the polygons face

End if

A few things to note:

Doing this for every rotation can be slower than

-> Calculate the Normal for every polygon at start of your program, and keep it these precalculated values

-> Treat the normal like a vertice and rotate them all, this way the normal is ALWAYS facing away from the polygon(the normals should be rotated around their own axis, i.e. rotate them around 0 , 0 , 0

If you want the light-sourcing info then post back and I will explain this too...and lastly, if you are anything like me (a slight bit thick!) then it may take you some time for this info to sink in...please reply either way...if you undertood it or not!

Kevin.

(BTW...I think a normal IS a vector, both describe a direction and a length!, but I''m not sure about this, it helps me to think of them as one and the same!)

:-)

##### Share on other sites
Oh and...the above code will work on a polygon 3 points or above...as you only need 2 vectors from it to determine its normal...

The difference between a normal point and a normal vector ?

well...a vector describes a direction.

e.g.

1
0.5
-0.22

this is a vector in 3D space and basically means...

for every 1 right, it goes 0.5 up(or down, depending how you work with your dimensions :-), and 0.22 down(the opposite of the up or down in the Y)

Basically its an arrow...

The point is...well, if you add that vector to a point, any point, then you will get the point(which will be the tail) and the head(which''ll be the new value!)

I hope this explains a little bit, and any more experienced 3D programmers out there, please keep me right if what I''m saying isnt really true...:-) Thanks...:-)

Kevin.

:-)

1. 1
2. 2
3. 3
4. 4
Rutin
19
5. 5

• 14
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632926
• Total Posts
3009252
• ### Who's Online (See full list)

There are no registered users currently online

×