![TikZ で等傾斜線上に傾斜を描く](https://rvso.com/image/399812/TikZ%20%E3%81%A7%E7%AD%89%E5%82%BE%E6%96%9C%E7%B7%9A%E4%B8%8A%E3%81%AB%E5%82%BE%E6%96%9C%E3%82%92%E6%8F%8F%E3%81%8F.png)
私は常微分方程式の等傾斜線を描く必要があります($y' = x^2 - y^2$
私の例では)。私は以下のコードを使用します。この質問(小さな変更を加えて) かなりうまく動作しますが、3 つの問題に遭遇しました。
- 変数 が定義されていないため、緑の等傾斜線 (コード内の関数
g5(x)
および)に傾斜を描くことができません。間隔 を「スキップ」することは可能ですか? 次のようなものを使用しようとしましたが、整数でのみ機能します。 も使用しようとしましたが、機能しませんでした。g6(x)
x
-1 < x < 1
\foreach
(0,1)
\ifnum \xmin+\i*\hx < -1 draw...
\ifnum
\breakforeach
- 斜面の中心を等傾斜線上に置くことは可能ですか?
(x0,y0)
を斜面の左端、を(x1,y1)
斜面の右端とします。 変換を行うと、各斜面の中心は対応する等傾斜線上になると思います。 しかし、斜面の右端にx0 -> x0 - abs(x0 - (x0+x1)/2), y0 -> y0 - abs(y0 - (y0+y1)/2)
がある場合、それを LaTeX コードでどのように記述すればよいかわかりません。atan2
- 左の緑の曲線には小さな隙間があります。右の緑の曲線にはそのような隙間はありません。
ムウェ
\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
回転によって、赤い曲線から緑の曲線が現れます。以下はさらに簡略化できますが、私の意見では、あなたの質問はあまり明確に書かれていません。キーを使用して、パスの中央に物を配置できます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}