GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Download
  • News
  • Community
  • Resources
  • Language Reference
  • SmallBASIC Manual

This view

  • Original page
  • New address

GeezerVison is showing smallbasic.github.io — SmallBASIC | ATAN2

Edit History

ATAN2

a = ATAN2 (x, y)

Home > Reference > Math

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

x = 10                       ' Opposite side of right-angled triangle
y = 100                      ' Adjacent side of right-angled triangle

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.

centerX = xmax / 2
centerY = ymax / 2

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

    mouseX = pen(4) 
    mouseY = pen(5)

    line centerX, centerY, mouseX, mouseY, 15 'draw line from center to mouse

    differenceX = mouseX - centerX
    differenceY = mouseY - centerY 
    a = atan2(differenceY, differenceX)       ' < notice y difference is listed first

    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

    s = "Angle of mouse to center of screen ~ " + deg(a)\1 + " degrees"
    locate 30, 20 : print s
    showpage
    delay 10
wend
Code samples using ATAN2
another look at trig functions.bas   bowling7.bas   curve.bas   dmsareaplot.bas   navigation.bas   polyline.bas   zacalc.bas  
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  
This page was last edited on Tue, 19 Sep 2023 14:04:58 +0200 | Markdown processed with pandoc 3.1.12.1
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.