TikZ의 등각선에 경사 그리기

TikZ의 등각선에 경사 그리기

ODE에 대한 등각선을 그려야 합니다( $y' = x^2 - y^2$예제에서는). 나는 다음의 코드를 사용합니다.이 질문(작은 변경 사항 포함) 꽤 잘 작동하지만 제가 발견한 세 가지 문제가 있습니다.

  1. 변수가 정의되지 않았기 때문에 녹색 등분사선(함수 g5(x)g6(x)코드) 에 경사를 그릴 수 없습니다 . 간격을 "건너뛰기" 할 수 있습니까 ? 나는 다음과 같은 것을 사용하려고 시도했지만 정수 에서만 작동합니다. 저도 사용해봤는데 안되더라구요.x-1 < x < 1\foreach(0,1)\ifnum \xmin+\i*\hx < -1 draw...\ifnum\breakforeach
  2. 등경선에 경사면의 중심을 두는 것이 가능합니까? (x0,y0)경사면의 왼쪽 끝이 되고 경사면 (x1,y1)의 오른쪽 끝이 됩니다. 번역을 하면 각 경사면의 중심이 해당 등위선 위에 있을 것 같습니다 x0 -> x0 - abs(x0 - (x0+x1)/2), y0 -> y0 - abs(y0 - (y0+y1)/2). 하지만 atan2경사면의 오른쪽 끝이 있을 때 LaTeX 코드로 작성하는 방법을 모르겠습니다 .
  3. 왼쪽 녹색 곡선에 작은 간격이 있습니다. 오른쪽 녹색 곡선에는 그러한 간격이 없습니다.

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}

등각선

답변1

녹색 곡선은 회전에 의해 빨간색 곡선에서 나타납니다. 다음은 더 단순화될 수 있지만 IMHO 귀하의 질문은 명확하게 작성되지 않았습니다. 열쇠를 사용하면 길 중앙에 물건을 놓을 수 있습니다 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}

여기에 이미지 설명을 입력하세요

답변2

@user121799님의 도움으로 제가 원하는 것을 얻었습니다. 등경선에 경사면의 중심을 배치하는 ({\xmin+\i*\hx},{g1(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15)것으로 변경하면 충분합니다 . ({atan2(0,1)}:-0.075) ++ ({\xmin+\i*\hx},{g1(\xmin+\i*\hx)}) -- ++ ({atan2(0,1)}:0.15)어쩌면 누군가에게 유용할 수도 있습니다.

여기에 이미지 설명을 입력하세요

\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}

관련 정보