Skip to content

Instantly share code, notes, and snippets.

@kreeger
Last active August 29, 2015 14:25
Show Gist options
  • Save kreeger/f41442ef1365f78107da to your computer and use it in GitHub Desktop.
Save kreeger/f41442ef1365f78107da to your computer and use it in GitHub Desktop.
Distance between two points.
points = [
{ name: "POINT A", coords: [46.71875, -87.6875, -68.8125] },
{ name: "POINT B", coords: [51.78125,-94.625,-53.21875] }
]
# (17.8ly)
x_comp = (points[1][:coords][0] - points[0][:coords][0]) ** 2
y_comp = (points[1][:coords][1] - points[0][:coords][1]) ** 2
z_comp = (points[1][:coords][2] - points[0][:coords][2]) ** 2
combined = x_comp + y_comp + z_comp
sqrd = Math.sqrt(combined)
puts sqrd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment