我有一个 pgfshape 声明为
\pgfdeclareshape{Curve1}{
\inheritsavedanchors[from=coordinate]
\inheritanchor[from=coordinate]{center}
\backgroundpath{
\begin{pgfscope}
\pgftransformshift{\centerpoint}
\pgfmathdivide{\pgfkeysvalueof{/pgf/minimum width}}{1pt}
\pgftransformscale{\pgfmathresult}
\pgfpathmoveto{\pgfpoint{ 0}{ 0}}
[...]
\pgfpathlineto{\pgfpoint{-1.637140473757006e-01}{9.752876882003444e-01}}
[...]
\pgfpathlineto{\pgfpoint{ 0}{ 0}}
\pgfpathclose
\end{pgfscope}}}
其中 [...] 是省略号,表示我为了简洁而省略的几点。
然而,当我用
\node [Curve1, draw, scale = 10] at (0, 0) {};
10 * (-1.637140473757006e-01, 9.752876882003444e-01)
最终的地点与我期望的没有任何关系:
梅威瑟:
\documentclass[english]{scrbook}
\usepackage{tikz}
\pgfdeclareshape{Curve1}{
\inheritsavedanchors[from=coordinate]
\inheritanchor[from=coordinate]{center}
\backgroundpath{
\begin{pgfscope}
\pgftransformshift{\centerpoint}
\pgfmathdivide{\pgfkeysvalueof{/pgf/minimum width}}{1pt}
\pgftransformscale{\pgfmathresult}
\pgfpathmoveto{\pgfpoint{ 0}{ 0}}
\pgfpathlineto{\pgfpoint{-1.637140473757006e-01}{9.752876882003444e-01}}
\pgfpathlineto{\pgfpoint{ 0}{ 0}}
\pgfpathclose
\end{pgfscope}}}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (-2,0) grid (1,10);
\node [Curve1, draw, scale = 10, thick] at (0, 0) {};
\fill (-1.637140473757006, 9.752876882003444) circle[radius=2pt];
\end{tikzpicture}
\end{figure}
\end{document}
形状声明中给出的坐标、比例和最终图片中的坐标之间有什么关系? 有没有我可以在某些地方使用的公式?
答案1
您需要记住,如果您不提供单位,则命令会\pgfpoint
添加单位。我添加了一个红色圆圈来表明您的方法在原则上是可行的。pt
\documentclass[english]{scrbook}
\usepackage{tikz}
\pgfdeclareshape{Curve1}{
\inheritsavedanchors[from=coordinate]
\inheritanchor[from=coordinate]{center}
\backgroundpath{
\begin{pgfscope}
\pgftransformshift{\centerpoint}
\pgfmathdivide{\pgfkeysvalueof{/pgf/minimum width}}{1pt}
\pgftransformscale{\pgfmathresult}
\pgfpathmoveto{\pgfpoint{ 0}{ 0}}
\pgfpathlineto{\pgfpoint{-1.637140473757006e-01}{9.752876882003444e-01}}
\pgfpathlineto{\pgfpoint{ 0}{ 0}}
\pgfpathclose
\end{pgfscope}}}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (-2,0) grid (1,10);
\node [Curve1, draw, scale = 10, thick] at (0, 0) {};
\fill (-1.637140473757006, 9.752876882003444) circle[radius=2pt];
\fill[red] (-1.637140473757006pt, 9.752876882003444pt) circle[radius=1pt];
\end{tikzpicture}
\end{figure}
\end{document}
您可以cm
在形状声明中使用。
\documentclass[english]{scrbook}
\usepackage{tikz}
\pgfdeclareshape{Curve1}{
\inheritsavedanchors[from=coordinate]
\inheritanchor[from=coordinate]{center}
\backgroundpath{
\begin{pgfscope}
\pgftransformshift{\centerpoint}
\pgfmathdivide{\pgfkeysvalueof{/pgf/minimum width}}{1pt}
\pgftransformscale{\pgfmathresult}
\pgfpathmoveto{\pgfpoint{ 0}{ 0}}
\pgfpathlineto{\pgfpoint{-1.637140473757006e-01*1cm}{9.752876882003444e-01*1cm}}
\pgfpathlineto{\pgfpoint{ 0}{ 0}}
\pgfpathclose
\end{pgfscope}}}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (-2,0) grid (1,10);
\node [Curve1, draw, scale = 10, thick] at (0, 0) {};
\fill (-1.637140473757006, 9.752876882003444) circle[radius=2pt];
\end{tikzpicture}
\end{figure}
\end{document}