arrows in the middle of bezier curves

Denis Girou Denis.Girou at idris.fr
Thu Dec 18 22:31:48 CET 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.
-----------------------------------------------------------------------------

  Here is my own (limited) attempt - unfortunately the code posted
by Tamas Bori <bori at cs.elte.hu> is too difficult for me to understand...
It work only for \psline for the moment, but I'm pretty sure than it can be
extended this way to other kinds of curves.

  I add two new parameters ArrowInside and ArrowInsidePos. The first define
the arrow to print inside each segment of the line and the second the position 
of it in the segment (it must be a number between 0 and 1, with 0.5 as default 
value). The arrow itself is one of those defined, beginning each time by the
- character.

  See the examples below after the \begin{document} line.

D.G.

\documentclass{article}

\usepackage{pstricks}

\textheight=25cm

\pagestyle{empty}

\makeatletter

% DG addition begin - Dec. 18, 1997

% Adapted from \psset at arrows
\def\psset at ArrowInside#1{%
\begingroup
\pst at activearrows
\xdef\pst at tempg{<#1}%
\endgroup
\expandafter\psset@@ArrowInside\pst at tempg\@empty-\@empty\@nil
\if at pst\else
\@pstrickserr{Bad intermediate arrow specification: #1}\@ehpa
\fi}

% Adapted from \psset@@arrows
\def\psset@@ArrowInside#1-#2\@empty#3\@nil{%
\@psttrue
\def\next##1,#1-##2,##3\@nil{\def\pst at tempg{##2}}%
\expandafter\next\pst at arrowtable,#1-#1,\@nil
\@ifundefined{psas@#2}%
{\@pstfalse\def\psk at ArrowInside{}}%
{\def\psk at ArrowInside{#2}}}
\def\psk at ArrowInside{}

% Modified version of \pst at addarrowdef
\def\pst at addarrowdef{%
\addto at pscode{%
/ArrowA {
\ifx\psk at arrowA\@empty
\pst at oplineto
\else
\pst at arrowdef{A}
moveto
\fi
} def
/ArrowB {
\ifx\psk at arrowB\@empty \else \pst at arrowdef{B} \fi
} def
% DG addition
/ArrowInside {\ifx\psk at ArrowInside\@empty \else \pst at arrowdefA{Inside} \fi} def
}}

% Adapted from \pst at arrowdef
\def\pst at arrowdefA#1{%
\ifnum\pst at repeatarrowsflag>\z@
/Arrow#1c [ 6 2 roll ] cvx def Arrow#1c
\fi
\tx at BeginArrow
\psk at arrowscale
\@nameuse{psas@\@nameuse{psk at Arrow#1}}
\tx at EndArrow}

% ArrowInsidePos parameter
\def\psset at ArrowInsidePos#1{\pst at checknum{#1}\psk at ArrowInsidePos}%
\psset at ArrowInsidePos{0.5}

% Redefinition of the PostScript /Line macro to print the intermediate arrow
% on each segment of the line
\pst at def{Line}<{%
NArray
n 0 eq not
  { n 1 eq { 0 0 /n 2 def } if
    2 copy
    /y1 ED
    /x1 ED
    ArrowA
    x1 y1
    /n n 1 sub def
    n { 4 copy
        /y1 ED
        /x1 ED
        /y2 ED
        /x2 ED
        /aposx x2 x1 sub \psk at ArrowInsidePos mul x1 add def
        /aposy y2 y1 sub \psk at ArrowInsidePos mul y1 add def
        x1 y1 aposx aposy ArrowInside pop pop pop pop Lineto
      } repeat
    CP 4 2 roll ArrowB L pop pop } if}>

% DG addition end

\makeatother

\begin{document}

\psset{arrowscale=3}

\begin{pspicture}(2,1)
  \psline{->}(2,1)
\end{pspicture}

\begin{pspicture}(2,1)
  \psline[ArrowInside=->]{<->}(2,1)
\end{pspicture}

\begin{pspicture}(2,1)
  \psline[ArrowInside=-|]{|-|}(0,0)(2,1)
\end{pspicture}

\begin{pspicture}(0,-1)(10,2)
  \psline[ArrowInside=-*]{->}(0,0)(2,1)(3,-1)(5,-1)(10,2)
\end{pspicture}

\begin{pspicture}(0,-1)(10,2)
  \psline[ArrowInside=->,ArrowInsidePos=0.25]{->}(0,0)(2,1)(3,-1)(5,-1)(10,2)
\end{pspicture}

\begin{pspicture}(0,-1)(10,2)
  \psline[linestyle=none,ArrowInside=->,ArrowInsidePos=0.25]
         {->}(0,0)(2,1)(3,-1)(5,-1)(10,2)
\end{pspicture}

\begin{pspicture}(0,-1)(10,2)
  \psline[ArrowInside=-<,ArrowInsidePos=0.75]{->}(0,0)(2,1)(3,-1)(5,-1)(10,2)
\end{pspicture}

\begin{pspicture}(0,-1)(10,2)
  \psset{ArrowInside=-*}
  \psline(0,0)(2,1)(3,-1)(5,-1)(10,2)
  \psset{linestyle=none}
  \psline[ArrowInsidePos=0](0,0)(2,1)(3,-1)(5,-1)(10,2)
  \psline[ArrowInsidePos=1](0,0)(2,1)(3,-1)(5,-1)(10,2)
\end{pspicture}

\psset{ArrowInside=-|}

\begin{pspicture}(0,-1)(10,2)
  \psline[linearc=1]{<->}(0,0)(2,1)(3,-1)(5,-1)(10,2)
\end{pspicture}

\end{document}


  

-----------------------------------------------------------------------------
The list interface (subscription, information, access to the archives) is on:
http://www.tug.org/cgi-bin/lwgate/pstricks
Otherway to unsubscribe, send mail to pstricks-request at mail.tug.org
with a blank subject and in body the line unsubscribe <email-address>
-----------------------------------------------------------------------------



More information about the PSTricks mailing list