I am trying to get the angle between three points on a plane using this formula:
cos-1((P122 + P132 - P232)/(2 * P12 * P13))
but occasionally I am getting a math domain exception. here is the function:
P12 = math.sqrt((x1-x2)**2 + (y1-y2)**2)
P13 = math.sqrt((x1-x3)**2 + (y1-y3)**2)
P23 = math.sqrt((x2-x3)**2 + (y2-y3)**2)
if P12 ==0 or P23 ==0 or P13 ==0 :
return 0
return math.acos((P12**2 + P13**2 - P23**2) / (2*P12*P13) )
where P1 is the vertex what could be going wrong here?
Thanks