Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Given the point

Vector pos = new Vector(0.0, 0.20156815648078918, -78.30000305175781, 1.0);

and the plane (triangle)

Vector a = new Vector(-6.599999904632568, 0.0, -78.5, 1.0);
Vector b = new Vector(6.599999904632568, 0.0, -78.5, 1.0);
Vector c = new Vector(6.599999904632568, 4.400000095367432, -78.5, 1.0);

I want to get a plane normal pointing in the direction of pos

//Getting plane normal
Vector ac = Vector.Subtract(a,c);
Vector bc = Vector.Subtract(b,c);
Vector planeNormal = Vector.CrossProduct(bc, ac);

//Testing which side of the plane the point is on
double dprod = Vector.DotProduct(planeNormal, pos);
if (dprod < 0)
{
    planeNormal.Negate();
}

But this method is wrong. The resulting planeNormal points in the negative Z direction, so it should not be negated. Is there a best practise for this? Please help me, I fail massively @ math :)

share|improve this question
    
I'd normalize the normal, if you're using a similar method for lighting calculations. –  Ray Dey Apr 23 '11 at 2:18
add comment

1 Answer

up vote 7 down vote accepted

Your method is mostly correct but misses one step. You can't simply use the point's position as the vector to get a dot product with, you need to create a direction vector from a point on the plane. Any point on the plane will do (the direction doesn't need to be exact) so just use one of the corners.

share|improve this answer
    
Thanks! –  Daniel Szalay Apr 23 '11 at 2:29
    
Cool. Why doesn't it matter which point on the plane is chosen? –  Cameron May 15 '12 at 2:52
    
Because you're only looking for positive or negative from the dot product at the end. Regardless of the exact value calculated, the dot product is positive for vectors pointing at one side and negative for vectors pointing at the other. –  jhocking May 15 '12 at 12:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.