# [pstricks] node calculations

Herbert Voss Herbert.Voss at alumni.TU-Berlin.DE
Mon Jun 7 07:11:03 CEST 2004

John Frampton wrote:
> Several times, I have needed a macro which could be used as follows:
>
>      \midpoint{A1}{A2}{A3}
>
> would label the midpoint of the line joining A1 and A2 as node A3.
>
> It would be even better to have a macro which could be used as follows:
>
>    \interpolate{A1}{A2}{.7}{A3}
>
> would label the point  .3*Point(A1) + .7*Point(A2) with the lable A3.
>
> Still better would be a macro so that
>
>    \linearcombination{1.2}{A1}{2.3}{A2}{A3}
>
> would label the appropriate linear combination of the points labeled A1 and A2
> with the label A3.
>
> Has anyone has already figured out how to incorporate this into PSTricks?  I assume that
> raw Postscript code is required.

yes, but it is always the same way. And very easy
to understand

Herbert

\documentclass{article}
\usepackage{pstricks,pst-node}
\SpecialCoor
\makeatletter
\def\setPoint(#1)(#2)#3#4{%
\pst at getcoor{#1}\pst at tempa%
\pst at getcoor{#2}\pst at tempb%
\pnode(!%
\pst at tempa /YA exch \pst at number\psyunit div def
/XA exch \pst at number\psxunit div def
\pst at tempb /YB exch \pst at number\psyunit div def
/XB exch \pst at number\psxunit div def
/dx XB XA sub def
/dy YB YA sub def
dx #3\space mul dy #3\space mul){#4}
}
\def\setPointII(#1)#2(#3)#4#5{%
\pst at getcoor{#1}\pst at tempa%
\pst at getcoor{#3}\pst at tempb%
\pnode(!%
\pst at tempa /YA exch \pst at number\psyunit div def
/XA exch \pst at number\psxunit div def
\pst at tempb /YB exch \pst at number\psyunit div def
/XB exch \pst at number\psxunit div def
XA #2\space mul XB #4\space mul add
YA #2\space mul YB #4\space mul add){#5}
}
\makeatletter
\begin{document}

\begin{pspicture}(5,5)
\psgrid[subgriddiv=0,griddots=10]
\psline(5,5)
\qdisk(0,0){2pt}\qdisk(5,5){3pt}
\setPoint(0,0)(5,5){0.75}{PI}
\qdisk(PI){4pt}
%
\psset{linecolor=red}
\psline{->}(2,1)\psline{->}(0.5,2)
\setPointII(2,1){1.5}(0.5,2){0.75}{PII}
\psline{->}(PII)
\end{pspicture}

\end{document}

--
http://TeXnik.de/
http://PSTricks.de/
ftp://ftp.dante.de/tex-archive/info/math/voss/Voss-Mathmode.pdf
http://www.dante.de/faq/de-tex-faq/
http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes