All problems
Arc Length of a Polyline
Problem
Compute the total length of a polyline through consecutive 2D points.
Sum the Euclidean distance between each pair of adjacent points. A polyline with fewer than two points has length 0.0.
Hint
Use the Pythagorean distance sqrt(dx * dx + dy * dy) for each segment.
Test cases
case 1
in: [[[0,0],[3,4]]]
expected: 5
case 2
in: [[[0,0],[1,0],[1,1],[0,1]]]
expected: 3
case 3
in: [[[0,0]]]
expected: 0
case 4
in: [[[1,1],[4,5],[4,5]]]
expected: 5
Starter codePython
def polyline_length(points):
# points is a list of [x, y] pairs
# Your code here
pass4 test cases · run your code against them in the editor