12

TikZ gives us the ease of using relative coordinates, like in the following example.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
    \coordinate (A) at (-1,0);
    \draw[blue,->] (A) -- +(30:1);
    \draw[red] ($(A)+(30:1)$) +(30+90:1) -- +(30-90:1) -- +(30:0.5) -- +(30+90:1) coordinate (end);
    \draw[green] (A) -- (end) ++(30-90:2) -- (A);
\end{tikzpicture}
\end{document}

ex

This is extremely elegant, as I do not have to computed the coordinates by hand, especially when using arbitrarily placed nodes.

As PSTricks makes use of the computational power of Postscript, I hope there is a way to use relative coordinates. The syntax might not be as easy as in TikZ, but using 3D and plotting is much easier with PSTricks.

Question: Does PSTricks have capabilities for relative coordinates? (If yes, how do I use them?)

  • 1
    give another example, because the above is a simple \psline(1,0) – user2478 May 31 '13 at 18:59
  • I adjusted my post. Of course \psline(1,0) would have worked in that case, but needs the explicit coordinate (1,0). – Henri Menke May 31 '13 at 19:04
  • What do you think about my answer, are you satisfied with it? If no, please explain what kind of answer you are seeking. – kiss my armpit Jun 9 '13 at 13:49
  • I added more excessive examples. My question is about all the mechanisms, that exist for handling relative coordinates in PSTricks. – Henri Menke Jun 9 '13 at 17:25
6

\psrline is explained in pst-node documentation on page 41 but its code is implemented in pstricks-add. As usual, there might be a historical reason for this.

Based on your first case (before editing):

\psrline(A)(B)(C)... is equivalent to \draw (A) -- ++(B) -- ++(C)....

\documentclass[pstricks,border=4mm]{standalone}
\usepackage{pstricks-add}
\begin{document}
\begin{pspicture}[showgrid](-2,-1)(1,1)
    \pnode(-1,0){A}
    \psrline(A)(1;30)
\end{pspicture}
\end{document}

enter image description here

Based on your second case (after editing):

As far as I know, there is no PSTricks equivalent for \draw (A) -- +(B) -- +(C).... The following code produces the same output as yours.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}

\begin{document}
\begin{pspicture}[showgrid=true](-2,-1)(1,2)
    \pnode(-1,0){A}
    \pnode([nodesep=1,angle=30]A){B}
    \pnode([nodesep=1,angle={!30 90 add}]B){end}
    \psrline[linecolor=blue]{->}(A)(1;30)
    \psline[linecolor=red](B)(end)([nodesep=1,angle={!30 90 sub}]B)([nodesep=0.5,angle=30]B)(end)
    \psline[linecolor=green](A)(end)
    \psline[linecolor=green]([nodesep=2,angle={!30 90 sub}]end)(A)
\end{pspicture}
\end{document}

enter image description here

  • Thank you very much for adjusting your answer. Now it covers a broader range. – Henri Menke Jun 9 '13 at 19:26
  • 1
    I will make use of all the things explained in your answer to typeset the graphics for lecture notes. Hopefully, I encounter new practices and can extend this answer with more examples. – Henri Menke Jun 9 '13 at 20:04
6
\documentclass[border=3mm,pstricks]{standalone}
\usepackage{pstricks-add}
\begin{document}

 \begin{pspicture}[showgrid](9,10)
 \psStartPoint(1,0)
 \psVector(1;30) 
 \psStartPoint(1,1)
 \psVector[arrows=-](3;30)
 \psVector[arrows=-](4;60)
 \psVector[linecolor=red,arrows=-](3;10)
 \psVector[linestyle=dashed,arrows=-](4;110)
 \end{pspicture}

\end{document}

enter image description here

another possibility for a single line segment is \rput(-1,0){\psline(1;30)}

  • \psrline is explained in pst-node documentation but its code is defined in pstricks-add. Do you know it? – kiss my armpit Jun 7 '13 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.