![从中心点绘制直线和曲线](https://linux22.com/image/380729/%E4%BB%8E%E4%B8%AD%E5%BF%83%E7%82%B9%E7%BB%98%E5%88%B6%E7%9B%B4%E7%BA%BF%E5%92%8C%E6%9B%B2%E7%BA%BF.png)
我使用以下代码从它们的中心点绘制线条,以方便它们彼此之间的定位。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (3,0);
\draw [thick,-latex](0,0) -- (0,4);
\draw [thick, green] (1.8,1.4) node [circle, draw, black, fill=black, scale=0.2]{} +(-50:1.4cm) -- +(130:1.4cm);
\draw [thick, orange] (1.4,1.4) node [circle, draw, black, fill=black, scale=0.2]{} +(50:1.4cm) -- +(-130:1.4cm);
\end{tikzpicture}
\end{frame}
\end{document}
使用以下代码,是否有办法从中间点绘制曲线。
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (4,0);
\draw [thick,-latex](0,0) -- (0,4);
\draw [thick, green] (.88,3.5) to [out=-90,in=180] node [pos=.5,circle, draw, red, fill=red, scale=0.2]{} +(-46.:4.cm);
\draw [thick, blue] (.74,.2) to [out=90,in=-90] node [pos=.5,circle, draw, red, fill=red, scale=0.2]{} +(60:3.8cm);
\end{tikzpicture}
答案1
这当然不是一个完整的解决方案。我之所以没有提出完全自动化的解决方案,是因为在给定点上我能想到的所有建议都利用了transform canvas
。举个例子,我们可以想象的一件事是保存路径,看看它偏离了多少,然后用这些好技巧。但是,我只能使用变换画布移动重复使用的路径。虽然这在视觉上看起来没问题,但最终这仍然是有问题的,因为您无法将移动的路径用于交叉点。
出于所有这些原因,我想说,从长远来看,这种非自动化解决方案可能更好。它带有一种风格
determine the necessary shift to=<target>
输入您想要的曲线中心。如果您已经位于中心,代码将保持沉默,否则它将告诉您需要添加哪个,xshift
以yshift
使中心位于所需的坐标。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usetikzlibrary{decorations.markings,calc}
\tikzset{determine the necessary shift to/.style={save path=\tmpPath,
preaction={decorate,decoration={markings,
mark=at position 0.5 with {\coordinate (aux);
\pgftransformreset
\path let \p1=($#1-(aux)$),\n1={veclen(\x1,\y1)} in \pgfextra{
\pgfmathtruncatemacro{\nTest}{\n1}
\ifnum\nTest=0
\else
\typeout{Please\space add\space xshift=\x1,yshift=\y1\space to your path}
\fi};
};}}}}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (3,0);
\draw [thick,-latex](0,0) -- (0,4);
\draw [thick, green] (1.8,1.4) node [circle, draw, black, fill=black, scale=0.2]{} +(-50:1.4cm) -- +(130:1.4cm);
\draw [thick, orange] (1.4,1.4) node [circle, draw, black, fill=black, scale=0.2]{} +(50:1.4cm) -- +(-130:1.4cm);
\end{tikzpicture}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (4,0);
\draw [thick,-latex](0,0) -- (0,4);
\draw [determine the necessary shift to={(1.8,1.4)},green,thick,xshift=8.24234pt,yshift=1.83932pt] (.88,3.5) to [out=-90,in=180] +(-46.:4.cm);
\draw [determine the necessary shift to={(1.8,1.4)},thick, blue,xshift=7.93524pt,yshift=-7.4265pt] (.74,.2) to [out=90,in=-90] +(60:3.8cm);
\end{tikzpicture}
\end{frame}
\end{document}