Inside-Outside Point Test using the Dot Product

The purpose of this paper is to derive a "tool" used for determining if a point is on the "inside" or "outside" of a line or plane based on the definition of the dot product.

written and derived by Kenny Hoff (Oct. 3, 1995)
based on the definition of the dot product


Given the Point-Normal form of a line or a plane in which the direction of the normal "points" to the "inside" half-space, we would like to be able to determine is a point P is in this "inside" half-space, on the line or plane, or in the "outside" half-space. How can we do this? Since we are using the Point-Normal form for the line or plane, we have the normal readily available to develop an angular relationship between the normal and the point P. If we subtend a vector from any point on the line or plane to the point P, we will obtain a vector that points in the direction of P from the line or plane. Let's call this vector V:

	vector V = P - (Point on line or plane)

The angle between V and the normal can be used to determine the position of the point P in relation to the line or plane. If the angle is less than 90 degrees, P is on the same side the normal is facing ("inside" half-space); if the angle is greater than 90 degrees, P is on the oppositive side the normal is facing ("outside" half-space); and if the angle equals 90 degrees, the point P is on the line or plane. So now that we have this vector V, the normal to the line or plane, and an angular relationship between these two vectors that determines the point's location, how can we determine the angle? By using the dot product of these two vectors.

By definition, the dot product between V and N is defined as follows:

	V.N = |V|*|N|*cos(angle)

The dot product is the magnitude of V times the magnitude of N times the cos of the angle between the two vectors. What does this mean? Since |V| and |N| are absolute magnitudes, they are always positive; therefore, the sign of |V|*|N|*cos(angle) is influenced only by the sign of cos(angle). Remembering from trigonometry:

	-1 <= cos(angle) <= 1

So from the unit circle, the cos represent the x-coordinate of point on the circle subtending angles from the origin from 0 to PI radians. This means that is cos(angle)=0 the angle must be PI/2 radians or 90 degrees.

	if cos(angle)=0, 
		V.N = |V|*|N|*0 = 0
		angle = 90 degrees

	Therefore we have rule #1,

	(1) if V.N = 0, then angle = 90 degrees

If cos(angle) is less than 0 (negative), PI/2 < angle <= PI or the angle is greater than 90 degrees, but less than or equal to 180.

	if cos(angle)<0, 
		V.N = |V|*|N|*NEGATIVE < 0
		90 degrees < angle <= 180 degrees

	(2) if V.N < 0, then angle is greater than 90 degrees

If cos(angle) is greater than 0 (positive), 0 <= angle < PI/2 or the angle is greater than or equal to 0 degrees and less than 90.

	if cos(angle)>0,
		V.N = |V|*|N|*POSITIVE
		0 <= angle < 90

	(3) if V.N > 0, then angle is less than 90 degrees

What can we conclude from this? Well earlier we had stated that an angle of 90 degrees between the normal N and vector V meant that the point P was on the line or plane, an angle > 90 degrees meant that P was in the "outside" half-space, and an angle < 90 degrees meant that P was in the "inside" half-space. So in conclusion, we can derive the following rules:

	if V.N = 0, P is on the line or plane
	if V.N < 0, P is in the "outside" half-space (opposite of the normal direction)
	if V.N > 0, P is in the "inside" half-space (side of normal direction)

These rules almost seem useless with our given definition of the dot product; however the true "power" of this technique is made apparent when we utilize an alternate definition:

	2D case: V.N = (Vx*Nx) + (Vy*Ny)
	3D case: V.N = (Vx*Nx) + (Vy*Ny) + (Vz*Nz)