Zeichnen von Neigungen auf Isoklinen in TikZ

Zeichnen von Neigungen auf Isoklinen in TikZ

Ich muss Isoklinen für eine ODE zeichnen ( $y' = x^2 - y^2$in meinem Beispiel). Ich verwende den Code vondiese Frage(mit kleinen Änderungen) und es funktioniert ziemlich gut, aber ich bin auf drei Probleme gestoßen.

  1. Ich kann keine Steigungen auf den grünen Isoklinen zeichnen (Funktionen g5(x)und g6(x)im Code), da xdie Variable nicht definiert ist, wenn . Ist es möglich , ein Intervall -1 < x < 1zu „überspringen“ ? Ich habe versucht, so etwas zu verwenden: funktioniert aber nur mit ganzen Zahlen. Ich habe auch versucht, zu verwenden, aber es hat nicht funktioniert.\foreach(0,1)\ifnum \xmin+\i*\hx < -1 draw...\ifnum\breakforeach
  2. Ist es möglich, die Mittelpunkte der Hänge auf Isoklinen zu legen? Lassen Sie (x0,y0)das linke Ende des Hangs und (x1,y1)das rechte Ende des Hangs sein. Ich vermute, dass der Mittelpunkt jedes Hangs auf der entsprechenden Isoklinen liegen würde, wenn ich eine Übersetzung vornehme x0 -> x0 - abs(x0 - (x0+x1)/2), y0 -> y0 - abs(y0 - (y0+y1)/2). Aber ich weiß nicht, wie ich das in LaTeX-Code schreiben soll, wenn es atan2das rechte Ende des Hangs gibt.
  3. Auf der linken grünen Kurve befindet sich eine kleine Lücke. Auf der rechten grünen Kurve gibt es keine solche Lücke.

MWE

\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
[declare function=
{f(\x,\y)=\x*\x-\y*\y;
g1(\x)=\x;
g2(\x)=-\x;
g3(\x)=sqrt(\x*\x+1);
g4(\x)=-sqrt(\x*\x+1);
g5(\x)=sqrt((\x*\x)-1);
g6(\x)=-sqrt((\x*\x)-1);
},
scale=2.5]


\def\xmax{2.0} \def\xmin{-2.0}
\def\ymax{2.0} \def\ymin{-2.0}
\def\nx{15}  \def\ny{15}

\draw[red] plot[domain=\xmin-0.1:\xmax+0.1] (\x,{g1(\x)});
\draw[red] plot[domain=\xmin-0.1:\xmax+0.1] (\x,{g2(\x)});
\draw[red] plot[samples=100, smooth,domain=\xmin-0.1:\xmax+0.1] (\x,{g3(\x)});
\draw[red] plot[samples=100, smooth,domain=\xmin-0.1:\xmax+0.1] (\x,{g4(\x)});
\draw[green] plot[samples=1000, smooth,domain=\xmin-0.1:-1.0] (\x,{g5(\x)});
\draw[green] plot[samples=100, smooth,domain=1:\xmax+0.1]  (\x,{g5(\x)});
\draw[green] plot[samples=1000, smooth,domain=\xmin-0.1:-1.0] (\x,{g6(\x)});
\draw[green] plot[samples=100, smooth,domain=1:\xmax+0.1]  (\x,{g6(\x)});

\pgfmathsetmacro{\hx}{(\xmax-\xmin)/\nx}
\pgfmathsetmacro{\hy}{(\ymax-\ymin)/\ny}
\foreach \i in {0,...,\nx}
\foreach \j in {0,...,\ny}{
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g1(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15);
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g2(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15);
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g3(\xmin+\i*\hx)}) -- ++ ({atan2(-1,1)}:0.15);
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g4(\xmin+\i*\hx)}) -- ++ ({atan2(-1,1)}:0.15);
}

\draw[-latex] (\xmin-.1,0)--(\xmax+.1,0) node[below right] {$x$};
\draw[-latex] (0,\ymin-.1)--(0,\ymax+.1) node[above left] {$y$};
\end{tikzpicture}
\end{document}

Isoklinen

Antwort1

Die grünen Kurven entstehen durch Rotation aus den roten. Das Folgende kann weiter vereinfacht werden, aber meiner Meinung nach ist Ihre Frage nicht sehr klar formuliert. Mit dem Schlüssel können Dinge in die Mitte eines Pfads gelegt werden midway.

\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
[declare function=
{f(\x,\y)=\x*\x-\y*\y;
g1(\x)=\x;
g2(\x)=-\x;
g3(\x)=sqrt(\x*\x+1);
g4(\x)=-sqrt(\x*\x+1);
},
scale=2.5]


\def\xmax{2.0} \def\xmin{-2.0}
\def\ymax{2.0} \def\ymin{-2.0}
\def\nx{15}  \def\ny{15}
\begin{scope}[red]
\draw plot[domain=\xmin-0.1:\xmax+0.1] (\x,{g1(\x)});
\draw plot[domain=\xmin-0.1:\xmax+0.1] (\x,{g2(\x)});
\draw plot[samples=100, smooth,domain=\xmin-0.1:\xmax+0.1] (\x,{g3(\x)});
\draw plot[samples=100, smooth,domain=\xmin-0.1:\xmax+0.1] (\x,{g4(\x)});
\end{scope}
\begin{scope}[green,rotate=90]
\draw plot[samples=100, smooth,domain=\xmin-0.1:\xmax+0.1] (\x,{g3(\x)});
\draw plot[samples=100, smooth,domain=\xmin-0.1:\xmax+0.1] (\x,{g4(\x)});
\end{scope}

