TikZ에서 두 개의 포물선 경로를 연결하는 방법은 무엇입니까?

TikZ에서 두 개의 포물선 경로를 연결하는 방법은 무엇입니까?

하나는 수평이고 다른 하나는 수직인 두 개의 포물선 경로로 구성된 간단한 곡선을 그리려고 합니다. 지금까지는 을 사용하도록 설정되어 있지만 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}

포함된 출력에서 ​​명백한 문제는 두 경로가 "연관되지 않은" 것처럼 보이는 것입니다. 연속 경로처럼 보이도록 하는 방법이 있나요?

답변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

Zarko의 방식이 가장 정확하다는 것은 확실합니다.하지만, 때로는 경로를 통합하는 것이 약간 까다로울 수 있습니다 ...

그렇다면 길을 만드는 까다로운 방법이 있습니다.바라보다결합되어 있지만 실제로는 별개의 경로입니다. 이를 위해 line cap원래 설정된 키를 사용할 수 있습니다 butt. 수직 접합에서는 line cap=rect경로가 날카롭게 연결된 것처럼 보이도록 하거나 모든 경우에 line cap=round경로가 둥글게 연결된 것처럼 보이게 만드는 기능을 사용할 수 있습니다 .*

여기의 경우는 수직 조인이므로 를 사용할 수 있지만 항상 작동하지만 항상 그런 것은 아님 rect을 보여주기 위해 MWE에 더 많은 그림을 추가했습니다 . 또한 왼쪽 상단에는 세 가지 라인 캡의 예가 모두 표시되어 차이점을 확인할 수 있습니다.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}

*물론 이것은 동일한 너비의 선에만 유효합니다. 선의 너비가 다른 경우 이 방법으로는 제대로 연결되지 않습니다.

관련 정보