<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ellipse zeichnen]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe gerade ein Problem mit einem Algorithmus zum rastern einer Ellipse. Der Code sieht wie folgt aus:</p>
<pre><code class="language-cpp">void ImageWidget::drawEllipse(int x, int y, int rx, int ry, int phi) {
    QPainter painter(image);
    painter.setPen(Qt::green);

    double pi = 4 * std::atan(1);
    double cosphi = std::cos(phi);
    double sinphi = std::sin(phi);
    double a = rx * cosphi;
    double b = ry * sinphi;
    double c = rx * sinphi;
    double d = ry * cosphi;
    double x0 = a + x;
    double y0 = c + y;
    double theta = 0;
    int n = 100;
    double incr = 2 * pi / n;
    for(int j = 0; j &lt;= n; j++) {
        theta += incr;
        double costheta = std::cos(theta);
        double sintheta = std::sin(theta);
        double x1 = a * costheta - b * sintheta + x;
        double y1 = c * costheta + d * sintheta + y;
        painter.drawLine(x0, y0, x1, y1);
        x0 = x1;
        y0 = y1;
    }

    update();
}
</code></pre>
<p>Zum testen sollte eine Ellipse im 90° Winkel gezeichnet werden. Wie man jedoch unschwer am angehängten Bild erkennen kann ist das Ergebnis alles andere als korrekt. Problem ist nun, dass ich meinen Fehler einfach nicht sehe...</p>
<p><a href="http://s14.directupload.net/images/120520/ybvbr4du.jpg" rel="nofollow">http://s14.directupload.net/images/120520/ybvbr4du.jpg</a></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/303688/ellipse-zeichnen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 07:23:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/303688.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 20 May 2012 13:42:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ellipse zeichnen on Sun, 20 May 2012 13:42:55 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe gerade ein Problem mit einem Algorithmus zum rastern einer Ellipse. Der Code sieht wie folgt aus:</p>
<pre><code class="language-cpp">void ImageWidget::drawEllipse(int x, int y, int rx, int ry, int phi) {
    QPainter painter(image);
    painter.setPen(Qt::green);

    double pi = 4 * std::atan(1);
    double cosphi = std::cos(phi);
    double sinphi = std::sin(phi);
    double a = rx * cosphi;
    double b = ry * sinphi;
    double c = rx * sinphi;
    double d = ry * cosphi;
    double x0 = a + x;
    double y0 = c + y;
    double theta = 0;
    int n = 100;
    double incr = 2 * pi / n;
    for(int j = 0; j &lt;= n; j++) {
        theta += incr;
        double costheta = std::cos(theta);
        double sintheta = std::sin(theta);
        double x1 = a * costheta - b * sintheta + x;
        double y1 = c * costheta + d * sintheta + y;
        painter.drawLine(x0, y0, x1, y1);
        x0 = x1;
        y0 = y1;
    }

    update();
}
</code></pre>
<p>Zum testen sollte eine Ellipse im 90° Winkel gezeichnet werden. Wie man jedoch unschwer am angehängten Bild erkennen kann ist das Ergebnis alles andere als korrekt. Problem ist nun, dass ich meinen Fehler einfach nicht sehe...</p>
<p><a href="http://s14.directupload.net/images/120520/ybvbr4du.jpg" rel="nofollow">http://s14.directupload.net/images/120520/ybvbr4du.jpg</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2213423</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2213423</guid><dc:creator><![CDATA[smoon]]></dc:creator><pubDate>Sun, 20 May 2012 13:42:55 GMT</pubDate></item><item><title><![CDATA[Reply to Ellipse zeichnen on Sun, 20 May 2012 14:16:47 GMT]]></title><description><![CDATA[<p>Hey,</p>
<p>dein cos(phi) bzw. sin(phi) sorgt dafür, dass die Elipse um die X-Achse rotiert !<br />
Wenn ich das richtig verstanden habe, möchtest du, dass die Hauptachse parallel zur X-Achse verläuft !?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2213430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2213430</guid><dc:creator><![CDATA[ponchosi]]></dc:creator><pubDate>Sun, 20 May 2012 14:16:47 GMT</pubDate></item><item><title><![CDATA[Reply to Ellipse zeichnen on Sun, 20 May 2012 17:11:49 GMT]]></title><description><![CDATA[<p>BTW: Wenn die Ellipse immer Axis-Aligned ist könntest du einen &quot;Bresenham Style&quot; Algorithmus verwenden:<br />
<a href="http://www.gamedev.sk/bresenham-s-ellipse-algorithm" rel="nofollow">http://www.gamedev.sk/bresenham-s-ellipse-algorithm</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2213483</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2213483</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 20 May 2012 17:11:49 GMT</pubDate></item><item><title><![CDATA[Reply to Ellipse zeichnen on Sun, 20 May 2012 18:33:01 GMT]]></title><description><![CDATA[<p>smoon schrieb:</p>
<blockquote>
<p>Zum testen sollte eine Ellipse im 90° Winkel gezeichnet werden. Wie man jedoch unschwer am angehängten Bild erkennen kann ist das Ergebnis alles andere als korrekt. Problem ist nun, dass ich meinen Fehler einfach nicht sehe...</p>
</blockquote>
<p>Ich rate jetzt nur; wenn Du von 90° sprichst, meinst Du damit, dass die Ellipse quasi 'hochkant' auf der Spitze steht? Falls ja, welchen Wert uebergibst Du beim Funktionsaufruf an phi? Etwa 90? Da alles im Bogenmass ist, waere der richtige Wert pi/2, aber da Du dort eine int Variable uebergibst, kannst Du damit pi/2 nicht abbilden.<br />
[Teilweise geloescht aufgrund voreiliger Schlussfolgerung <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> ]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2213530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2213530</guid><dc:creator><![CDATA[wollewausfander]]></dc:creator><pubDate>Sun, 20 May 2012 18:33:01 GMT</pubDate></item><item><title><![CDATA[Reply to Ellipse zeichnen on Sun, 20 May 2012 20:04:25 GMT]]></title><description><![CDATA[<p>Danke dort lag wirklich der Fehler. Richtig ist es natürlich so:</p>
<pre><code class="language-cpp">double convert = pi /180;
double cosphi = std::cos(phi*convert);
double sinphi = std::sin(phi*convert);
</code></pre>
<p>Jetzt funktionierts <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2213571</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2213571</guid><dc:creator><![CDATA[smoon]]></dc:creator><pubDate>Sun, 20 May 2012 20:04:25 GMT</pubDate></item></channel></rss>