The {{KW|ATN}} or arctangent function returns the angle in radians of a numerical [[TAN|tangent]] value.


{{PageSyntax}}
:: radian_angle = '''ATN(''tangent!'')'''


{{Parameters}}
* The return is that tangent value's ''angle'' in radians.
* ''tangent'' [[SINGLE]] or [[DOUBLE]] values are use by the function. EX:'''{{text|Pi &lt;nowiki&gt;=&lt;/nowiki&gt; 4 * ATN(1)|green}}'''


{{PageDescription}}
* To convert from radians to degrees, multiply radians * (180 / &amp;pi;).
* The ''tangent'' value would be equal to the tangent value of an angle. EX: '''{{text|[[TAN]](ATN(1)) &lt;nowiki&gt;=&lt;/nowiki&gt; 1|green}}'''
* The function return value is between -&amp;pi; / 2 and &amp;pi; / 2.


''Example 1:'' When the [[TAN]]gent value equals 1, the line is drawn at a 45 degree angle(.7853982 radians) where [[SIN]] / [[COS]] = 1.
{{CodeStart}} '' ''
{{Cl|SCREEN}} 12
x = 100 * {{Cl|COS}}({{Cl|ATN}}(1))
y = 100 * {{Cl|SIN}}({{Cl|ATN}}(1))
{{Cl|LINE}} (200, 200)-(200 + x, 200 + y) '' ''
{{CodeEnd}}


''Example 2:'' {{KW|ATN}} can be used to define &amp;pi; in [[SINGLE]] or [[DOUBLE]] precision. The calculation can NOT be used as a [[CONST]]ant.
{{CodeStart}} '' ''
Pi = 4 * {{Cl|ATN}}(1)   '{{Cl|SINGLE}} precision
Pi# = 4 * {{Cl|ATN}}(1#) '{{Cl|DOUBLE}} precision
PRINT Pi, Pi# '' ''
{{CodeEnd}}


''Example 3:'' Finds the angle from the center point to the mouse pointer. 
{{CodeStart}} '' ''
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32)
x1! = 320
y1! = 240

DO
  {{Cl|PRESET}} (x1!, y1!), {{Cl|_RGB}}(255, 255, 255)
  dummy% = {{Cl|_MOUSEINPUT}}
  x2! = {{Cl|_MOUSEX}}
  y2! = {{Cl|_MOUSEY}}
  {{Cl|LINE}} (x1, y1)-(x2, y2), {{Cl|_RGB}}(255, 0, 0)
  {{Cl|LOCATE}} 1, 1: {{Cl|PRINT}} getangle(x1!, y1!, x2!, y2!)
  {{Cl|_DISPLAY}}
  {{Cl|_LIMIT}} 200
  {{Cl|CLS}}
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} &lt;&gt; &quot;&quot;
{{Cl|END}}

{{Cl|FUNCTION}} getangle# (x1#, y1#, x2#, y2#) 'returns 0-359.99...
{{Cl|IF...THEN|IF}} y2# = y1# {{Cl|THEN}}
  {{Cl|IF...THEN|IF}} x1# = x2# {{Cl|THEN}} {{Cl|EXIT FUNCTION}}
  {{Cl|IF...THEN|IF}} x2# &gt; x1# {{Cl|THEN}} getangle# = 90 {{Cl|ELSE}} getangle# = 270
  {{Cl|EXIT FUNCTION}}
{{Cl|END IF}}
{{Cl|IF...THEN|IF}} x2# = x1# {{Cl|THEN}}
  {{Cl|IF...THEN|IF}} y2# &gt; y1# {{Cl|THEN}} getangle# = 180
  {{Cl|EXIT FUNCTION}}
{{Cl|END IF}}
{{Cl|IF...THEN|IF}} y2# &lt; y1# {{Cl|THEN}}
  {{Cl|IF...THEN|IF}} x2# &gt; x1# {{Cl|THEN}}
    getangle# = {{Cl|ATN}}((x2# - x1#) / (y2# - y1#)) * -57.2957795131
  {{Cl|ELSE}}
    getangle# = {{Cl|ATN}}((x2# - x1#) / (y2# - y1#)) * -57.2957795131 + 360
  {{Cl|END IF}}
{{Cl|ELSE}}
  getangle# = {{Cl|ATN}}((x2# - x1#) / (y2# - y1#)) * -57.2957795131 + 180
{{Cl|END IF}}
{{Cl|END FUNCTION}} '' ''
{{CodeEnd}}{{small|Function by Galleon}}


{{PageSeeAlso}}
* [[_PI]] {{text|(QB64 function)}}
* [[TAN]] {{text|(tangent function)}}
* [[SIN]], [[COS]]
* [[Mathematical Operations]]
* [[Mathematical_Operations#Derived_Mathematical_Functions|Derived Mathematical Functions]]


{{PageNavigation}}