# three plane intersection point

This topic is 5003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello. I have some trouble calculating the intersection point between three planes. I found this implementation here: http://www.flipcode.com/cgi-bin/fcmsg.cgi?thread_show=24657
// ^ = dot product
// % = cross product
// b(i) are bases (points in planes), n(i) are plane unit normals.
bool planeInt(Vec3 & ip,Vec3 & b1,Vec3 & n1,Vec3 & b2,Vec3 & n2,Vec3 & b3,Vec3 & n3)
{
flt det = Mat3(n1,n2,n3).det(); // Construct matrix, get determinant.
if (det == 0.f) return false; // Should use a close to zero tolerance check.
Vec3 a = (b1 ^ n1)*(n2 % n3);
Vec3 b = (b2 ^ n2)*(n3 % n1);
Vec3 c = (b3 ^ n3)*(n1 % n2);
ip = (a+b+c)/det;
return true;
} // planeInt


But i cannot get it to work. The determinant is always zero, you can see the two way's iv tried to figure out how he counstructs his matrix, one is commented out. My source is the following which uses d3d for vector and matrix lib:
bool three_plane_intersection_point(const plane_t* plane1, const plane_t* plane2, const plane_t* plane3, D3DXVECTOR3* intersection_point)
{
D3DXVECTOR3 normal1 = plane1->m_normal;
D3DXVECTOR3 normal2 = plane2->m_normal;
D3DXVECTOR3 normal3 = plane3->m_normal;
D3DXVECTOR3 point1 = plane1->get_point_on_plane();
D3DXVECTOR3 point2 = plane2->get_point_on_plane();
D3DXVECTOR3 point3 = plane3->get_point_on_plane();

// Construct matrix
/*
D3DXMATRIX matrix(	normal1.x, normal2.x, normal3.x, 0,
normal1.y, normal2.y, normal3.y, 0,
normal1.z, normal2.z, normal3.z, 0,
0, 0, 0, 0);
*/
D3DXMATRIX matrix(	normal1.x, normal1.y, normal1.z, 0,
normal2.x, normal2.y, normal2.z, 0,
normal3.x, normal3.y, normal3.z, 0,
0, 0, 0, 0);
// Get determinant.
float determinant = D3DXMatrixDeterminant(&matrix);

// Use a close to zero tolerance check.
if(float_compare(determinant, 0.0f))
return false;

D3DXVECTOR3 cross1;
D3DXVec3Cross(&cross1, &normal2, &normal3);
D3DXVECTOR3 cross2;
D3DXVec3Cross(&cross2, &normal3, &normal1);
D3DXVECTOR3 cross3;
D3DXVec3Cross(&cross3, &normal1, &normal2);

D3DXVECTOR3 a = D3DXVec3Dot(&point1, &normal1)*cross1;
D3DXVECTOR3 b = D3DXVec3Dot(&point2, &normal2)*cross2;
D3DXVECTOR3 c = D3DXVec3Dot(&point3, &normal3)*cross3;

(*intersection_point) = (a+b+c) / determinant;

return true;
}


Does anyone know what im doing wrong in constructing the matrix? :-/ Or even better, can anyone confirm that this intersection test works? Thanks in advance! EDIT: I use the top, far, and left plane of my view frustum for testing, so i know they intersect. (they work fine for occlusion culling etc). Ultimatly i want to use this to draw the frustum cone in 3d.

##### Share on other sites
You can get the point in a less computationally intensive way (but the code you have would reduce to that, anyway).

The trick is that you know that the point fulfills all the plane equations at the same time. You'll remember that the plane equations can be formulated as Ax+By+Cz+D == 0. You have three plane equations (different values of A,B,C and D) and want to solve for the three unknowns x,y and z. Plugging this into an equation system and doing simple (hard-coded) Gauss elimination will pop out the solution.

I e: formulate z in terms of x and y.
Substitute for z, into the next equation, formulate y in terms of x.
Substitute for y, into the next equation, and solve the equation. It'll be an algebraic expression in all the plane coefficients.

Now, you actually have the solution as a formula. Plug the numbers in, and out comes your x. Plug that into the substituted equation 2, and out comes your y. Plug that into your first equation, and out comes your z.

##### Share on other sites
I don't see why it uses cross products and all that... I'd take hplus's approach though I'd use a matrix to solve the equations instead of a Gauss elimination.

(A1)x + (B1)y + (C1)z = -(D1)
(A2)x + (B2)y + (C2)z = -(D2)
(A3)x + (B3)y + (C3)z = -(D3)

therefore
( A1, B1, C1 }   ( x )   ( -D1 ){ A2, B2, C2 } * ( y ) = ( -D2 )( A3, B3, C3 )   ( z )   ( -D3 )Let the matrix [M] be( A1, B1, C1 }{ A2, B2, C2 }( A3, B3, C3 )so[M] * (x, y, z) = (-D1, -D2, -D3)so(x, y, z) = inverse([M]) * (-D1, -D2, -D3).

If the planes don't collide to make a single point, the determinant of [M] will be zero so it can't be inverted.

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633270
• Total Posts
3011155
• ### Who's Online (See full list)

There are no registered users currently online

×