11

I am trying to draw a simple curve that consists of two parabolic paths, one horizontal, the other vertical. So far, I am set on using parabola, but I can be swayed from doing so. Below is my current code:

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

The issue, evident in the included output, is how the two paths look "disjointed." Is there a way to make them look like a continuous path?

14

Two separate lines canot be joined. You need to draw both parabolas in single path. Try:

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

enter image description here

  • 1
    +1. Another simple solution, is to pass line cap=round, assuming rounded line joins are not an issue. – Guilherme Zanotelli Nov 16 '16 at 7:00
  • @GuilhermeZ.Santos, nice idea, howeve with your solution the "disjoin" is only less visible, but still present. – Zarko Nov 16 '16 at 7:13
  • I know. But the OP has asked, and I quote, "to make them look like a continous path". ;D – Guilherme Zanotelli Nov 16 '16 at 7:26
  • 1
    @GuilhermeZ.Santos, you have right! Make answer with this solution :) – Zarko Nov 16 '16 at 7:28
12

Zarko's way is the most correct one, that's for sure. But, sometimes uniting the paths may be a ltttle tricky...

Then, there's a tricky way to make the paths look united, when in fact they are separate paths. To do this, one can use line cap key which is originally set to butt. In perpendicular joints is possible to use line cap=rect which will make the paths look like they're sharply joined, or for all cases line cap=round will make the paths look like they were roundly joined.*

Since the case here is a perpendicular join, it's possible to use rect, but I've added more drawings to the MWE, just to show how line cap=round always works but rect not always. Also on the top left corner there's examples of all three line caps so that the difference is appreciated.

enter image description here

The full 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}

*Of course this is only valid for lines of the same width, if the lines have different widths they wont be joined properly with this method...

  • Thanks for your answer. It's very instructive. I marked Marko's answer as the correct one, but I'm also grateful for yours. – Minh Nov 16 '16 at 8:04
  • No worries there, you did the right thing. If you had marked this one I'd have suggested otherwise. I added this as it may be helpful to someone else. And you are very welcome! :D – Guilherme Zanotelli Nov 16 '16 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.