Graphics Reference
In-Depth Information
P denom
=
d 1 (( n 2
·
n 2 ) n 1
( n 1
·
n 2 ) n 2 )
+
d 2 (( n 1
·
n 1 ) n 2
( n 1
(gathering similar terms)
·
n 2 ) n 1 )
P denom
=
d 1 ( n 2 ×
( n 1 ×
n 2 ))
+
d 2 ( n 1 ×
( n 2 ×
n 1 ))
(rewriting using vector identity)
P denom
=
d 1 ( n 2 ×
( n 1 ×
n 2 ))
d 2 ( n 1 ×
(changing sign to make inner cross products equal)
( n 1 ×
n 2 ))
P denom
=
( d 1 n 2
d 2 n 1 )
×
( n 1 ×
n 2 )
(gathering similar terms)
P
=
( d 1 n 2
d 2 n 1 )
×
d / denom
(substituting d for n 1
×
n 2 ; dividing by denom on both sides)
The final terms in the expression of the line L
=
P
+
t d are therefore
d ( d
P
=
( d 1 n 2
d 2 n 1 )
×
·
d )
d
=
n 1 ×
n 2 .
The implementation now becomes:
// Given planes p1 and p2, compute line L = p+t*d of their intersection.
// Return 0 if no such line exists
int IntersectPlanes(Plane p1, Plane p2, Point &p, Vector &d)
{
// Compute direction of intersection line
d = Cross(p1.n, p2.n);
// If d is (near) zero, the planes are parallel (and separated)
// or coincident, so they're not considered intersecting
float denom = Dot(d, d);
if (denom < EPSILON) return 0;
// Compute point on intersection line
p = Cross(p1.d*p2.n - p2.d*p1.n, d) / denom;
return 1;
}
It should be noted that when it is known that the plane normals have been nor-
malized (that is,
=
=
n 1
n 2
1), the division by the denominator is not required
in either formulation.
 
Search WWH ::




Custom Search