Kreissektor zeichnen
Übersicht

![]() |
BlitzMoritzBetreff: Kreissektor zeichnen |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hier eine kleine Funktion "DrawFilledSector()", mit der man einen Kreissektor zeichnet. Is' nicht weiter aufregend, nur gab es so'ne Function im Code-Archiv noch nicht.
Der Weg führt ganz einfach über die Approximation durch Dreiecke, die mit DrawPolygon gezeichnet werden. Mit dem Argument "maxdifference" stellt man optional ein, wie klein der Fehler am Kreisrand sein soll. Weitere Benutzeranleitung beim Starten des Beispiels. Code: [AUSKLAPPEN] SuperStrict
'##################################################### Function DrawFilledSector(centralX:Float, centralY:Float, radius:Float, angle1:Float, angle2:Float, maxdifference:Float = 0.5) If radius < 2 Then Return maxdifference = Min(Int(radius)-1, maxdifference) Local anglestep:Float = 2 * ACos(1.0 - maxdifference / radius) While angle1 > angle2 angle2 = angle2 + 360 Wend Local count:Int = Max(1, Int((angle2 - angle1) / anglestep) + 1) anglestep = (angle2 - angle1) / count Local px1:Float = centralX + radius * Cos(angle1) Local py1:Float = centraly + radius * Sin(angle1) Local px2:Float, py2:Float While angle2 - angle1 > 0.5 * anglestep angle1 = angle1 + anglestep px2 = centralX + radius * Cos(angle1) py2 = centraly + radius * Sin(angle1) DrawPoly ([ centralX, centralY, px1, py1, px2, py2 ]) px1 = px2 py1 = py2 Wend End Function '##################################################### AppTitle = "Kreissektor-Demo" Graphics 900,700 Local Mx1:Float, My1:Float, Mx2:Float, My2:Float, Zx:Float = 450, Zy:Float = 375 Local Radius:Float = 200, Winkel1:Float = -120, Winkel2:Float = -20 '--------------------------------------------------------------------------------------------------- Repeat '--------------------------------------------------------------------------------------------------- If MouseDown(1) Then Mx1= MouseX() My1 = MouseY() Radius = Sqr((Mx1-Zx)^2 + (My1-Zy)^2) Winkel1 = ATan2(My1-Zy, Mx1 - Zx) ElseIf MouseDown(2) Then Mx2= MouseX() My2 = MouseY() Radius= Sqr((Mx2-Zx)^2 + (My2-Zy)^2) Winkel2 = ATan2(My2-Zy, Mx2 - Zx) End If '--------------------------------------------------------------------------------------------------- Cls DrawText "Variiere mit linker Maustaste den ersten Schenkel des Winkels = " + Winkel1 + " Grad", 10, 20 DrawText "Variiere mit rechter Maustaste den zweiten Schenkel des Winkels = " + Winkel2 + " Grad", 10, 40 DrawText "Drehrichtung IM UHRZEIGERSINN !", 10, 60 DrawFilledSector(Zx, Zy, Radius, Winkel1, Winkel2) Flip '--------------------------------------------------------------------------------------------------- Until KeyDown(KEY_ESCAPE) Or AppTerminate() |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group