Calc Intersection of 2 and 3 planes

Started by
5 comments, last by scorpiomidget 21 years, 6 months ago
Hi, I'm looking for some code, so i can calculate the line that 2 planes interesect at and also a point if 3 planes intersect. Can anyone help me ? Please [edited by - scorpiomidget on October 16, 2002 8:08:41 AM]
Scorpio
Advertisement
Equation of a plane:

Ax + By + Cz + D = 0

You have two planes -> two equations. Since you have to find three unknowns, you can express y as a function of x, and z as a function of x (or use a fourth independant variable "t" and express all three variables x,y,z as a function of t).

You should learn about matrices, if you don''t know about them already.

If you have three planes, there is only one possible solution.

Cédric
Cédric said:
>If you have three planes, there is only one possible solution.

No there isn''t. Three planes can intersect in a point, in
a line, in two lines, in three lines, or not intersect at
all.

You might perhaps only care about the case where they
intersect in a point, but the other cases are still
possible.

Christer Ericson
Sony Computer Entertainment, Santa Monica

  // If this method fails it means the 3 planes have normals which all lie in the same plane. In this case, all 3// planes (a, b, c) intersect at 3 lines which can be retrieved by calling GetIntersectionLineOfPlanes for// the plane pairs (ab), (ac), and (bc).bool cPlane::GetIntersectionPointOfPlanes(const cPlane& a, const cPlane& b, const cPlane& c, cVector3& Q){	float	det;	// Need to find a point Q that lies on all three planes. Let the three planes be:	//	// L1 = <N1, D1>	// L2 = <N2, D2>	// L3 = <N3, D3>	//	// Find the point Q is a simple case of solving the following linear system:	//	// L1.Q = 0	// L2.Q = 0	// L3.Q = 0	//	// This can be written in matrix form:	//	//      [-D1]	// MQ = [-D2]	//      [-D3]	//	// where the matrix M is:	cMatrix3x3 M;	M.e[0][0] = a.n.x;	M.e[0][1] = a.n.y;	M.e[0][2] = a.n.z;	M.e[1][0] = a.n.x;	M.e[1][1] = a.n.y;	M.e[1][2] = a.n.z;	M.e[2][0] = a.n.x;	M.e[2][1] = a.n.y;	M.e[2][2] = a.n.z;	// Q is now solvable using the following:	//	//          [-D1]	// Q = M(-1)[-D2]	//          [-D3]	//	// If M is singular the three planes intersect with an edge, not a point	if (cMaths::FCmpZ(det = M.Determinant()))		return (false);	// Calculate the inverse using the already calculated determinant	M = cMatrix3x3::Inverse(M, det);	// Transform the distance vector by the inverse to get the intersection point	Q.x = M.e[0][0] * -a.d + M.e[0][1] * -b.d + M.e[0][2] * -c.d;	Q.y = M.e[1][0] * -a.d + M.e[1][1] * -b.d + M.e[1][2] * -c.d;	Q.z = M.e[2][0] * -a.d + M.e[2][1] * -b.d + M.e[2][2] * -c.d;	return (true);}bool cPlane::GetIntersectionLineOfPlanes(const cPlane& a, const cPlane& b, cVector3& Q, cVector3& V){	// The line by which two planes intersect has a direction that is perpendicular to	// the normals of the two planes:	cVector3 N1(a.n.x, a.n.y, a.n.z), N2(b.n.x, b.n.y, b.n.z);	V = cVector3::Cross(N1, N2);	// Providing a point on the line can be accomplished by constructing a third plane which	// passes through the origin (D=0) and whose normal direction is that of the line (V):	cPlane c(V, 0);	// ...and calculating the intersection point of these three planes:	return (GetIntersectionPointOfPlanes(a, b, c, Q));}  
oops, doc error, change:

"intersect at 3 lines"

to:

"possibly intersect at on a maximum of 3 lines"
quote:Original post by Anonymous Poster
Cédric said:
>If you have three planes, there is only one possible solution.

No there isn''t. Three planes can intersect in a point, in
a line, in two lines, in three lines, or not intersect at
all.

Of course... I''m getting lazy with my explanations.

But since I''m feeling picky today, I might as well add that three planes cannot intersect in two or three lines, because the intersection of two planes is already a line, a plane, or nothing. Hence the intersection with the third plane can only be a plane, a line, a point, or nothing.

You can only get three lines if you consider the planes two by two, which is not the intersection of the three planes that the OP is looking for.

Cédric
Many many thanks for all the help you''ve given
Scorpio

This topic is closed to new replies.

Advertisement