4x4 Matrix Transformation of the Implicit Form of the Plane
Kenneth E. Hoff III
7/13/98
Given a plane as a 4-vector [ A B C D ] whose components are the coefficients of the implicit form of the plane Ax+By+Cz+D where (A,B,C) is the normal to the plane (possibly not normalized) and D is the negative distance from the origin to the plane along the normal (in units of the normal's length if not normalized), and a 4x4 transformation matrix M, we wish to transform the plane. I describe two different methods.
The simplest method would be to convert the implicit form of the plane to the point-normal form. We already have the normal as (A,B,C) and we can obtain a point on the plane as follows:
PtOnPlane = -D*(A,B,C)
This is simple since -D is the negative distance from the origin to the plane along the normal (in units of the normal, if not normalized).
So now we have the point-normal form as 1 point on the plane and 1 vector that is the plane's normal. We can perform two transformations as follows:
NewNormal N' = M * NormalNewPtOnPlane P' = M * PtOnPlane
Through substitution and expansion we get:
[ N'x ] = M * [ A ]
[ N'y ] [ B ][ N'z ] [ C ][ 0 ] [ 0 ]
[ P'x ] = M * [ -AD ]
[ P'y ] [ -BD ][ P'z ] [ -CD ][ 1 ] [ 1 ]
We can get the implicit form [ A' B' C' D' ] for the xformed plane as follows:
We should be able to remove the conversion step by expanding the terms:
[ A' ] [ M00*A + M01*B + M02*C ][ B' ] = [ M10*A + M11*B + M12*C ]
[ C' ] [ M20*A + M21*B + M22*C ][ D' ] = -( (M00*-AD + M01*-BD + M02*-CD + M03) * (M00*A + M01*B + M02*C) +
(M10*-AD + M11*-BD + M12*-CD + M13) * (M10*A + M11*B + M12*C) +
(M20*-AD + M21*-BD + M22*-CD + M23) * (M20*A + M21*B + M22*C) ) = -( (-D * (M00*A + M01*B + M02*C) + M03) * A' + (-D * (M10*A + M11*B + M12*C) + M13) * B' + (-D * (M20*A + M21*B + M22*C) + M23) * C' ) = -( (-DA' + M03) * A' + (-DB' + M13) * B' + (-DC' + M23) * C' )
This gives an efficient and compact form for the planar xform without renormalization of the normal. We could then normalize as follows:
L = sqrt(A'2+B'2+C'2)
[ A B C D ] = [ A/L B/L C/L D/L ]
We could incorporate the normalization into the calculation more efficiently by reordering the operations of D' to compute (A'2+B'2+C'2):
D' = -(-DA' + M03) * A' + (-DB' + M13) * B' + (-DC' + M23) * C'
= -(-DA'2 + A'M03 + -DB'2 + B'M13 + -DC'2 + C'M23) = -(-D*(A'2 + B'2 + C'2) + (A'M03 + B'M13 + C'M23)) = D*(A'2 + B'2 + C'2) - (A'M03 + B'M13 + C'M23)
So now we can compute an intermediate value L2 (length squared) before computing D' and normalization:
L2 = A'2 + B'2 + C'2
L = sqrt(L2)
D' = D*L2 - (A'M03 + B'M13 + C'M23)
[ A’ B’ C’ D’ ] = [ A'/L B'/L C'/L D'/L ]
<OR MORE EFFICIENTLY>
L2 = A'2 + B'2 + C'2
L = sqrt(L2)
[ A’ B’ C’ ] = [ A'/L B'/L C'/L ]
D’ = D*L - (A*M03 + B*M13 + C*M23)
since
D’ = D'/L = [D*L2 - (A'M03 + B'M13 + C'M23)]/L = D*L2/L - (A'/L)M03 + (B'/L)M13 + (C'/L)M23 = D*L - (A*M03 + B*M13 + C*M23)
Note that this assumes that the 4x4 matrix does not include a projection, a shear, or a nonuniform scaling. We need a more general method in this case.
The implicit form of the plane Ax + By + Cz + D = 0 can be written in matrix notation as:
[ A B C D ] * [ x ]
[ y ] = 0 [ z ] [ 1 ]The set of points (x,y,z) that satisfy this equation lie on the plane. We are given a general, non-singular 4x4 matrix M that will be used to transform all points on the plane. We wish to find a tranformation matrix Q that can be applied to the plane coefficients vector [ A B C D ] such that the resulting transformed plane equation will be satisfied by the set of points on the original plane transformed by M.
Find 4x4 matrix Q to transform plane as follows:
Q * [ A ] [ A’ ]
[ B ] = [ B’ ][ C ] [ C’ ]
[ D ] [ D’ ]
such that if all points on the original plane are transformed by M, they will lie on the plane transformed by Q:
[ A’ B’ C’ D’ ] * ( M * [ x ] )
( [ y ] ) = 0
( [ z ] )
( [ 1 ] )
Substitute and solve for Q:
( Q * [ A ] )^T * ( M * [ x ] )
( [ B ] ) ( [ y ] ) = 0
( [ C ] ) ( [ z ] )
( [ D ] ) ( [ 1 ] )
[ A B C D ] * Q^T * ( M * [ x ] )
( [ y ] ) = 0
( [ z ] )
( [ 1 ] )
[ A B C D ] * (Q^T * M) * [ x ]
[ y ] = 0
[ z ]
[ 1 ]
Q^T * M = Identity Matrix I
Q^T * M = I
Q^T * M * M^-1 = M^-1
Q^T = M^-1
Q = (M^-1)^T
So, in order to transform the plane represented by coefficient vector [ A B C D ] by matrix M, we must transform the coefficient vector by the transpose of the inverse of M (matrix Q):
(M^-1)^T * [ A ] [ A’ ]
[ B ] = [ B’ ]
[ C ] [ C’ ]
[ D ] [ D’ ]
Incidentally, this is also the formulation needed to properly transform normal vectors (planes are often represented by their normal vector and a point on the plane). See the OpenGL redbook appendix for additional details.