Advertisement

calculating normals

Started by January 13, 2001 02:44 AM
5 comments, last by m9 23 years, 10 months ago
Hello! Somebody, please tell me how to calculate normals for a square. I have a square consisting of 4 points. (a.x, a.y, a.z, b.x, ...) But how do I give that square a normal? I would like to see some code, not some replies like: search the net... thanx. --- marius http://fr.ee/linux
---conehttp://cone.cz.eePS. The Dog Ate My Homework
It is very easy, if you make the assumption that your rectangle is flat.

just do it like this:

a-----b
|ooooo|
|ooooo|
c-----d


no you just need to do the cross product between two of the vectors going from one of the point to the two points next to it.
example:

normal = (c - a ) x ( b - a )

Simple!

there are problems though..
you shading wont be nice though if you just use one normal for each surface..
and the method i have shown will give you the same normal for each corner, so that wouldnt help either..


Edited by - ZubZorro on January 13, 2001 4:00:23 AM
Jonas Meyer Rasmussenmeyer@diku.dk
Advertisement
The normal of any point on a polygon (triangle, quad, octagon, etc...)

v1 = lastpoint - currentpoint;
v2 = nextpoint - currentpoint;

normalize v1 and v2

calculate the cross product of v1 & v2
The result is the normal for the current point.

I also have a page about this at
http://tannara.2y.net/Graphics/Theory/finding_the_normal_of_a_surface.htm

l8r,
Rob
http://tannara.2y.net/
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Once you find the normal of the surface, would you then set the normal of each of those vertexes to the calculated surface normal?
ok VERY basic question.. by lastpoint-currentpoint do you mean the distance between them? i.e sqrt(x^2+y^2+z^2). or is it
vector1.x = lastpointx - currentpointx
vector1.y = lastpointy - currentpointy
vector1.z = lastpointz - currentpointz
The second. When I wrote v1 = lastpoint - currentpoint I meant it as vector math so...
v1.X = LastPoint.X - CurrentPoint.X;
v1.Y = LastPoint.Y - CurrentPoint.Y;
v1.Z = LastPoint.Z - CurrentPoint.Z;

I''ve also updated my page with calculating normals with some sample code.

http://tannara.2y.net/Graphics/Theory/finding_the_normal_of_a_surface.htm

l8r,
Rob
http://tannara.2y.net/
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Advertisement
Thanx, everybody. Got them working.
i needed them on a terrain engine that I was creating. But now the entire terrain is all blocky. Check the url below for the topic.

http://www.gamedev.net/community/forums/topic.asp?topic_id=37246


---
marius
http://fr.ee/linux
---conehttp://cone.cz.eePS. The Dog Ate My Homework

This topic is closed to new replies.

Advertisement