# [Programming] Relative coordinates

Denis Girou Denis.Girou at idris.fr
Fri Oct 17 23:34:50 CEST 1997

-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

Talking recently with somebody from Italy, I show him the simplification
that using relative coordinates can introduce in some cases.

Unfortunately relative coordinates are not available in PSTricks!
During some old discussion with Timothy in 1994, he tell me that he absolutely
agree that this functionality was useful and that he will think to that for a
future version.

But as we have not this one, I can propose the minimal implementation
I write at this time (I clean it up recently) for people interested. It works
only for cartesian and polar coordinates, but it is the most common cases.

I think that usage is straightforward looking at these examples.

\documentclass{article}

\usepackage{pstricks}

\newpsobject{showgrid}{psgrid}{subgriddiv=0,gridlabels=6pt}

\makeatletter

% Minimal implementation of relative cartesian and polar coordinates
% (n:m) means add n units in X direction and m in Y direction
% (n!m) means add n units in X direction and b degrees of angle
% Denis Girou (CNRS/IDRIS - France) <Denis.Girou at idris.fr> - 1994/1997
%
% New functions
\let\@psunit\psxunit
\afterassignment\pstunit at off
%
\let\@psunit\psyunit
\afterassignment\pstunit at off
%
%
\def\RelativeCartesian at coor#1#2{%
\edef\pst at coor{\pst at number\pst at dimg \pst at number\pst at dimh}}
%
\def\RelativePolar at coor#1#2{%
\edef\pst at coor{\pst at number\pst at dimg \pst at angle \tx at PtoC}}
%
\def\special@@@coor#1;#2;#3\@nil{%
\ifx#3;\relax
\polar at coor{#1}{#2}%
\else
% DG modification begin - 1994
\special@@@@coor#1::\@nil
\fi}
\def\special@@@@coor#1:#2:#3\@nil{%
\ifx#3:\relax
\RelativeCartesian at coor{#1}{#2}%
\else
\special@@@@@coor#1!!\@nil
\fi}
\def\special@@@@@coor#1!#2!#3\@nil{%
\ifx#3!\relax
\RelativePolar at coor{#1}{#2}%
\else
% DG modification end
\cartesian at coor#1,\relax,\@nil
\fi}

\makeatother

\begin{document}

\begin{pspicture}(4,4)
\showgrid
\SpecialCoor
\psline[linecolor=blue]{->}(2,3)(3,2)(2,0)
\psline[linecolor=red]{->}(0,2)(2:-1)(4,4)(-2:0)
\psline[linecolor=green]{->}(2,2)(-1:-2)(3:2)(-1:1)
\psframe[linewidth=1mm](2,2)(1:1)
\end{pspicture}
\hspace{1cm}
\begin{pspicture}(4,4)
\showgrid
\SpecialCoor
\psset{xunit=2}
\pspolygon[linecolor=blue](1,3)(1.5,2)(0.5,1)
\pspolygon[linecolor=green](1,2)(-0.5:-2)(1.5:2)(-0.5:1)
\end{pspicture}

\vspace{1cm}
\begin{pspicture}(4,4)
\showgrid
\SpecialCoor
\pscurve[linecolor=blue]{->}(2,3)(3,2)(1,1)
\pscurve[linecolor=green]{->}(2,2)(-1:-2)(3:2)(-1:1)
\end{pspicture}
\hspace{1cm}
\begin{pspicture}(4,4)
\showgrid
\SpecialCoor
\psline[linecolor=blue]{->}(2;30)(3;60)(1;30)
\pscurve[linecolor=green]{->}(2;30)(1!30)(-2!-30)
\psline[linecolor=red]{->}(0;0)(3!90)(0!-90)(2!45)
\end{pspicture}

\vspace{1cm}
\begin{pspicture}(4,4)
\showgrid
\SpecialCoor
\psline[linecolor=blue]{->}(2;30)(4;60)(1;30)
\psline[linestyle=dotted,dotsep=2mm]{->}(2;30)(2!30)(-3!-30)
\end{pspicture}
\hspace{1cm}
\begin{pspicture}(4,4)
\showgrid
\SpecialCoor
\degrees[4]
\psline[linecolor=blue]{->}(3;0)(4;1)(0;2)
\psline[linestyle=dotted,dotsep=2mm]{->}(3;0)(1!1)(-4!1)
\end{pspicture}

\end{document}

D.G.

-----------------------------------------------------------------------------