我可以透過使用\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}