Graphics Reference
In-Depth Information
as suggested by [Goldman90]. This formula can be obtained by realizing that
X
can
be expressed as a linear combination of the directions of the lines of intersection of
the planes,
X
=
a
(
n
2
×
n
3
)
+
b
(
n
3
×
n
1
)
+
c
(
n
1
×
n
2
),
for some
a
,
b
, and
c
. Inserting this point in each of the three plane equations gives
n
1
·
(
a
(
n
2
×
n
3
)
+
b
(
n
3
×
n
1
)
+
c
(
n
1
×
n
2
))
=
d
1
n
2
·
(
a
(
n
2
×
n
3
)
+
b
(
n
3
×
n
1
)
+
c
(
n
1
×
n
2
))
=
d
2
n
3
·
(
a
(
n
2
×
n
3
)
+
b
(
n
3
×
n
1
)
+
c
(
n
1
×
n
2
))
=
d
3
,
which simplify to
n
1
·
a
(
n
2
×
n
3
)
=
d
1
n
2
·
b
(
n
3
×
n
1
)
=
d
2
n
3
·
c
(
n
1
×
n
2
)
=
d
3
,
from which
a
,
b
, and
c
are easily solved. Inserting the obtained values for
a
,
b
, and
c
gives the original formula. Some simple manipulation allows the formula for
X
to be
further simplified to
d
1
(
n
2
×
n
3
)
+
n
1
×
(
d
3
n
2
−
d
2
n
3
)
X
=
,
n
1
·
(
n
2
×
n
3
)
which in code becomes:
// Compute the point p at which the three planes p1, p2 and p3 intersect (if at all)
int IntersectPlanes(Plane p1, Plane p2, Plane p3, Point &p)
{
Vector u = Cross(p2.n, p3.n);
float denom = Dot(p1.n, u);
if (Abs(denom) < EPSILON) return 0;
// Planes do not intersect in a point