CodeItBetter Programming Another VB Programming Blog

ArcTangent function that works in all quadrants

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'Math - ArcTangent function that works in all quadrants
Option Explicit
 
Public Function ArcTangent(ByVal op As Double, ByVal ad As Double) As Double
    Const PI = 3.14159265358979
    Dim at As Double
 
    If ad = 0 Then
        If op > 0 Then
            ArcTangent = PI / 2#
        Else
            ArcTangent = PI * 1.5
        End If
    Else
        at = Atn(op / ad)
        If ad < 0 Then
            ArcTangent = PI + at
        ElseIf op# < 0 Then
            ArcTangent = PI + PI + at
        Else
            ArcTangent = at
        End If
    End If
End Function
Filed under: Math Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.