Wie kann man Bögen zeichnen?

Anfängerfragen zum Programmieren mit PureBasic.
derschutzhund
Beiträge: 328
Registriert: 06.06.2013 20:37
Computerausstattung: Satellite A210-19Z, Samsung Netbook N130, VPAD10

Re: Wie kann man Bögen zeichnen?

Beitrag von derschutzhund »

Fehler behoben wenn der Startwinkel größer als Endwinkel!

Code: Alles auswählen

Procedure Bogen(mx.f, my.f, sx.f, sy.f, ex.f, ey.f, d.f, genauigkeit.f, fakt.f, maxiy.i)
   Define  radius.f, Gwinkel.f, Swinkel.f, Ewinkel.f, aktwinkel.f
   Define wpx1.f, wpy1.f, wpx2.f, wpy2.f, absewinkel.f
   
   radius = Sqr(((sx-mx)*(sx-mx)) + ((sy-my)*(sy-my)))
   
   swinkel= ACos((sx-mx)/radius)*57.295776
   If my>sy : swinkel=360-swinkel : EndIf
   
   ewinkel= ACos((ex-mx)/radius)*57.295776
   If my>ey : ewinkel=360-ewinkel : EndIf
   
   If ewinkel = swinkel : swinkel = 0 : ewinkel = 360 : EndIf
   
   If ewinkel < swinkel 
      absewinkel = ewinkel
      ewinkel = 360
   EndIf
   
   aktwinkel = Swinkel
   
   wpx1 = sx
   wpy1 = sy
   While aktwinkel + genauigkeit < ewinkel
      aktwinkel = aktwinkel + genauigkeit        
      wpx2 = mx + radius*Cos(Radian(aktwinkel))
      wpy2 = my + radius*Sin(Radian(aktwinkel))
      
      ; Ausgabe über eigene Linienfunktion
      LinieXYD(wpx1,wpy1,wpx2,wpy2,d,fakt,maxiy)                  
      ; Ausgabe über Standardlinie
      ;     LineXY(Round(wpx1,#PB_Round_Nearest),maxiy-Round(wpy1,#PB_Round_Nearest),Round(wpx2,#PB_Round_Nearest),maxiy-Round(wpy2,#PB_Round_Nearest),RGB(1, 1,0))
      wpx1 = wpx2
      wpy1 = wpy2
   Wend   
   
   If aktwinkel < ewinkel      
      ; Ausgabe über eigene Linienfunktion
      LinieXYD(wpx1,wpy1,wpx2,wpy2,d,fakt,maxiy)      
      ; Ausgabe über Standardlinie         
      ; LineXY(Round(wpx1,#PB_Round_Nearest),maxiy-Round(wpy1,#PB_Round_Nearest),Round(ex,#PB_Round_Nearest),maxiy-Round(ey,#PB_Round_Nearest),RGB(1, 1,0))
   EndIf
   
   If absewinkel < swinkel
      aktwinkel = 0.0
      ewinkel = absewinkel
      While aktwinkel + genauigkeit < ewinkel
         aktwinkel = aktwinkel + genauigkeit        
         wpx2 = mx + radius*Cos(Radian(aktwinkel))
         wpy2 = my + radius*Sin(Radian(aktwinkel))
         
         ; Ausgabe über eigene Linienfunktion
         LinieXYD(wpx1,wpy1,wpx2,wpy2,d,fakt,maxiy)                  
         ; Ausgabe über Standardlinie
         ;     LineXY(Round(wpx1,#PB_Round_Nearest),maxiy-Round(wpy1,#PB_Round_Nearest),Round(wpx2,#PB_Round_Nearest),maxiy-Round(wpy2,#PB_Round_Nearest),RGB(1, 1,0))
         wpx1 = wpx2
         wpy1 = wpy2
      Wend   
      
      If aktwinkel < ewinkel      
         ; Ausgabe über eigene Linienfunktion
         LinieXYD(wpx1,wpy1,wpx2,wpy2,d,fakt,maxiy)      
         ; Ausgabe über Standardlinie         
         ; LineXY(Round(wpx1,#PB_Round_Nearest),maxiy-Round(wpy1,#PB_Round_Nearest),Round(ex,#PB_Round_Nearest),maxiy-Round(ey,#PB_Round_Nearest),RGB(1, 1,0))
      EndIf     
   EndIf   
EndProcedure   
Satellite A210-19Z, Samsung N130, VPAD10, WinXP, Win7, PuppyLinux, PB 5.24, 5.31. 5.70
Elektronik, Mikrocontroller, CNC-Technik, 3D-Druck
Antworten