\pgfmathsetmacro{\hx}{(\xmax-\xmin)/\nx}
\pgfmathsetmacro{\hy}{(\ymax-\ymin)/\ny}
\foreach \i in {0,...,\nx}
\foreach \j in {0,...,\ny}{
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g1(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15)
    node[midway,sloped]{$\times$};
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g2(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15)
    node[midway,sloped]{$\times$};
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g3(\xmin+\i*\hx)}) -- ++ ({atan2(-1,1)}:0.15)
    node[midway,sloped]{$\times$};
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g4(\xmin+\i*\hx)}) -- ++ ({atan2(-1,1)}:0.15)
    node[midway,sloped]{$\times$};
}
\begin{scope}[rotate=90]
\foreach \i in {0,...,\nx}
\foreach \j in {0,...,\ny}{
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g1(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15)
    node[midway,sloped]{$\times$};
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g2(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15)
    node[midway,sloped]{$\times$};
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g3(\xmin+\i*\hx)}) -- ++ ({atan2(-1,1)}:0.15)
    node[midway,sloped]{$\times$};
    \draw[blue,-] 
    ({\xmin+\i*\hx},{g4(\xmin+\i*\hx)}) -- ++ ({atan2(-1,1)}:0.15)
    node[midway,sloped]{$\times$};
}
\end{scope}
\draw[-latex] (\xmin-.1,0)--(\xmax+.1,0) node[below right] {$x$};
\draw[-latex] (0,\ymin-.1)--(0,\ymax+.1) node[above left] {$y$};
\end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

Antwort2

Mit der Hilfe von @user121799 habe ich bekommen, was ich wollte. Es reicht, ({\xmin+\i*\hx},{g1(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15)mit zu ändern ({atan2(0,1)}:-0.075) ++ ({\xmin+\i*\hx},{g1(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15), um die Mittelpunkte der Hänge auf den Isoklinen zu platzieren. Vielleicht ist es für jemanden nützlich.

Bildbeschreibung hier eingeben

\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
    \begin{tikzpicture}
    [declare function=
    {f(\x,\y)=\x*\x-\y*\y;
        g1(\x)=\x;
        g2(\x)=-\x;
        g3(\x)=sqrt(\x*\x+1);
        g4(\x)=-sqrt(\x*\x+1);
    },
    scale=2.5]


    \def\xmax{2.0} \def\xmin{-2.0}
    \def\ymax{2.0} \def\ymin{-2.0}
    \def\nx{15}  \def\ny{15}
    \begin{scope}[red]
    \draw plot[domain=\xmin-0.3:\xmax+0.3] (\x,{g1(\x)});
    \draw plot[domain=\xmin-0.3:\xmax+0.3] (\x,{g2(\x)});
    \draw plot[samples=100, smooth,domain=\xmin-0.1:\xmax+0.1] (\x,{g3(\x)});
    \draw plot[samples=100, smooth,domain=\xmin-0.1:\xmax+0.1] (\x,{g4(\x)});
    \end{scope}
    \begin{scope}[red,rotate=90]
    \draw plot[samples=100, smooth,domain=\xmin-0.1:\xmax+0.1] (\x,{g3(\x)});
    \draw plot[samples=100, smooth,domain=\xmin-0.1:\xmax+0.1] (\x,{g4(\x)});
    \end{scope}

    \pgfmathsetmacro{\hx}{(\xmax-\xmin)/\nx}
    \pgfmathsetmacro{\hy}{(\ymax-\ymin)/\ny}
    \foreach \i in {0,...,\nx}
    \foreach \j in {0,...,\ny}{
        \draw[blue,-] 
        ({atan2(0,1)}:-0.075) ++ ({\xmin+\i*\hx},{g1(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15);
        \draw[blue,-] 
        ({atan2(0,1)}:-0.075) ++ ({\xmin+\i*\hx},{g2(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15);
        \draw[blue,-] 
        ({atan2(-1,1)}:-0.075) ++ ({\xmin+\i*\hx},{g3(\xmin+\i*\hx)}) -- ++ ({atan2(-1,1)}:0.15);
        \draw[blue,-] 
        ({atan2(-1,1)}:-0.075) ++ ({\xmin+\i*\hx},{g4(\xmin+\i*\hx)}) -- ++ ({atan2(-1,1)}:0.15);
    }
    \begin{scope}[rotate=90]
    \foreach \i in {0,...,\nx}
    \foreach \j in {0,...,\ny}{
        \draw[blue,-] 
        ({atan2(-1,1)}:-0.075) ++ ({\xmin+\i*\hx},{g3(\xmin+\i*\hx)}) -- ++ ({atan2(-1,1)}:0.15);
        \draw[blue,-] 
        ({atan2(-1,1)}:-0.075) ++ ({\xmin+\i*\hx},{g4(\xmin+\i*\hx)}) -- ++ ({atan2(-1,1)}:0.15);
    }
    \end{scope}


    \draw[-latex] (\xmin-.1,0)--(\xmax+.1,0) node[below right] {$x$};
    \draw[-latex] (0,\ymin-.1)--(0,\ymax+.1) node[above left] {$y$};
    \end{tikzpicture}
\end{document}

verwandte Informationen