1

I am able to draw parabolic curves in tikz by using \draw and parabola bend

\begin{tikzpicture}
        \draw (-3,4) parabola bend (0,-.5) (3,4);
\end{tikzpicture}

However I would like to draw this parabola mirrored over the line y=x. I attempted to input what seemed like sensible points:

\begin{tikzpicture}
        \draw (4,-3) parabola bend (-.5,0) (4,3);
\end{tikzpicture}

However this creates a broken curve and it is quite clear that tikz is not intended to take input in this way. Is there someway I could get a sideways parabolic curve using \draw in a similar fashion to how I obtained the first curve?

2 Answers 2

2

The parabola path command makes only parabolas of the kind y=a*x+b, still you're free to rotate, scale, slant it or whatever. So you want to mirrow it, the question remains: Can we mirror a part in tikz? Oh yes we can:

enter image description here

MWE

\documentclass{standalone}
\usepackage{tikz}

% Code from user Qrrbrbirlbel (https://tex.stackexchange.com/a/142491/81905)
\usetikzlibrary{backgrounds}
\makeatletter
\tikzset{
    mirror/.code={\pgfutil@in@{--}{#1}\ifpgfutil@in@\tikz@trans@mirror#1\@nil
        \else\tikz@scan@one@point\pgftransformmirror#1\relax\fi},
    ymirror/.code={\pgfutil@ifnextchar(\tikz@trans@ymirror@coordinate\tikz@trans@ymirror@simple#1\@nil},
    xmirror/.code={\pgfutil@ifnextchar(\tikz@trans@xmirror@coordinate\tikz@trans@xmirror@simple#1\@nil}}
\def\tikz@trans@mirror#1--#2\@nil{%
    \pgfextract@process\pgf@trans@mirror@A{\tikz@scan@one@point\pgfutil@firstofone#1}%
    \pgfextract@process\pgf@trans@mirror@B{\tikz@scan@one@point\pgfutil@firstofone#2}%
    \pgftransformMirror{\pgf@trans@mirror@A}{\pgf@trans@mirror@B}}
\def\pgftransformxmirror#1{\pgfmathparse{2*(#1)}\pgftransformcm{-1}{0}{0}{1}{\pgfqpoint{+\pgfmathresult pt}{+0pt}}}
\def\pgftransformymirror#1{\pgfmathparse{2*(#1)}\pgftransformcm{1}{0}{0}{-1}{\pgfqpoint{+0pt}{+\pgfmathresult pt}}}
\def\tikz@trans@ymirror@simple#1\@nil{
    \pgfmathparse{#1}\let\tikz@temp\pgfmathresult
    \ifpgfmathunitsdeclared
    \pgftransformymirror{\tikz@temp pt}%
    \else
    \pgf@process{\pgfpointxy{0}{\tikz@temp}}%
    \pgftransformymirror{+\the\pgf@y}%
    \fi}
\def\tikz@trans@xmirror@simple#1\@nil{
    \pgfmathparse{#1}\let\tikz@temp\pgfmathresult
    \ifpgfmathunitsdeclared
    \pgftransformxmirror{\tikz@temp pt}%
    \else
    \pgf@process{\pgfpointxy{\tikz@temp}{0}}%
    \pgftransformxmirror{+\the\pgf@x}%
    \fi}
\def\tikz@trans@xmirror@coordinate#1\@nil{\tikz@scan@one@point\pgfutil@firstofone#1\pgftransformxmirror{+\the\pgf@x}}
\def\tikz@trans@ymirror@coordinate#1\@nil{\tikz@scan@one@point\pgfutil@firstofone#1\pgftransformymirror{+\the\pgf@y}}
\def\pgftransformmirror#1{%
    \pgfpointnormalised{#1}%
    \pgf@xa=\pgf@sys@tonumber\pgf@y\pgf@x
    \pgf@xb=\pgf@sys@tonumber\pgf@x\pgf@x
    \pgf@yb=\pgf@sys@tonumber\pgf@y\pgf@y
    \multiply\pgf@xa2\relax
    \pgf@xc=-\pgf@yb\advance\pgf@xc\pgf@xb
    \pgf@yc=-\pgf@xb\advance\pgf@yc\pgf@yb
    \edef\pgf@temp{{\the\pgf@xc}{+\the\pgf@xa}{+\the\pgf@xa}{+\the\pgf@yc}}%
    \expandafter\pgf@transformcm\pgf@temp{\pgfpointorigin}}
\def\pgftransformMirror#1#2{%
    \pgfextract@process\pgf@trans@mirror@A{#1}%
    \pgfextract@process\pgf@trans@mirror@B{#2}%
    \pgfextract@process\pgf@trans@mirror@g{\pgfpointdiff{\pgf@trans@mirror@A}{\pgf@trans@mirror@B}}%
    \pgftransformshift{\pgf@trans@mirror@A}%
    \pgftransformmirror{\pgf@trans@mirror@g}%
    \pgftransformshift{\pgfpointscale{-1}{\pgf@trans@mirror@A}}}
\makeatother
%End of code from Qrrbrbirlbel

\begin{document}
\begin{tikzpicture}
\draw (-3,4) parabola bend (0,-.5) (3,4);
\draw[thick, <->] (-3,0) -- (3,0);
\draw[thick, <->] (0,-3) -- (0,4);
\coordinate (1) at (-3,-3);
\coordinate (2) at (3,3);
\draw[dashed,very thin] (1)--(2);
\draw[mirror=(1)--(2),red] (-3,4) parabola bend (0,-.5) (3,4);
\end{tikzpicture}
\end{document}
3
  • Thank you for the answer. I unfortunately was unable to get Qrrbrbirlbel's code to work for me and ended up just switching my axes. Jan 31, 2017 at 7:04
  • That's also another nice possibility, you should add that as an answer. Would mind elaborating on why the code did not work? Was there an error? Did the above MWE raised any issues? Jan 31, 2017 at 8:16
  • I don't think I will add an answer because the solution I was using would not be the solution I would have wanted when I asked the question. I literally just switched the labels on my axes so that the graph was technically the correct one. I did end up getting your solution to work just fine in the end, so thanks! Feb 1, 2017 at 3:09
1

A simple fix to consider:

\begin{tikzpicture}
        \draw[rotate=-90] (-3,4) parabola bend (0,-.5) (3,4);
\end{tikzpicture}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .