Ellipse wird in der pgfplot-Achsenumgebung nicht richtig skaliert und gedreht

Ellipse wird in der pgfplot-Achsenumgebung nicht richtig skaliert und gedreht

Ich habe Probleme, in einer pgfplots- axisUmgebung eine Ellipse basierend auf den Hauptachsen, Nebenachsen und dem Winkel in Bezug auf die X-Achse zu zeichnen. Ich habe es geschafft, eine solche Ellipse mit Tikz zu zeichnen, allerdings beachtet die Drehung des Winkels das Seitenverhältnis zwischen den Achsen nicht richtig. Damit meine ich, dass, wenn bei einer Figur mit fester Breite und Höhe und gleichem Seitenverhältnis der Winkel 45° beträgt, eine Vergrößerung des Bereichs der X-Achse die Ellipse „zusammenquetschen“ (und den Winkel vergrößern) sollte. Wie drehe ich also die Ellipse in Bezug auf das Koordinatensystem selbst, nicht nur „den Bildschirm“? Danke!

MWE:

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
    \begin{axis} [
        name=plot_left,
        scale only axis,
        height=35mm,
        width=15mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \draw[draw=blue] (axis cs:1,1) ellipse [x radius=0.25, y radius=0.5, rotate=45];
    \end{axis}
    \begin{axis} [
        name=plot_right,
        at={(plot_left.north east)},
        anchor=north west,
        xshift=10mm,
        scale only axis,
        height=35mm,
        width=90mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \draw[draw=blue] (axis cs:1,1) ellipse [x radius=0.25, y radius=0.5, rotate=45];
    \end{axis}
\end{tikzpicture}

\end{document}

Ausgabe:

Ellipse

Gewünscht:

Zur Klarstellung: Das ist es , wonach ich suche: also etwas in der Art der Lösung von Jasper Habicht (axis cs:1,1) ellipse [x radius=0.25*\a, y radius=0.5*\b, rotate=45*\c], wobei \aund basierend auf dem Seitenverhältnis und der Bildbreite berechnet werden.\b\c

gewünscht

Antwort1

Ich bin nicht sicher, ob Sie das meinen, aber Sie können den Drehwinkel berechnen, indem Sie die Breite und Höhe durch die Achseneinheiten dividieren und dann den Arcustangens erhalten. Allerdings bin ich nicht sicher, ob das wirklich das richtige Ergebnis liefert:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
    \begin{axis} [
        name=plot_left,
        scale only axis,
        height=35mm,
        width=15mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \pgfmathsetmacro{\a}{
            atan(
                (\pgfkeysvalueof{/pgfplots/width}/(\pgfkeysvalueof{/pgfplots/xmax}-\pgfkeysvalueof{/pgfplots/xmin}))/
                (\pgfkeysvalueof{/pgfplots/height}/(\pgfkeysvalueof{/pgfplots/ymax}-\pgfkeysvalueof{/pgfplots/ymin})))
        }
        \draw[draw=blue] (1,1) ellipse [x radius=0.25, y radius=0.5, rotate=\a];
    \end{axis}
    \begin{axis} [
        name=plot_right,
        at={(plot_left.north east)},
        anchor=north west,
        xshift=10mm,
        scale only axis,
        height=35mm,
        width=90mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \pgfmathsetmacro{\a}{
            atan(
                (\pgfkeysvalueof{/pgfplots/width}/(\pgfkeysvalueof{/pgfplots/xmax}-\pgfkeysvalueof{/pgfplots/xmin}))/
                (\pgfkeysvalueof{/pgfplots/height}/(\pgfkeysvalueof{/pgfplots/ymax}-\pgfkeysvalueof{/pgfplots/ymin})))
        }
        \draw[draw=blue] (1,1) ellipse [x radius=0.25, y radius=0.5, rotate=\a];
    \end{axis}
\end{tikzpicture}

\end{document}

Bildbeschreibung hier eingeben


Der beste Weg ist wahrscheinlich, die parametrische Funktion der Ellipse irgendwie zu berechnen und darzustellen. Das würde dann etwa so aussehen:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
    \begin{axis} [
        name=plot_left,
        scale only axis,
        height=35mm,
        width=15mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \addplot[domain=0:360, samples=200, blue](
            {cos(x)*sqrt(0.33/(sin(2*x)+2))+1},
            {sin(x)*sqrt(0.33/(sin(2*x)+2))+1}
        );
    \end{axis}
    \begin{axis} [
        name=plot_right,
        at={(plot_left.north east)},
        anchor=north west,
        xshift=10mm,
        scale only axis,
        height=35mm,
        width=90mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \addplot[domain=0:360, samples=200, blue](
            {cos(x)*sqrt(0.33/(sin(2*x)+2))+1},
            {sin(x)*sqrt(0.33/(sin(2*x)+2))+1}
        );
    \end{axis}
\end{tikzpicture}

\end{document}

Bildbeschreibung hier eingeben

Antwort2

Ich habe es dank Jasper Habichts Vorschlag herausgefunden, sowieDasBeitrag: Es stellt sich heraus, dass es wirklich nicht so kompliziert ist, wie ich dachte.

Mit dem folgenden Code können Sie also eine Ellipse in einer pgfplotsAchsenumgebung zeichnen, indem Sie die Mittelpunkte x und y sowie den Haupt- und Nebenwinkel und den Winkel bezüglich der x-Achse angeben.

MWE:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\newcommand{\addellipse}[5]{\addplot [domain=0:360, samples=50, draw=blue] ({(#3/2)*cos(x)*cos(#5) - (#4/2)*sin(x)*sin(#5) + #1}, {(#3/2)*cos(x)*sin(#5) + (#4/2)*sin(x)*cos(#5) + #2});}

\begin{document}

\begin{tikzpicture}
    \begin{axis} [
        name=plot_left,
        scale only axis,
        height=35mm,
        width=15mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \addellipse{1}{1}{1}{0.5}{45}
        );
    \end{axis}
    \begin{axis} [
        name=plot_right,
        at={(plot_left.north east)},
        anchor=north west,
        xshift=10mm,
        scale only axis,
        height=35mm,
        width=90mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \addellipse{1}{1}{1}{0.5}{45}
        );
    \end{axis}
\end{tikzpicture}

\end{document}

Ausgabe:

richtige_Skalierung

verwandte Informationen