Nov-20-2018, 06:10 AM
(This post was last modified: Nov-20-2018, 06:10 AM by Gribouillis.)
It is almost correct. The order of the points matters
import math def angle3pt(a, b, c): """Counterclockwise angle in degrees by turning from a to c around b Returns a float between 0.0 and 360.0""" ang = math.degrees( math.atan2(c[1]-b[1], c[0]-b[0]) - math.atan2(a[1]-b[1], a[0]-b[0])) return ang + 360 if ang < 0 else ang print(angle3pt((5, 0), (0, 0), (0, 5)))
Output:90.0
This function will not throw an error if a==b
or c==b
because math.atan2(0,0)
returns 0.0. It would probably be a good idea to add this in the function, something likeif b in (a, c): raise ValueError("Undefined angle, two identical points", (a, b, c))