Basic Univers
; Auteur Dr.Dri
; Formules trigonométriques

Procedure.f Pi()
  !FLDPI
EndProcedure

Debug Pi()


; - - - - - - - - - - - - - - - - - - - - - - - -



Procedure.f Sec(x.f)
  ProcedureReturn 1 / Cos(x)
EndProcedure

Procedure.f CoSec(x.f)
  ProcedureReturn 1 / Sin(x)
EndProcedure

Procedure.f CoTan(x.f)
  ProcedureReturn 1 / Tan(x)
EndProcedure


; - - - - - - - - - - - - - - - - - - - - - - - -


Procedure.f Pi2()
  ProcedureReturn ATan(1) * 4
EndProcedure

Procedure.f ATanFull(dx.f, dy.f)
  Protected alpha.f, pi.f
 
  pi = Pi()
 
  If dx = 0
    alpha = 90
    If dy < 0
      alpha + pi
    EndIf
  Else
    If dy = 0
      alpha = 0
    Else
      alpha = ATan(dy / dx)
    EndIf
    If dx < 0
      alpha + pi
    EndIf
  EndIf
 
  If alpha < 0
    alpha + pi + pi
  EndIf
  ProcedureReturn alpha
EndProcedure


angle.f
pi.f = Pi()
OpenWindow(0, 0, 0, 400, 400, #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered, "ATanFull")
Repeat
  If StartDrawing( WindowOutput() )
   
    Box(0, 0, 400, 400, $FFFFFF)
   
    DrawingMode(4|1)
   
    Circle(200, 200, 150, $000000)
    Line(20, 200, 360, 0)
    Line(200, 20, 0, 360)
   
    Locate(352, 200) : DrawText("0")
    Locate(202, 350) : DrawText("90")
    Locate( 22, 200) : DrawText("180")
    Locate(202,  20) : DrawText("270")
   
    x = WindowMouseX()
    y = WindowMouseY()
   
    If x>= 0 And y>= 0 And x<400 And y<400
      dx = x - 200
      dy = y - 200
     
      angle =(ATanFull(dx, dy) * 180) / pi
      Locate(0, 0) : DrawText( StrF(angle) )
     
      LineXY(200, 200, x, y, $0000ff)
    EndIf
   
    StopDrawing()
  EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow