![]() |
AW: Ellipsenalgo aus Formelsammlung kreieren
Zitat:
Man will die Schrittlänge, oder "Punktdichte" ja nicht jedes Mal von Hand optimieren und vorgeben. Bei kleinen Ellipsen sind 4096 vielleicht totaler Overhead, bei großen Ellipsen kommt es vielleicht gerade mal so hin. Die Frage wäre deshalb, wie berechne ich die Schritte immer optimal, z.B. anhand einer gewünschten "Punktdichte" für alle Zeichenelemente auf dem Canvas ? Dazu fallen mir mindestens 3 Alternativen ein, die aber alle nicht ideal sind, weil sie sqrt und trigonometrische Funktionen nutzen können. Grundsätzlich denke ich, gibt es: A.) Entweder vor dem eigentlichen Zeichen berechen/abschätzen
Delphi-Quellcode:
Das kann spitze Enden aber womöglich nicht dicht genug abbilden.function CalcNumSteps(a, b, stAngleDeg, endAngleDeg: Extended; dMax: Integer): Integer; oder B.) iterativ innerhalb der Zeichenschleife anhand der Teilstücke berechnen. Damit könnte zumindest die "Punktdichte" auch variieren, z.B. bei extrem unsymmetrischen Ellipsen. Vielleicht gibt es dafür ja auch eine möglichst effiziente Methode, die ich nicht kenne? |
AW: Ellipsenalgo aus Formelsammlung kreieren
Zitat:
![]() |
AW: Ellipsenalgo aus Formelsammlung kreieren
Zitat:
|
AW: Ellipsenalgo aus Formelsammlung kreieren
the Step should be calculated from the drawing function not to be supplied with a, b, startangle and endangle, unless you want to draw points instead of continuous line, and it should be calculated from the radius, the radius here is Sqrt(a^2+b^2)
Step = 1/Sqrt(a^2+b^2) and that it is for continuous line, if you want a dotted draw then make the passed parameter with coefficient as factor to the step so it will be Step = StepMultiplier/Sqrt(a^2+b^2) |
AW: Ellipsenalgo aus Formelsammlung kreieren
Zitat:
I think it depends a lot on the shape, how to handle it. For lines, circles, squares, a pre-calculated step will work nicely. For ellipses and other complex paths, maybe you always need varying step-sizes during drawing. |
AW: Ellipsenalgo aus Formelsammlung kreieren
Zitat:
the only case when it corrupt drawing is when the ellipse is more like a line then an ellipse, when one of the axis is barely moving while the other taking the full speed for the next step. |
AW: Ellipsenalgo aus Formelsammlung kreieren
To calculate this accurately you need to take the last used step then calculate the length to move for current pixel based on the last step, draw it then adjust the step for the next one, so in theory we will be calculating the step for the next pixel but not for the current one.
after calculating the distance from the last pixel divide by the radius and use it for the next pixel. |
AW: Ellipsenalgo aus Formelsammlung kreieren
Zitat:
An algorithm sould be univeral and not break when it comes closer to extreme settings. ![]() If the dot is on top side, each of its step is maybe set to be dense enough. If the dot is in right side, anbd the ellipse not very high, then the density will increase a lot, perhaps too dense. Either you can accept these changes in density, or you try to optimize it in each step. The whole world is a compromize :-D Maybe one solution would be to divide the ellipse into sections, where its equal to circle, where its more dense and where its not so dense, for switching to different optimized algorithms in each segment. |
AW: Ellipsenalgo aus Formelsammlung kreieren
Zitat:
1) in the first it is easier to simply compare (new pixel vs last pixel) then adjust. 2) in the other you must have the distance is close enough to 1 in four straight direction (up, down, left and right) and close enough to sqrt(2) in 4 diagonal direction, any less than that we are drawing on top of the current (or the last), any bigger we are skipping. Whole problem is due the arithmetic is in float numbers while drawing and coordination in integers. i don't think that there is quite real one liner algorithm that can be solve this. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:49 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz