\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}
\begin{document}
\multido{\i=0+30}{12}{%
\begin{pspicture}(-2,-2)(2,2)
\pscircle{1}
\pnode(1;\i){R}
\psset{arrows=->}
\psline(R)
\psline[linecolor=blue](R|0,0)
\psline[linecolor=red](0,0|R)
\psset{linecolor=gray,linestyle=dashed,linewidth=0.5\pslinewidth,arrows=-,dash=2pt 2pt}
\psline(R)(R|0,0)
\psline(R)(0,0|R)
\end{pspicture}}
\end{document}
带有箭头的零长度线有意义吗?这是错误吗?我希望这是错误。如果不是错误,那么在 TeX 或 PS 级别使用条件宏处理这种情况的最佳方法是什么?
显然,TikZ 也采用了这个特性。
\documentclass[tikz,border=0pt]{standalone}
\usepackage{tikz}
\begin{document}
\tikzpicture
\fill[yellow] (-1,-1) -- (-1,1) -- (1,1) -- (1,-1) -- cycle;
\draw[->] (0,0)--(0,0);
\endtikzpicture
\end{document}
答案1
来自pstricks.tex
http://archiv.dante.de/~herbert/texnik/tex/generic/pstricks/ \psLine
只能有一或者二坐标对。稍后将在 CTAN 上介绍。
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node,multido}
\begin{document}
\multido{\i=0+30}{12}{%
\begin{pspicture}(-2,-2)(2,2)
\pscircle{1}
\pnode(1;\i){R}
\psset{arrows=->}
\psLine(R)
\psLine[linecolor=blue](R|0,0)
\psLine[linecolor=red](0,0|R)
\psset{linecolor=gray,linestyle=dashed,linewidth=0.5\pslinewidth,arrows=-,dash=2pt 2pt}
\psLine(R)(R|0,0)
\psLine(R)(0,0|R)
\end{pspicture}}
\end{document}
答案2
在 TikZ 中,如果路径的最后一段长度为零,则可以通过修补内部\pgf@check@for@arrows
宏来避免绘制箭头:
\makeatletter
\def\pgf@check@for@arrows{%
\pgf@drawarrowsfalse%
\ifx\pgf@startarrow\pgfutil@empty\else\pgf@drawarrowstrue\fi%
\ifx\pgf@endarrow\pgfutil@empty\else\pgf@drawarrowstrue\fi%
\ifdim\pgf@shorten@end@additional=0pt\relax\else\pgf@drawarrowstrue\fi%
\ifdim\pgf@shorten@start@additional=0pt\relax\else\pgf@drawarrowstrue\fi%
\ifpgf@drawarrows%
\pgfsyssoftpath@getcurrentpath\pgf@arrowpath%
\ifx\pgf@arrowpath\pgfutil@empty%
\pgf@drawarrowsfalse%
\else%
\pgfprocesscheckclosed{\pgf@arrowpath}{\pgf@drawarrowsfalse}%
%%% New stuff starts here
% Extract first, second, second last and last points
\pgfprocesspathextractpoints{\pgf@arrowpath}%
% If the second last and last points are identical ...
\ifx\pgfpointsecondlastonpath\pgfpointlastonpath%
% ... disable the arrow head
\pgf@drawarrowsfalse%
\fi%
%%% New stuff ends here
\fi%
\fi%
}
\makeatother
\documentclass[tikz,border=0pt]{standalone}
\usepackage{tikz}
\makeatletter
\def\pgf@check@for@arrows{%
\pgf@drawarrowsfalse%
\ifx\pgf@startarrow\pgfutil@empty\else\pgf@drawarrowstrue\fi%
\ifx\pgf@endarrow\pgfutil@empty\else\pgf@drawarrowstrue\fi%
\ifdim\pgf@shorten@end@additional=0pt\relax\else\pgf@drawarrowstrue\fi%
\ifdim\pgf@shorten@start@additional=0pt\relax\else\pgf@drawarrowstrue\fi%
\ifpgf@drawarrows%
\pgfsyssoftpath@getcurrentpath\pgf@arrowpath%
\ifx\pgf@arrowpath\pgfutil@empty%
\pgf@drawarrowsfalse%
\else%
\pgfprocesscheckclosed{\pgf@arrowpath}{\pgf@drawarrowsfalse}%
\pgfprocesspathextractpoints{\pgf@arrowpath}%
\ifx\pgfpointsecondlastonpath\pgfpointlastonpath%
\pgf@drawarrowsfalse%
\fi%
\fi%
\fi%
}
\makeatother
\begin{document}
\foreach \angle in {0,5,...,355}{%
\begin{tikzpicture}[
scale=1.5,
arrow/.style={
-stealth, thick, line cap=round
}
]
\fill [white] (-1.02,-1.02) rectangle (1.02, 1.02);
\draw [gray, densely dashed] (0:{cos(\angle)}) |- (90:{sin(\angle)});
\draw (0,0) circle [radius=1];
\draw [blue, arrow] (0,0) -- (0:{cos(\angle)});
\draw [red, arrow] (0,0) -- (90:{sin(\angle)});
\draw [black, arrow] (0,0) -- (\angle:1);
\end{tikzpicture}%
}
\end{document}