ATAN2
a = ATAN2 (x, y)
Returns the angle a
in radians of a right-angled
triangle, where x
is the opposite side and y
is the adjacent side.
Example 1
10 ' Opposite side of right-angled triangle
x = 100 ' Adjacent side of right-angled triangle
y =
print deg( atan2(x, y) ) ' Output: 5.71059313749964
Example 2: Graphics demo
' Both atan(n) and atan2(y, x) return an angle measured in radians.
' The return measure is from -pi to pi. In demo below it is converted
' to angle between 0 and 360 degrees.
' atan2 is better for detecting angle's quardrant because
' x and y are given separartely.
' y the vertical change is given first.
xmax / 2
centerX = ymax / 2
centerY =
pen on
while asc(inkey) <> 27
cls
locate 0,20: print "ATAN2 demo, used to detect angle of mouse to screen center."
at centerX + 210, centerY - 10 : Print "0 degrees (or radians)"
line centerX, centerY, centerX + 200, centerY
pen(4)
mouseX = pen(5)
mouseY =
line centerX, centerY, mouseX, mouseY, 15 'draw line from center to mouse
differenceX = mouseX - centerX
differenceY = mouseY - centerY atan2(differenceY, differenceX) ' < notice y difference is listed first
a =
if a < 0 then a += 2 * pi ' atan2 returns neg number for angles > 180
arc centerX, centerY, 100, 0, a 'draw the arc from 0 to angle
"Angle of mouse to center of screen ~ " + deg(a)\1 + " degrees"
s = locate 30, 20 : print s
showpage
delay 10
wend
Code samples using ATAN2
Math
ABS
ABSMAX
ABSMIN
ACOS
ACOSH
ACOT
ACOTH
ACSC
ACSCH
ASEC
ASECH
ASIN
ASINH
ATAN
ATAN2
ATANH
ATN
CEIL
COS
COSH
COT
COTH
CSC
CSCH
DEG
DERIV
DETERM
DIFFEQN
EXP
EXPRSEQ
FIX
FLOOR
FRAC
INT
INTERSECT
INVERSE
LINEQN
LOG
LOG10
M3APPLY
M3IDENT
M3ROTATE
M3SCALE
M3TRANS
MAX
MIN
POLYAREA
POLYCENT
POLYEXT
POW
PTDISTLN
PTDISTSEG
PTSIGN
RAD
RND
ROOT
ROUND
SEC
SECH
SEGCOS
SEGLEN
SEGSIN
SEQ
SGN
SIN
SINH
SQR
STATMEAN
STATMEANDEV
STATMEDIAN
STATSPREADP
STATSPREADS
STATSTD
SUM
SUMSQ
TAN
TANH
TRANSPOSE
If there is insufficient information on this page and you wish learn more about ATAN2,
please send an email to smallbasic@gmail.com. You can help to improve information about
ATAN2 by submitting a pull request,
click View Source for details. Note, an offline language reference text file is also available - see the Download section.