Attribute VB_Name = "Geometry_Math"

Option Explicit

'Clockwise angle in radians with Y up and X right
Public Function Angle(ByVal X As Double, ByVal Y As Double)
    If X <> 0 Or Y <> 0 Then
        If Abs(X) > Abs(Y) Then
            Y = Y / X
            If X > 0 Then
                Angle = Atn(-Y) + (PI * 0.5)
            Else
                Angle = Atn(-Y) + (PI * 1.5)
            End If
        Else
            X = X / -Y
            If Y < 0 Then
                Angle = Atn(-X) + PI
            Else
                If X > 0 Then
                    Angle = Atn(-X) + (PI * 2)
                Else
                    Angle = Atn(-X)
                End If
            End If
        End If
    Else
        Angle = 0
    End If
End Function
