Skip to content

Instantly share code, notes, and snippets.

@fospathi
Last active April 17, 2018 15:47
Show Gist options
  • Save fospathi/27facb61439d3f5f144dc992066f1bdc to your computer and use it in GitHub Desktop.
Save fospathi/27facb61439d3f5f144dc992066f1bdc to your computer and use it in GitHub Desktop.
Closest approach of two lines
Let L₀ = P₀ + αD₀ and L₁ = P₁ + βD₁ be two lines. Let P = P₁ - P₀ and
L = L₁ - L₀
= P - αD₀ + βD₁
Then
L² = L⋅L
= (P - αD₀ + βD₁)⋅(P - αD₀ + βD₁)
= P² + (αD₀)² + (βD₁)² - 2α(P⋅D₀) + 2β(P⋅D₁) - 2αβ(D₀⋅D₁)
thus
d(L²)
----- = 2α(D₀)² - 2(P⋅D₀) - 2β(D₀⋅D₁)
d(L²)
----- = 2β(D₁)² + 2(P⋅D₁) - 2α(D₀⋅D₁)
Let 0 = d(L²) = d(L²) and so minimise L² giving two simultaneous equations with two unknowns: α and β
----- -----
dα dβ
0 = α(D₀)² + β[-(D₀⋅D₁)] - (P⋅D₀)
0 = α[-(D₀⋅D₁)] + β(D₁)² + (P⋅D₁)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment