1
$\begingroup$

How do I classify a point with respect to a plane, returning whether the point is inside, outside, or coplanar?

I know that if a point is on the plane the Dot product + the plane distance would equal to 0, but what does inside, outside, and coplanar mean. Also how it is computed.

$\endgroup$
2
  • $\begingroup$ As you imply, a plane can be represented by its normal, N, and a scalar, d. A point X is on the plane if N.X+d = 0. As for inside and outside typically you define a rule, e.g., that the normal points "out" from the plane which just means that if N.X+d > 0, then X is outside the plane, while N.X+d<0, implies it's inside. $\endgroup$
    – Simon F
    Jan 31, 2017 at 9:40
  • $\begingroup$ Clearly my brain is not in gear this morning. Will delete. $\endgroup$
    – Simon F
    Jan 31, 2017 at 10:24

1 Answer 1

2
$\begingroup$
Vec3 v = myPoint - pointOnPlane;
float vDotPlaneNormal = dot(v, planeNormal)
if (vDotPlaneNormal == 0) 
    printf("point on plane");
else if (vDotPlaneNormal > 0)
    printf("point above somehow...");
else
    printf("point under sadly...");

If you wonder what is pointOnPlane. In fact it can be any point that lies on the plane. Imagine this as a sheet of paper; draw two lines on this sheet to define the center of the piece of paper, imagine that this point is aligned with the world coordinate system origin and that sheet is in xz plane of that coordinate system (in which y defines the up vector). So the paper is horizontal in a way. Now move the sheet around. The pointOnPlane can be the coordinates of the point you drew in the center of the sheet of paper with respect to the world origin.

All you have to do is rotate that sheet of paper. That rotation is given to you by the plane's normal.

The rest is basic trig. If the point P is one the plane, the dot product between the vector defined by (P - PointOnPlane) and the plane's normal will be equal to 0. The dot product tells you whether two vectors are orthogonal, on the same side of the plane or point in opposite directions.

FASTER SOLUTION - EDIT

As mentioned by SimonF in a comment, you don't really need the pointOnPlane parameter and save the subtraction between this point and the tested point:

As you imply, a plane can be represented by its normal, $N$, and a scalar, $d$.

A point X is on the plane if $N \cdot X+d = 0$. As for inside and outside typically you define a rule, e.g., that the normal points "out" from the plane which just means that if $N \cdot X + d > 0$, then $X$ is above the plane, while $N \cdot X + d < 0$, implies it's below.

You can test/use both techniques.

$\endgroup$
6
  • $\begingroup$ If you represent your plane by the Normal and a scalar you can avoid the unnecessary expensive of the vector subtract. $\endgroup$
    – Simon F
    Jan 31, 2017 at 11:10
  • $\begingroup$ @SimonF. Sure ... feel free to edit my answer and add that as a quicker solution... I just made an answer). $\endgroup$
    – user18490
    Jan 31, 2017 at 11:29
  • $\begingroup$ Given the number of typos I'm making today ( "expensive of the", good grief!), I don't think I dare. :-) $\endgroup$
    – Simon F
    Jan 31, 2017 at 13:52
  • 1
    $\begingroup$ @SimonF - I'll do it for you... $\endgroup$
    – user18490
    Jan 31, 2017 at 19:59
  • 1
    $\begingroup$ One thing we should point out that is, if using floating point, it is unlikely, in general, that you will ever get (vDotPlaneNormal == 0.0). You may need to add a "within epsilon" test $\endgroup$
    – Simon F
    Feb 2, 2017 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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