19

enter image description here

\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}

Does a zero-length line with an arrow make sense? Is it a bug? I hope it is a bug. If it is not a bug, what is the best way to handle this case using a conditional macro in either TeX or PS level?

Apparently, this feature is also adopted by TikZ.

enter image description here

\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
    Add an epsilon perturbation so that direction is properly defined. – Aditya Sep 05 '12 at 04:33
  • why should this be a bug? If the user defines an arrow then it is drawn. –  Sep 05 '12 at 11:54
  • @Herbert: Because it does not make sense. It will be better if the PSTricks core automatically does nothing for zero-length lines. – kiss my armpit Sep 05 '12 at 11:58
  • that has the user to be decide if it makes sense or not ... –  Sep 05 '12 at 12:13
  • @Herbert: If the line length with an arrow is measured from the tip of the arrow to the tail of the line then a zero-length line should be invisible. :-) – kiss my armpit Sep 05 '12 at 12:15
  • I guess this feature is provided for users who need to draw an arrow head only. – kiss my armpit Sep 05 '12 at 12:32
  • @GarbageCollector: exactly, eg for a vector field –  Sep 05 '12 at 12:44
  • @Herbert: Is it necessary to draw a zero-length vector field only with arrow heads? In my opinion, if we draw the arrow head for zero vector field then it will probably make the reader assume the magnitude of the vector field is not zero but too small to be drawn instead. It is dangerous. :-) – kiss my armpit Sep 05 '12 at 12:46
  • Hmmm, interesting. The problem with TikZ will be that only \draw[->] (0,0); draws the arrow, even it is just a move-to. A more complicated case will be \draw[->] (0,0) -- (.2,.2) (.5,.5); (also, try <->). I guess someone has to test somehow if the last operation on a path is a move-to and disable the “start arrow”. Simple..? – Qrrbrbirlbel Oct 05 '13 at 19:46
  • @Qrrbrbirlbel: Just testing for a move-to won't be enough, since \draw [->] (0,0) -- (0,0); also shouldn't result in an arrow head. – Jake Oct 06 '13 at 10:04
  • @Jake You’re right, I didn’t mention the original problem anymore. I guess, your answer will cover most of the problematic cases. – Qrrbrbirlbel Oct 06 '13 at 12:50
  • @Jake and Qrrbrbirlbel: Should it be regarded as a bug? – kiss my armpit Oct 06 '13 at 12:54
  • @PGFTricks: Depends on your definition of "bug", I think. You might want to post a bug report and see if it gets accepted. – Jake Oct 06 '13 at 12:57
  • @Jake: OK. Thanks. I will make a bug report later. – kiss my armpit Oct 06 '13 at 13:52
  • @DonutE.Knot Did you make one? If yes, what was the feedback? Jake’s answer won’t work for the CVS version (with or without the new arrows.meta library) and such strange paths have even more interesting results (there is a non-non-zero-length path added). – Qrrbrbirlbel Nov 23 '13 at 00:48
  • @Qrrbrbirlbel: I have not made a bug report yet. :-) – kiss my armpit Nov 23 '13 at 01:42

2 Answers2

17

With pstricks.tex from http://archiv.dante.de/~herbert/texnik/tex/generic/pstricks/ \psLine can have only one or two pairs of coordinates. Will later be on 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}

enter image description here

  • Is there another simpler, high level (as opposed to the low level with PSTricks core macro) workaround that I can digest and adopt for my future projects? – kiss my armpit Sep 05 '12 at 13:01
13

In TikZ, you can avoid drawing arrow heads if the last segment of a path has a length of zero by patching the internal \pgf@check@for@arrows macro:

\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}
Jake
  • 232,450