Geometry 2: Length of Line Segment in 3D

Published by Mateusz Mędrowski in

Write a function that takes coordinates of two points on a three-dimensional plane and returns the length of the line segment connecting those two points.

Examples

lineLength(arr[0]={15, 7, 5}, arr[1]={22, 11, 1}) ➞ 8.06

lineLength(arr[0]={0, 0, 0}, arr[1]={0, 0, 0}) ➞ 0

lineLength(arr[0]={0, 0, 0}, arr[1]={1, 1, 1}) ➞ 1.41

Notes

  • Numbers in argument array can be positive or negative.
  • The order of the given numbers is X, Y, Z.
  • There is 0.1 tolerance, so you don't need to round your result.
  • This challenge is easier than it looks.

Check my profile for other challenges in the series.

Watch a quick demo on how Edabit works.