AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Ellipsenalgo aus Formelsammlung kreieren

Ellipsenalgo aus Formelsammlung kreieren

Ein Thema von delphifan2004 · begonnen am 8. Jul 2025 · letzter Beitrag vom 12. Jul 2025
Antwort Antwort
Seite 2 von 3     12 3   
Rollo62

Registriert seit: 15. Mär 2007
4.240 Beiträge
 
Delphi 12 Athens
 
#11

AW: Ellipsenalgo aus Formelsammlung kreieren

  Alt 9. Jul 2025, 08:39
Danke an Euch alle! So wird meine Ellipse gezeichnet. Mit 4096 Schritten passiert das lückenlos.
Genau, das ist generell die Problematik bei diesen parametriesierten Methoden.
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:

    function CalcNumSteps(a, b, stAngleDeg, endAngleDeg: Extended; dMax: Integer): Integer;
Das kann spitze Enden aber womöglich nicht dicht genug abbilden.

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?
  Mit Zitat antworten Zitat
Benutzerbild von dummzeuch
dummzeuch

Registriert seit: 11. Aug 2012
Ort: Essen
1.733 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#12

AW: Ellipsenalgo aus Formelsammlung kreieren

  Alt 9. Jul 2025, 09:39
Zitat:
Vielleicht ist es besser, die Laufvariable parametrisch zu Normieren und nicht als Winkel zu übernehmen.
Dann kann man das Rendering etwass besser steuern.

Delphi-Quellcode:

    x := xm + xR * Cos(t);
    y := ym + yR * Sin(t);
Wo ich das gerade lese: Es gibt in Math eine Funktion SinCos, die Cos und Sin gleichzeitig berechnet und dadurch effizienter ist.
Thomas Mueller
  Mit Zitat antworten Zitat
freimatz

Registriert seit: 20. Mai 2010
1.513 Beiträge
 
Delphi 11 Alexandria
 
#13

AW: Ellipsenalgo aus Formelsammlung kreieren

  Alt 9. Jul 2025, 09:56
@himitsu: Ja, Delphi kann das auch aber ich wollte ja gerade wissen wie das Delphi intern macht und dazu ist die Ellipsengleiching notwendig.
Delphi macht das intern sicher anders. Dazu müsste man in dessen Code schauen.
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
457 Beiträge
 
#14

AW: Ellipsenalgo aus Formelsammlung kreieren

  Alt 9. Jul 2025, 10:08
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)
Kas
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
4.240 Beiträge
 
Delphi 12 Athens
 
#15

AW: Ellipsenalgo aus Formelsammlung kreieren

  Alt 9. Jul 2025, 15:53
Step = 1/Sqrt(a^2+b^2)
Like said, it is the sqrt that makes me nervous, but its maybe needed here.
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.
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
457 Beiträge
 
#16

AW: Ellipsenalgo aus Formelsammlung kreieren

  Alt 9. Jul 2025, 16:26
Step = 1/Sqrt(a^2+b^2)
Like said, it is the sqrt that makes me nervous, but its maybe needed here.
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.
A overdraw pixel will happen for the suggested above for sure, but it will not affect the drawing, the only enhancement to do is to check if x and y changed from last pixel/point then draw, due to approximation of course, as for dynamic, it will return to the same check no matter what algorithm been used, for more accurate approximation you need to calculate the derivative of the speed of pixel on the slope then divide it by the radius, but not that radius you will calculate from (0,0) the center of the ellipse, this will be more complex for no, benefit visually or not.

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.
Kas
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
457 Beiträge
 
#17

AW: Ellipsenalgo aus Formelsammlung kreieren

  Alt 9. Jul 2025, 16:30
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.
Kas
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
4.240 Beiträge
 
Delphi 12 Athens
 
#18

AW: Ellipsenalgo aus Formelsammlung kreieren

  Alt 9. Jul 2025, 16:55
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.
Yes, thats what I meant.
An algorithm sould be univeral and not break when it comes closer to extreme settings.
https://www.geogebra.org/m/AAx6FWka

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

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.

Geändert von Rollo62 ( 9. Jul 2025 um 16:58 Uhr)
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
457 Beiträge
 
#19

AW: Ellipsenalgo aus Formelsammlung kreieren

  Alt 9. Jul 2025, 17:31
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.
Think about it, no matter how much you divide it will return to check against the last pixel or calculating the new (next) pixel distance form the current:
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.
Kas
  Mit Zitat antworten Zitat
Baird

Registriert seit: 24. Dez 2024
2 Beiträge
 
#20

AW: Ellipsenalgo aus Formelsammlung kreieren

  Alt 10. Jul 2025, 07:10
Vielen Dank für das Teilen und den Rat. Die Diskussion zu diesem Thema ist sehr bedeutsam und hilft mir sehr.
Gute Gesellschaft ist unterwegs der kürzeste Weg.
motores paso a paso nema 16
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 3     12 3   

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:45 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