Point behind/front of plane

Started by
9 comments, last by BornToCode 10 years, 11 months ago

Following http://www.gamedev.net/topic/106765-determining-if-a-point-is-in-front-of-or-behind-a-plane/ doesn't work

I have a plane with normal and distance along normal to plane from origin and a point I'm testing.


bool PointBehindPlane(Vec3f p, Vec3f normal, float dist)
{
	float result = p.x*normal.x + p.y*normal.y + p.z*normal.z + dist;
	// 1*286.852 + 0*2 + 0*423.175 + 289.256 = 286.852

	//if(result < 0)
	if(result < EPSILON)
		return true;

	return false;
}

As in the comment, it says the point (286.852, 2, 423.175) isn't behind the plane (1,0,0)d=289.256.

Advertisement

Nevermind. http://www.gamedev.net/topic/643305-line-convex-hull-intersection-not-working/

The sign of dist is wrong: points in the plane have p*normal=dist, i.e p*normal-dist =0, and (regardless of which side you conventionally choose as "behind") that is the equation of the threshold you should test.

With your convention, increasingly larger values of p*normal should be classified as "behind" the plane as dist increases.

Omae Wa Mou Shindeiru

So which is the usual convention, because I can make it work either way - is d the distance along the normal to the plane, or is it the distance FROM the plane TO the origin?

It doesn't matter as long as you are consistent.

For an actual infinite plane, "in front" probably means on the same side as the camera, not a predetermined halfspace; for the faces of a convex polyhedron, probably you want a point containment test which doesn't need to leak whether the face normals are all facing outwards or all facing inwards.

Omae Wa Mou Shindeiru

So which is the usual convention, because I can make it work either way - is d the distance along the normal to the plane, or is it the distance FROM the plane TO the origin?

D is the shortest signed distance to the plane from the origin, which is the distance along the normal of the plane, if the normal has unit length.

The equation of a plane is ab + by + cz + d = 0, where a, b and c are your normal components. In order to get an understanding of this equation, notice that this is the dot-product of an arbitrary point and the normal of the plane with some value d added to it. How does this equation describe a plane then? Taking the dot-product of some vector x and a normal vector n, gives us the length of vector x projected onto n. Now try to image what happens when you project any point that lies on the plane, onto the normal vector. It will give your the signed distance from the origin to the plane.

Does that help with your understanding of the problem?

The dot product is commutative, so if the vector is shorter than unit length, doesn't that give the projection of the normal onto the vector and make the result erroneous?
Lorenzo, my containment test in the other thread is for a line segment, thus the checks for each intersection point to see if its behind all the other planes.

So which is the usual convention, because I can make it work either way - is d the distance along the normal to the plane, or is it the distance FROM the plane TO the origin?

NOTE: I really tried hard but didnt get LaTeX equations to work in this post. Apparently eqn is broken
and services like codecogs.com forbidden. So I posted the LaTeX code verbatim, sorry.

Hi!

I think this has nothing to do with conventions, but derives from the plane equation:

Let N be the normal vector of your plane and P an arbitrary point in your plane. The plane is then described by the equation
p = \{ Q | N(Q - P) = 0 \} = \{ Q | N^TQ + D = 0 \}, where D = -(N^T)P So my D is your dist, in this case.

So let's compute the distance of this plane to the origin. First we calculate the closest point Q on the plane to the origin,
by shooting a line l through the origin in direction N. The intersection of line l and plane p is the point Q.
The equation for l is simply l = \{ N \lambda + 0 | \lambda \in \mathbb{R} \}

Let's compute Q by intersecting l and p:
\begin{align*}
& N(\lambda N - P) = 0 \\
\Leftrightarrow & \lambda N^TN - NP = 0 \\
\Leftrightarrow & \lambda = \frac{NP}{||N||^2} = -\frac{D}{||N||^2}
\end{align*}

So Q = -\frac{D}{||N||^2} N

When normalizing N, we get Q = -DN.

There you see the distance of the plane to the origin is |D|.
You are free to interpret the sign of D in this equation, but it's not a matter of
convention I think

The dot product is commutative, so if the vector is shorter than unit length, doesn't that give the projection of the normal onto the vector and make the result erroneous?

No, the absolute distance will just be smaller than 1.

This topic is closed to new replies.

Advertisement