|
|
Given two planes n1 * X = d1 and n2 * X = d2 we want to find the minimum distance between the two. If the planes are not parallel to each other, they intersect and the distance is 0. Whether the planes are parallel can be determined either by using the cross product or the dot product between the two normals. The two planes are parallel, if n1 x n2 = 0 or abs(n1 * n2) = 1. If the planes intersect, the intersection is a line. The equation of the line can be written as: X = c1 * n1 + c2 * n2 + t * (n1 x n2) Using that in the plane equations yields c1 * n1 * n1 + c2 * n1 * n2 = d1 c1 * n1 * n2 + c2 * n2 * n2 = d2 Solving for c1 and c2 c1 = (d1 * n2 * n2 - d2 * n1 * n2) / determinant c2 = (d2 * n1 * n1 - d1 * n1 * n2) / determinant with determinant = (n1 * n1) * (n2 * n2) - (n1 * n2)^2 Note that n1 * n1 and n2 * n2 are the squared length of n1 and n2 respectively. Since plane normals are always normalized in XEngine, we can simplify c1, c2 and the determinant to c1 = (d1 - d2 * n1 * n2) / determinant c2 = (d2 - d1 * n1 * n2) / determinant determinant = 1 - (n1 * n2)^2
|
Copyright © by Martin Ecker |