I need a function to treat each point as the origin, starting from the one closest to (0,0), then compute the angle and length of each line segment from that point to every other point. It should skip over anything that would create a same line segment already computed before
However, my function is not taking into account the line segment from my first point to second point. Please help... here is the function
import math
def compute_vectors(points):
vectors = []
previous = points[0]
for point in points:
x = point[0] - previous[0]
y = point[1] - previous[1]
angle = math.degrees(math.atan2(y, x))
if angle < 0:
angle += 360
length = math.sqrt(x**2 + y**2)
vectors.append((angle, length))
previous = point
return vectors[1:]
points = [[1,1],[2,2],[3,1]]
compute_vectors(points)
>>> [(45.0, 1.4142135623730951), (315.0, 1.4142135623730951)]
I need it to output
>>> [(45.0, 1.4142135623730951),(0.0, 2),(315.0, 1.4142135623730951)]