我能够使用\draw
和在 tikz 中绘制抛物线parabola bend
\begin{tikzpicture}
\draw (-3,4) parabola bend (0,-.5) (3,4);
\end{tikzpicture}
但是我想画出这条抛物线,该抛物线与直线 y=x 呈镜像关系。我尝试输入一些看似合理的点:
\begin{tikzpicture}
\draw (4,-3) parabola bend (-.5,0) (4,3);
\end{tikzpicture}
但是,这会产生一条断线,很明显 tikz 不打算以这种方式输入。我能否以与\draw
获得第一条曲线类似的方式获得一条横向抛物线?
答案1
路径parabola
命令只能生成此类抛物线y=a*x+b
,但您仍然可以自由旋转、缩放、倾斜它或做其他任何操作。因此,如果您想镜像它,问题仍然存在:我们可以在 tikz 中镜像一部分吗?哦,是的,我们可以:
平均能量损失
\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}
答案2
可以考虑一个简单的解决方法:
\begin{tikzpicture}
\draw[rotate=-90] (-3,4) parabola bend (0,-.5) (3,4);
\end{tikzpicture}