Plane equation, + or - D

Started by
14 comments, last by fais 7 years, 6 months ago

Hi guys, quick question on the plane equation and finding if a point is on a plane or not.

Given a plane defined by a normal (ABC) and a distance from origin (D). I've read articles describing that a point is on the plane if it satisfies the plane equation:

Ax + By + Cz + D = 0

Which seems to me like it is the equivalent of:

DOT(ABC, xyz) + D = 0

These are the articles in question, tough many google results show the same thing:

http://gamedeveloperjourney.blogspot.com/2009/04/point-plane-collision-detection.html

http://www.xbdev.net/maths_of_3d/collision_detection/point_to_plane/index.php

So far so good, however after writing a few test programs, this does not seem accurate. I read "Real Time Collision Detection" by Christer Ericson, he gives this definition of a plane:


struct Plane {
	Vector n; // Plane normal. Points x on the plane satisfy Dot(n,x) = d 
	float d; // d = dot(n,p) for a given point p on the plane
};

By this definition, the equation of a plane should be

Ax + By + Cz = D

Meaning a point is on the plane if it satisfies:

Ax + By + Cz - D = 0

A quick google turned up this page, which seems to confirm the above assertion:

So, i guess my question is, what am i missing here!? Are these two different equations and i'm calling them by the wrong name? Is one of the sources i have wrong?
Advertisement

-d is the more "correct" version. Since it's a constant we can name it whatever we like, and even define d as -d. Point being, if you compute ax + by + cz you get a scalar, and this scalar is d. We end up with:

ax + by + cz = d

We can then move everything to one side:

ax + by + cz - d = 0

And, if we are so inclined we can re-name d to be positive:

ax + by + cz + d = 0

Why would anyone do this? Who knows. Personally I think it's annoying and should be negative.

I tend to use +D, since it’s consistent with transformations and the like:


   0 = Ax + By + Cz + D
?  0 = Px*Nx + Py*Ny + Pz*Nz + D
?  0 = (Px,Py,Pz,1) dot (Nx,Ny,Nz,D)
?  0 = (float4(pt.xyz,1)) dot (float4(normal,distance))

I mean, that's exactly what i'm confused about!

Let's assume D is a scalar

Ax + By + Cz = D

Now, if we do:

Ax + By + Cz - D = 0

The expands to

Ax + By + Cz - (Ax + By + Cz) = 0

If i just change the sign of D to positive for shits and giggles it becomes:

Ax + By + Cz + (Ax + By + Cz) = 0

I mean, it's not just me right, that's a VERY different equation! Like you can't just make a number positive for shits and giggles!

These two pieces of code return very different results!


bool PointOnPlane(Point point, Plane plane) {
	float result = plane.n.X * point.X + plane.n.Y * point.Y + plane.n.Z * point.Z + plane.d;
	return Math.Abs(0f - result) < 0.00001f;
}

bool PointOnPlane(Point point, Plane plane) {
	float result = plane.n.X * point.X + plane.n.Y * point.Y + plane.n.Z * point.Z - plane.d;
	return Math.Abs(0f - result) < 0.00001f;
}

OR are you saying that d in the definition of a plane:


struct Plane {
    Vector n; // Plane normal. Points x on the plane satisfy Dot(n,x) = d 
    float d; // d = dot(n,p) for a given point p on the plane
};

doesn't actually stand for distance from origin, rather a scalar?

OR are we saying that D in the plane equation and D in

d = dot(n,p) for a given point p on the plane

are two different distances, both just happen to be refered to as d. But one stands for the distance of the plane from origin, where the other is the distance of the point from the plane?


Ax + By + Cz + D = 0 

I think that this form is more used because it is in sync with the rest of the math. Additionally it is much easier to memorize formulas if there aren't many different version of the sign.

And of course depending on your logic behind it it is a bit more intuitive (or vice versa)

Randy is saying that we can make D be positive by doing essentially this...

Ax + By + Cz = d

Substitute -d with D

Ax + By + Cz - d = 0

Ax + By + Cz + D = 0

Ax + By + Cz + -(Ax + By + Cz) = 0

It doesn't change the result, it just adds a few parenthesis or sign changes through-out.

In some cases this might make it easier to do some math, or to remember it, or some other reason. The result stays the same, though.

EDIT: Typo.

Hello to all my stalkers.

I think about planes as being defined by a normal n and a point on the plane p. Then we can define the plane as (read * as dot-product):

P: n * x - n * p = n * ( x - p ) = 0

We can now define d = n * p and get:

P: n * x - d = 0

I thinks this is the more formal definition that you would find it in a textbook. If you use 4D vectors for planes and want to define the distance of a point to a plane using the dot product you would define d = -n * p which yields:

P : n * x + d = 0

I think the 4D vector definition also works well with transformations where you simply multiply the 4D 'plane' vector with a 4x4 transformation matrix (not sure though). Personally I prefer the more formal definition and use explicit plane functions to evaluate the distance to planes or transform them. If you want to wrap everything into a generic 4D vector the later might be the better choice.

HTH,

-Dirk

A plane (a,b,c,d) is really a four-dimensional trivector, not an ordinary vector. When you take the wedge product of three points P, Q, and R, it naturally produces a plane in which d = -dot(N, P) = -dot(N, Q) = -dot(N, R), where N = (a,b,c). When you take the dot product between a homogeneous point (x,y,z,w) and a plane (a,b,c,d), you get a*x + b*y + c*z + d*w, which gives you the signed distance between the point and the plane multiplied by w and the magnitude of N. A positive sign in front of the d is the correct choice.

This kind of stuff is discussed very thoroughly in my new book that comes out in August:

http://foundationsofgameenginedev.com/

Dirk, when a homogeneous point is treated as a single-column matrix that is transformed by multiplying on the left by a 4x4 matrix M, a 4D plane must be treated as a single-row matrix that is transformed by multiplying on the right by the adjugate of the matrix M. If the translation portion of the matrix M is not zero, then a plane will not be transformed correctly if you treat it the same as a point.

Hi guys, quick question on the plane equation and finding if a point is on a plane or not.

For the second part of the question, I have always used the method described by Dirk Gregorius. I find it more direct and simple to use. So just adding a bit of value here ...

Definitions p0 is a point we are sure is on the plane

Ib, p1, p2 are points that may or may not be on the plane

n is the normal of the plane

To see if a point is on the plane, first use a generic point P, to represent any arbitrary point. Then we later substitute P with Ib, p1, p2

( p0 - P ) Dot n = v If v = 0, then point lie on the plane, otherwise not

( p0 - p1 ) Dot n = 0 p1 is on the plane

( p0 - p2 ) Dot n = 0 p2 is on the plane

( p0 - Ib ) Dot n ? 0 Ib is not on the plane

300px-Line_plane.svg.png

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

lol


By this definition, the equation of a plane should be
Ax + By + Cz = D
 
Meaning a point is on the plane if it satisfies:
Ax + By + Cz - D = 0

This topic is closed to new replies.

Advertisement