I have set in autocad the correct angle settings, have been applying 20 different functions to obtain the correct angle (Y axis) between two coordinates, but I keep getting strange angles back from this routine. Either the correct angle is difference with 90, or 450. Any idea why? I have gone through most of math forums on the internet. I need the angle correctly in order to scale a polygon.
thanks.
Public Function GiveAngle(DegRad As Boolean, x1 As Double, y1 As Double, x2 As Double, y2 As Double) As Double
Dim Xdist, Ydist As Double
Dim ATAN3 As Double
Dim PI As Double
PI = 3.14159265358979
Xdist = (x2 - x1)
Ydist = (y2 - y1)
If Abs(Ydist) > Abs(Xdist) Then
If Ydist > 0 Then
ATAN3 = Math.Atn((x2 - x1) / (y1 - y2))
Else
ATAN3 = Math.Atn((x2 - x1) / (y1 - y2)) + PI
End If
Else
If Xdist > 0 Then
ATAN3 = 0.5 * PI - Atn((x2 - x1) / (y1 - y2))
Else
ATAN3 = -0.5 * PI - Atn((x2 - x1) / (y1 - y2))
End If
End If
GiveAngle = ATAN3 * 180 / PI
End Function