Skip to main content
gamedev.net
🔒 Locked

normal problem

Started by hello_there Jan 27, 2003 at 8:00 PM 1 replies 250+ views
Original Post
hello_there
hello_there
is there anyway to see if a point is infront of or behind a normal? ei the point is behind a wall or infront of it. [edited by - hello_there on January 27, 2003 12:04:20 AM]
____________How could hell be worse?
nail85
nail85
Get dot product of normal vector and your''s vertex vector. If it > 0 then it ahead, otherwise behind.

Vector n = GetMyNormal();
Vector v = GetMyVertex();
if (dp(n, v) > 0) {
// Ahead
...
}
else {
// Behind
...
}
Paradigm Shifter
Paradigm Shifter
Yes.
Say you have a point p and a normal n. Let f be a fixed point on the plane you want to test for in front/behind (usually defined by a triangle so use any one of the vertices).

Then

p - f == vector from f to p

dot product this with n, the plane normal. If this is positive then (p-f) and n are facing in the same direction, i.e. you are "in front" of the plane. If it's negative, (p-f) and n are facing in the opposite direction, i.e. you are on the 'tother side. If it's zero, you are incident to the plane.

The dot product result also gives you the perpendicular distance from the point to the plane (since n is normalised).

Bingo.

EDIT: nail85 was quicker but got the answer a bit wrong (only works for planes thru the origin).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

[edited by - Paradigm Shifter on January 28, 2003 6:48:18 AM]
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.