Graphics Reference
In-Depth Information
If
X
is a hyperplane in
R
n
defined by equation
6.6.4
Formula.
ax
+
a x
+
...
+
a x
+
d
=
0
,
11
2 2
nn
then the distance from
X
to the origin is
d
aa
.
2
2 2
+++
...
n
1
2
Proof.
Note that (a
1
,a
2
,...,a
n
) is a normal vector to plane
X
. Therefore, the formula
is basically equation (6.22) written in coordinate form. For an efficient formula that
avoids square roots see [Geor92].
Two special cases of Formula 6.6.4 are worth noting. The distance from the origin
to the line in the plane with equation ax + by + c = 0 is
c
ab
.
(6.24)
2
2
+
The distance from the origin to the plane in
R
3
with equation ax + by + cz + d = 0 is
d
abc
.
(6.25)
2
2 2
++
6.6.5 Formula.
Let
L
1
be the line defined by a point
P
and direction vector
v
. Let
L
2
be the line defined by a point
Q
and direction vector
w
. Assume that the lines are
not parallel. The distance d between
L
1
and
L
2
is given by
(
)
=-+
d
=
dist
LL
,
PQ v w
s
t
,
(6.26)
12
where
=-
(
(
)(
)
+
(
)(
)
)
s
PQ•w w•v
PQ•v w•w
D
,
=
(
(
)(
)
-
(
)(
)
)
t
PQ•v v•w
PQ•w v•v
D and
,
2
=
(
)(
)
-
(
)
D
v•v w•w
v•w
.
Furthermore, the point
A
=
P
+ s
v
on
L
1
is the unique point of
L
1
which is closest to
L
2
. Similarly, the point
B
=
Q
+ t
w
on
L
2
is the unique point of
L
2
which is closest to
L
1
. If the lines intersect, then
A
=
B
and we have formulas for the intersection point.
Proof.
See Figure 6.16. Let
A
=
P
+ s
v
and
B
=
Q
+ t
w
be typical points on
L
1
and
L
2
, respectively. Clearly, d = d(s,t) = dist(
A
,
B
), where the vector
AB
=
PQ
- s
v
+ t
w
is