ATanFull
Degrees# = ATanFull(Y, X)
 
Parameters:

    Y = The value representing the y-coordinate of a point.
    X = The value representing the x-coordinate of a point.
Returns:

    Degrees# = Angle in degrees range between (-180 to 180)
 

     ATanFull calculates the arc tangent of the two variables Y and X. It is similar to calculating the arc tangent of X / Y, except that the signs of both arguments are used to determine the quadrant of the result.

     ATanFull can be used to aim one sprite at another. For example, if Sprite #1 is at the point(X1, Y1), and Sprite #2 is at point (X2, Y2), ATanFull(Y1-Y2. X1-X2) will return an angle (in degrees) that can be used to rotate Sprite #2 so that it aims at Sprite #1.



FACTS:


     * In some programming languages ATanFull is called ATan2

     * Notice the order of the parameters Y and X.

     * Also See GetAngle2D and WrapAngle if want the angle to be within 0 to 360




Mini Tutorial:


  
; Create a coloured image
  Cls RGB(0,255,0)
  Image = GetFreeImage()
  GetImage Image,0,0,64,32
  PrepareFXImage Image
  
; Calculate the position of the sprite
  SpriteXPos = GetScreenWidth() / 2
  SpriteYPos = GetScreenHeight() - 100
  
  
; Create a sprite and assign the image
  Sprite =NewSprite(SpriteXPos,SpriteYPos,image)
  SpriteDrawMode Sprite,2
  SpriteHandle Sprite,(GetImageWidth(Image)/2)*-1,(GetImageHeight(Image)/2)*-1
  
; align the sprite to the current mouse position
  Repeat
     Cls RGB(0,0,0)
     
   ; calc the angle from the spites position to the mousex
     angle# = ATanFullMouseY()-SpriteYPos, MouseX() - SpriteXPos)
     RotateSprite Sprite, angle#
     
   ; Draw All the Sprites
     DrawAllSprites
     
     Sync
  Until EscKey()
  



 
Related Info: AngleDifference | Atan | CurveAngle | GetAngle2D | GetDistance2D | Tan | TurnDirection | WrapAngle :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com