Graphics Reference
In-Depth Information
and
m
3
=
n
1
n
3
T
, Cramer's rule gives the solution as
n
2
x
1
=
dm
2
m
3
m
1
m
2
m
3
x
2
=
m
1
dm
3
m
1
m
2
m
3
x
3
=
m
1
m
2
d
m
1
m
2
m
3
,
=
d
1
d
2
d
3
T
.
By selecting the most appropriate expressions for evaluation — in order to share
as much computation as possible — the scalar triple products simplify to
where
d
x
1
=
d
·
u
/
denom
x
2
=
m
3
·
v
/
denom
x
3
=−
m
2
·
v
/
denom
,
where
u
u
.
The following code implements this solution for three planes.
=
m
2
×
m
3
,
v
=
m
1
×
d
, and
denom
=
m
1
·
// 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 m1 = Vector(p1.n.x, p2.n.x, p3.n.x);
Vector m2 = Vector(p1.n.y, p2.n.y, p3.n.y);
Vector m3 = Vector(p1.n.z, p2.n.z, p3.n.z);
Vector u = Cross(m2, m3);
float denom = Dot(m1, u);
if (Abs(denom) < EPSILON) return 0;
// Planes do not intersect in a point
Vector d(p1.d, p2.d, p3.d);
Vector v = Cross(m1, d);
float ood = 1.0f / denom;
p.x = Dot(d, u) * ood;
p.y = Dot(m3, v) * ood;
p.z = -Dot(m2, v) * ood;
return 1;
}
An alternative approach is to solve for
X
using the formula
×
+
×
+
×
d
1
(
n
2
n
3
)
d
2
(
n
3
n
1
)
d
3
(
n
1
n
2
)
=
X
,
·
×
n
1
(
n
2
n
3
)