TikZ で 2 つの放物線パスを接続するにはどうすればよいでしょうか?

TikZ で 2 つの放物線パスを接続するにはどうすればよいでしょうか?

水平方向と垂直方向の 2 つの放物線から成る単純な曲線を描画しようとしています。 今のところ、 を使用するつもりですparabolaが、そうしないのもやむを得ません。以下は現在のコードです。

\documentclass[12pt, tikz, border=0mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{calc,intersections,through}
\tikzset{every label/.style = {label distance=2pt, inner sep=0pt}}
\tikzset{every node/.style={font=\footnotesize}}
\tikzset{> = {Stealth[width=4pt, length=5pt, inset=1pt]}}

\begin{document}

\newlength{\unit}
\setlength{\unit}{0.5cm}
\begin{tikzpicture}[x=\unit, y=\unit, line width=2pt]
  % Begin axes
  \begin{scope}[line width=0.5pt]
    \draw[->] (-3.5,0) -- (5.5,0);
    \draw[->] (0,-0.5) -- (0,5.5);
    \foreach \x in {-3, -2, -1, 1, 2, 3, 4, 5}
    \draw (\x,2pt) -- (\x,-2pt) node [anchor=base, shift={(0,-8pt)}, inner sep=1pt] {$\x$};
    \foreach \y in {1, ..., 5}
    \draw (2pt,\y) -- (-2pt,\y) node [anchor=east, inner sep=1pt] {$\y$};
  \end{scope}
  % End axes
  \draw [rotate around={-90:(3,5)}](3,5) parabola (5.5,-1);
  \draw (3,5) parabola (5,0);
\end{tikzpicture}      
\end{document}

含まれている出力で明らかな問題は、2 つのパスが「分離」しているように見えることです。これらを連続したパスのように見せる方法はありますか?

答え1

2 本の別々の線を結合することはできません。両方の放物線を 1 つのパスに描画する必要があります。次を試してください:

\documentclass[12pt, tikz, border=0mm]{standalone}
\usetikzlibrary{arrows.meta, % <-- only this is needed 
                calc, intersections, through}

\newlength{\unit}
\tikzset{every label/.style = {label distance=2pt, inner sep=0pt},
         every node/.style={font=\footnotesize},
         > = {Stealth[width=4pt, length=5pt, inset=1pt]}
         }

\begin{document} 
\setlength{\unit}{0.5cm}
\begin{tikzpicture}[x=\unit, y=\unit, line width=2pt]
  % Begin axes
  \begin{scope}[line width=0.5pt]
    \draw[->] (-3.5,0) -- (5.5,0);
    \draw[->] (0,-0.1) -- (0,5.5);
    \foreach \x in {-3, -2,...,5}
        \draw (\x,2pt) -- ++ (0,-4pt) node[below] {$\x$};
    \foreach \y in {1,...,5}
        \draw (2pt,\y) -- ++ (-4pt,0) node[left] {$\y$};    
  \end{scope}% End axes
  % the first parabola start at (5,0) and end at (3,5) 
  % wherends start the second, rotated one
  % for this the bend of the first parabola is moved to the end of path
  \draw (5,0) parabola[bend at end] (3,5) {[rotate around={-90:(3,5)}] parabola (5.5,-1)} ;
    \end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

答え2

ザルコのやり方が最も正しいのは確かだ。しかし場合によっては、パスを結合するのが少し難しい場合があります...

そして、パスを作るにはちょっとコツがいる見て実際には別々のパスであるにもかかわらず、結合されているように見えます。これを行うには、line capに設定されているキーを使用できますbutt。垂直ジョイントでは を使用でき、line cap=rectこれによりパスが鋭く結合されているように見えますline cap=round。または、すべてのケースで を使用すると、パスが丸く結合されているように見えます。*

この場合は垂直結合なので、 を使用できますが、が常に機能するが常に機能するとは限らないrectことを示すために、MWE にさらに図を追加しました。また、左上隅には、違いがわかるように、3 つのライン キャップすべての例があります。line cap=roundrect

ここに画像の説明を入力してください

完全な MWE:

\documentclass[12pt, tikz, border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{calc,intersections,through}
\tikzset{every label/.style = {label distance=2pt, inner sep=0pt}}
\tikzset{every node/.style={font=\footnotesize}}
\tikzset{> = {Stealth[width=4pt, length=5pt, inset=1pt]}}

\begin{document}

\newlength{\unit}
\setlength{\unit}{0.5cm}
\begin{tikzpicture}[x=\unit, y=\unit, line width=2pt]
  % Begin axes
  \begin{scope}[line width=0.5pt]
    \draw[->] (-3.5,0) -- (5.5,0);
    \draw[->] (0,-0.5) -- (0,5.5);
    \foreach \x in {-3, -2, -1, 1, 2, 3, 4, 5}
    \draw (\x,2pt) -- (\x,-2pt) node [anchor=base, shift={(0,-8pt)}, inner sep=1pt] {$\x$};
    \foreach \y in {1, ..., 5}
    \draw (2pt,\y) -- (-2pt,\y) node [anchor=east, inner sep=1pt] {$\y$};
  \end{scope}
  % End axes
  \draw[line cap=rect] [rotate around={-90:(3,5)}](3,5) parabola (5.5,-1);
  \draw (3,5) parabola (5,0);
  %%MWE ends here -- the rest is for demonstration purposes only
  \draw (1,0) -- (1,1);\draw[line cap=round] (1,1) -- +(135:1);
  \draw (2,0) -- (2,1);\draw[line cap=rect] (2,1) -- +(135:1);
  \draw (-3,5) -- +(1,0);\draw[ultra thin, white] (-3,5) -- +(1,0) node[font={\tiny\ttfamily},right,black]{butt};
  \draw[line cap=round] (-3,4.5) -- +(1,0); \draw[ultra thin, white] (-3,4.5) -- +(1,0) node[font={\tiny\ttfamily},right,black]{round};
  \draw[line cap=rect] (-3,4) -- +(1,0);\draw[ultra thin, white] (-3,4) -- +(1,0) node[font={\tiny\ttfamily},right,black]{rect};
\end{tikzpicture}      
\end{document}

*もちろん、これは同じ幅の線にのみ有効です。線の幅が異なる場合は、この方法では適切に結合されません...

関連情報