View Full Version : Finding if a point is in front or behind a plane

overTaker

03-05-2014, 06:37 AM

The question is how to find, if specified point is behind a plane. And by plane I rather mean a point with a given direction.

Let's say the plane is a point A with direction dirA, and the point we want to check is B

My thoughts were to check if dot product of dirA and a vector, that represents the length from the "plane" to the point B. But the thing is that vector would need to be perpendicular to the plane, and I got no idea how to get that vector.

Is my concept right? If it is, how do I get the vector I need?

Brokenmind

03-05-2014, 07:03 AM

The general prodecure would be this, as you already stated:

vec normalA;

vec AB = B - A;

double dot = dot(AB, normalA);

bool inFront = (dot > 0);

Of course you need the normal of the plane; with only one direction parameter of the plane, this task can't be solved. Which information do you have, or rather what do you mean by "point A with direction dirA"? A small sketch would be helpful and might answer the question to yourself ;)

overTaker

03-05-2014, 07:48 AM

I actually tried doing it this way, but it didn't work.

Perhaps an explanation will be better than a picture :)

Try to imagine a a vertex with a normal. Then, imagine a plane that is perpendicular to that normal. Now my goal is to check if different point lies on the side that normals points at, or at the opposite one.

I think the error is in AB = B - A, since A is not perpendicular to B.

I imagine it like this. The picture itself is 2D, but it should work the same for 3D.

http://i57.tinypic.com/2vunhj4.png

Brokenmind

03-05-2014, 08:00 AM

A is not perpendicular to B... how can a point be perpendicular to another point? :D

What you've drawn is correct... if you have the normal, which is normalA in my formula, and have the points A and B, you have everything you need.

dot(normalA, AB) basically gives you a hint about the angle between the two vectors. If the vectors are perpendicular, i.e. if B lies in your plane, the dot product is 0.

It is >0 if the angle is <90° and <0 if the angle is >90°. Maybe you could try to calculate it for test values to see if it is correct.

overTaker

03-05-2014, 08:28 AM

I meant A as a plane :)

It actually works fine when I try with test values. I must did something wrong in the actual code.

Big thanks!

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.