The [[ATN]] or arctangent function returns the angle in radians of a numerical [[TAN|tangent]] value. {{PageSyntax}} : {{Parameter|radianAngle}} = [[ATN]]({{Parameter|tangent!}}) {{Parameters}} * The return is the {{Parameter|tangent!}}'s angle in '''radians'''. * {{Parameter|tangent!}} [[SINGLE]] or [[DOUBLE]] values are used by the function. EX:'''{{text|Pi <nowiki>=</nowiki> 4 * ATN(1)|green}}''' {{PageDescription}} * To convert from radians to degrees, multiply radians * (180 / &pi;). * The ''tangent'' value would be equal to the tangent value of an angle. Ex: '''{{text|[[TAN]](ATN(1)) <nowiki>=</nowiki> 1|green}}''' * The function return value is between -&pi; / 2 and &pi; / 2. {{PageExamples}} ''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:'' [[ATN]] can be used to define &pi; in [[SINGLE]] or [[DOUBLE]] precision. The calculation cannot 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}} :''Note:'' You can use QB64's native [[_PI]] function. ''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$}} <> "" {{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# > 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# > y1# {{Cl|THEN}} getangle# = 180 {{Cl|EXIT FUNCTION}} {{Cl|END IF}} {{Cl|IF...THEN|IF}} y2# < y1# {{Cl|THEN}} {{Cl|IF...THEN|IF}} x2# > 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}}