
Let L1 and L2 = Non-parallel lines in 3D space.
Let V1 = Vector representing the direction of L1.
Let V2 = Vector representing the direction of L2.
Let P1 = Point on L1 closest to L2.
Let P2 = Point on L2 closest to L1.
Let W = Vector formed by subtracting P1 from P2.
W = (P1x-P2x, P1y-P2y, P1z-P2z)
Given:
1) P1 and P2 form a line perpindicular to both lines L1 and L2.
W.V1 = 0
W.V2 = 0
2) Length of the line formed by P1 and P2 is the shortest distance
between L1 and L2.
3) Points on a line follow: P = s*(Vx, Vy, Vz)+D
Solution:
(P1x-P2x)*V1x + (P1y-P2y)*V1y + (P1z-P2z)*V1z = 0
(P1x-P2x)*V2x + (P1y-P2y)*V2y + (P1z-P2z)*V2z = 0
V1.(s1*V1 - s2*V2 + D1 - D2) = 0
V2.(s1*V1 - s2*V2 + D1 - D2) = 0
We know V1, D1, V2, and D2. Solve the system of equations for s1 and s2
to get P1 and P2.


Let S = A plane.
Let N = A vector normal to S.
Let V = A point on S.
Let L = Line not on S1.
Let P = Point of intersection.
Equation of a plane: N.(x, y, z) = N.V
(Nx*x) + (Ny*y) + (Nz*z) = (Nx*Vx + Ny*Vy + Nz*Vz)
Equation of a line: (x, y, z) = s*M + B = s*(Mx, My, Mz) + (Bx, By, Bz)
Solution:
N.(s*M + B) = N.V
We know N, M, B, and V. Solve for s to get P.


