Suppose we are at point A, with position vector a, how do we calculate the distance to the nearest point of a nearby plane passing through point B and with a unit normal vector n.
We know the vector from B to A = b - a, and with a little thought that the required distance is the component of b - a in the direction of the unit normal to the plane:
This distance is just the projection of a - b on to the unit normal vector n
d = n . ( a - b )
Relating maths to real life again (see the equation of the line), our starship is on a linear course, r1(t), between points A and B,
r1(t) = a + t (b - a) where t is any real number
A second starship is on course, r2(t), between C and D,
r2(s) = c + s (d - c) where s is any real number
Regulations state that the path of any 2 starships at warp (as we both happen to be) cannot come closer than 1000km of each other (note this refers to the courses and not just the ships). To check we're obeying regulations, we will find the shortest distance, d, that r1(t) and r2(s) ever come to each other.
Firstly, note we are going to assume the two lines are not parallel and non intersecting, then imagine the line our ship is following. There exist an infinite number of planes that contain the line, though only one of them does not intersect the line that the other ship is travelling along. I found this easier to see by constructing the plane as follows:
b - a lies in the plane, and
c - d is parallel to the plane also, so using the cross product,
n = (b - a) x (c - d)
is a normal vector to the plane, and the plane passes through a hence any point R in the plane satisfies
(r - a) . n = 0
The distance, d, we want to find is that between this plane and the plane parallel to this one that contains C and D (ie. the other ship's course)
We can calculate d by taking any vector that joins the 2 planes and projecting it onto the unit normal vector. The vector from A to D ( = d - a ) is one of them so we've all but done it:
d = | (d - a) . (n/ n)) |
where n = (b - a) x (c - d)
and n = |n| = the magnitude of n