ATN: Difference between revisions
Jump to navigation
Jump to search
Function by Galleon
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
m (Protected "ATN" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite))) |
m (Add _ATAN2 under "See Also") |
||
(8 intermediate revisions by one other user not shown) | |||
Line 6: | Line 6: | ||
{{ | {{PageParameters}} | ||
* The return is the {{Parameter|tangent!}}'s angle in '''radians'''. | * The return is the {{Parameter|tangent!}}'s angle in '''radians'''. | ||
* {{Parameter|tangent!}} [[SINGLE]] or [[DOUBLE]] values are used by the function. EX:'''{{ | * {{Parameter|tangent!}} [[SINGLE]] or [[DOUBLE]] values are used by the function. EX:'''{{Text|Pi <nowiki>=</nowiki> 4 * ATN(1)|green}}''' | ||
{{PageDescription}} | {{PageDescription}} | ||
* To convert from radians to degrees, multiply radians * (180 / π). | * To convert from radians to degrees, multiply radians * (180 / π). | ||
* The ''tangent'' value would be equal to the tangent value of an angle. Ex: '''{{ | * 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 -π / 2 and π / 2. | * The function return value is between -π / 2 and π / 2. | ||
Line 19: | Line 19: | ||
{{PageExamples}} | {{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. | ''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}} | {{CodeStart}} | ||
{{Cl|SCREEN}} 12 | {{Cl|SCREEN}} 12 | ||
x = 100 * {{Cl|COS}}({{Cl|ATN}}(1)) | x = 100 * {{Cl|COS}}({{Cl|ATN}}(1)) | ||
y = 100 * {{Cl|SIN}}({{Cl|ATN}}(1)) | y = 100 * {{Cl|SIN}}({{Cl|ATN}}(1)) | ||
{{Cl|LINE}} (200, 200)-(200 + x, 200 + y) | {{Cl|LINE}} (200, 200)-(200 + x, 200 + y) | ||
{{CodeEnd}} | {{CodeEnd}} | ||
''Example 2:'' [[ATN]] can be used to define π in [[SINGLE]] or [[DOUBLE]] precision. The calculation cannot be used as a [[CONST]]ant. | ''Example 2:'' [[ATN]] can be used to define π in [[SINGLE]] or [[DOUBLE]] precision. The calculation cannot be used as a [[CONST]]ant. | ||
{{CodeStart}} | {{CodeStart}} | ||
Pi = 4 * {{Cl|ATN}}(1) '{{Cl|SINGLE}} precision | Pi = 4 * {{Cl|ATN}}(1) '{{Cl|SINGLE}} precision | ||
Pi# = 4 * {{Cl|ATN}}(1#) '{{Cl|DOUBLE}} precision | Pi# = 4 * {{Cl|ATN}}(1#) '{{Cl|DOUBLE}} precision | ||
PRINT Pi, Pi# | PRINT Pi, Pi# | ||
{{CodeEnd}} | {{CodeEnd}} | ||
:''Note:'' You can use QB64's native [[_PI]] function. | :''Note:'' You can use QB64's native [[_PI]] function. | ||
''Example 3:'' Finds the angle from the center point to the mouse pointer. | ''Example 3:'' Finds the angle from the center point to the mouse pointer. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32) | {{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32) | ||
x1! = 320 | x1! = 320 | ||
Line 74: | Line 74: | ||
getangle# = {{Cl|ATN}}((x2# - x1#) / (y2# - y1#)) * -57.2957795131 + 180 | getangle# = {{Cl|ATN}}((x2# - x1#) / (y2# - y1#)) * -57.2957795131 + 180 | ||
{{Cl|END IF}} | {{Cl|END IF}} | ||
{{Cl|END FUNCTION}} | {{Cl|END FUNCTION}} | ||
{{CodeEnd}}{{ | {{CodeEnd}} | ||
{{Small|Function by Galleon}} | |||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [[_PI]] {{ | * [[_PI]] {{Text|(QB64 function)}} | ||
* [[TAN]] {{ | * [[_ATAN2]] {{Text|((QB64 function)}} | ||
* [[TAN]] {{Text|(tangent function)}} | |||
* [[SIN]], [[COS]] | * [[SIN]], [[COS]] | ||
* [[Mathematical Operations]] | * [[Mathematical Operations]] | ||
* [[ | * [[Mathematical Operations#Derived_Mathematical_Functions|Derived Mathematical Functions]] | ||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 12:21, 26 October 2023
The ATN or arctangent function returns the angle in radians of a numerical tangent value.
Syntax
- radianAngle = ATN(tangent!)
Parameters
- The return is the tangent!'s angle in radians.
- tangent! SINGLE or DOUBLE values are used by the function. EX:Pi = 4 * ATN(1)
Description
- To convert from radians to degrees, multiply radians * (180 / π).
- The tangent value would be equal to the tangent value of an angle. Ex: TAN(ATN(1)) = 1
- The function return value is between -π / 2 and π / 2.
Examples
Example 1: When the TANgent value equals 1, the line is drawn at a 45 degree angle (.7853982 radians) where SIN / COS = 1.
SCREEN 12 x = 100 * COS(ATN(1)) y = 100 * SIN(ATN(1)) LINE (200, 200)-(200 + x, 200 + y) |
Example 2: ATN can be used to define π in SINGLE or DOUBLE precision. The calculation cannot be used as a CONSTant.
Pi = 4 * ATN(1) 'SINGLE precision Pi# = 4 * ATN(1#) 'DOUBLE precision PRINT Pi, Pi# |
- Note: You can use QB64's native _PI function.
Example 3: Finds the angle from the center point to the mouse pointer.
SCREEN _NEWIMAGE(640, 480, 32) x1! = 320 y1! = 240 DO PRESET (x1!, y1!), _RGB(255, 255, 255) dummy% = _MOUSEINPUT x2! = _MOUSEX y2! = _MOUSEY LINE (x1, y1)-(x2, y2), _RGB(255, 0, 0) LOCATE 1, 1: PRINT getangle(x1!, y1!, x2!, y2!) _DISPLAY _LIMIT 200 CLS LOOP UNTIL INKEY$ <> "" END FUNCTION getangle# (x1#, y1#, x2#, y2#) 'returns 0-359.99... IF y2# = y1# THEN IF x1# = x2# THEN EXIT FUNCTION IF x2# > x1# THEN getangle# = 90 ELSE getangle# = 270 EXIT FUNCTION END IF IF x2# = x1# THEN IF y2# > y1# THEN getangle# = 180 EXIT FUNCTION END IF IF y2# < y1# THEN IF x2# > x1# THEN getangle# = ATN((x2# - x1#) / (y2# - y1#)) * -57.2957795131 ELSE getangle# = ATN((x2# - x1#) / (y2# - y1#)) * -57.2957795131 + 360 END IF ELSE getangle# = ATN((x2# - x1#) / (y2# - y1#)) * -57.2957795131 + 180 END IF END FUNCTION |
See also
- _PI (QB64 function)
- _ATAN2 ((QB64 function)
- TAN (tangent function)
- SIN, COS
- Mathematical Operations
- Derived Mathematical Functions