# [pstricks] rounded ends with psbezier

Michael Sharpe msharpe at ucsd.edu
Fri Jun 11 05:53:06 CEST 2010

On Jun 9, 2010, at 1:25 PM, mathias legrand wrote:

> Finally, I found this solution:
>
> \psset{arrowinset=0,arrowlength=2,arrowsize=1.5pt 3}
> \begin{pspicture}(0,-3.12)(6.82,3.12)
> \psbezier[linewidth=0.04,ArrowInside=-<,ArrowInsidePos=0.5]{c-c}(3.2,1.7)(4.4,1.3)(4.6,0.5)(4.6,-0.1)
> \psbezier[linewidth=0.04,ArrowInside=-<,ArrowInsidePos=0.5]{c-c}(2.2,-0.3)(2.0,0.3)(2.6,1.3)(3.2,1.7)
> \psbezier[linewidth=0.04,ArrowInside=->,ArrowInsidePos=0.5]{c-c}(5.0,0.1)(6.8,1.3)(5.4,3.1)(3.6,1.9)
> \psbezier[linewidth=0.04,ArrowInside=->,ArrowInsidePos=0.5]{c-c}(2.2,-0.3)(2.8,-0.7)(4.0,-0.5)(4.6,-0.1)
> \psbezier[linewidth=0.04,ArrowInside=->,ArrowInsidePos=0.5]{c-c}(2.8,1.9)(0.4,2.7)(0.0,1.1)(1.8,-0.1)
> \psbezier[linewidth=0.04,ArrowInside=-<,ArrowInsidePos=0.5]{c-c}(4.6,-0.5)(4.6,-2.9)(3.0,-3.1)(2.2,-0.7)
> \psbezier[linewidth=0.04,ArrowInside=->,ArrowInsidePos=0.5]{c-c}(3.6,1.9)(4.8,1.5)(5.0,0.7)(5.0,0.1)
> \psbezier[linewidth=0.04,ArrowInside=->,ArrowInsidePos=0.5]{c-c}(1.8,-0.1)(1.6,0.5)(2.2,1.5)(2.8,1.9)
> \psbezier[linewidth=0.04,ArrowInside=-<,ArrowInsidePos=0.5]{c-c}(2.2,-0.7)(2.8,-1.1)(4.0,-0.9)(4.6,-0.5)
> \end{pspicture}}
>
> but the arrowheads are not curved and should be for nicer results: is this possible (I saw similar things done via Asymptote I guess)?
>

I'm not sure what you are looking for, but what I see is arrowheads that are not well-aligned to the curves. This is not a simple matter to do automatically  when the arrowheads are large or the curvature is high. If you have the most recent pst-node, the \ArrowNotch macro can help with this by adjusting the arrow orientation so that both the arrow tip and the arrow notch both lie on the curve.

\documentclass{minimal}
\usepackage{arrayjobx}
\newarray\thedata
\makeatletter
%The next macro constructs nodes at a sequence of points (the points you would see with showpoints=true if it were drawn as a parametricplot) along a Bezier curve with specified control points.
\def\psbezierpnodes{\pst at object{psbezierpnodes}}
\def\psbezierpnodes at i(#1)(#2)(#3)(#4)#5{{%optional [plotpoints=xx]
%  #1--#4 are control pts,#5=node root name,
\pst at killglue
\use at par
\pnode(#1){bez at 1}\pnode(#2){bez at 2}\pnode(#3){bez at 3}\pnode(#4){bez at 4}%
\pnode(#1){#50}
\pstVerb{%
gsave tx at Dict begin
/dt 1 \psk at plotpoints\space div def %
STV CP T \psGetNodeCenter{bez at 1}\space \psGetNodeCenter{bez at 2}\space \psGetNodeCenter{bez at 3}\space \psGetNodeCenter{bez at 4}\space %
/bez at 1x bez at 2.x bez at 1.x sub 3 mul def %
/bez at 1y bez at 2.y bez at 1.y sub 3 mul def %
/bez at 2x bez at 1.x bez at 2.x 2 mul sub bez at 3.x add 3 mul def %
/bez at 2y bez at 1.y bez at 2.y 2 mul sub bez at 3.y add 3 mul def %
/bez at 3x bez at 1.x neg bez at 2.x bez at 3.x sub 3 mul add bez at 4.x add def %
/bez at 3y bez at 1.y neg bez at 2.y bez at 3.y sub 3 mul add bez at 4.y add def %
/Func %
(bez at 3x t mul bez at 2x add t mul bez at 1x add t mul bez at 1.x add %
bez at 3y t mul bez at 2y add t mul bez at 1y add t mul bez at 1.y add ) cvx def end grestore }%
\multido{\i=1+1}{\psk at plotpoints}{%
\pnode(! /t dt \i\space mul def Func ){#5\i}}%
\expandafter\xdef \csname #5nodecount\endcsname {\psk at plotpoints}%
\typeout{Created nodes #50 .. #5\psk at plotpoints}%
}\ignorespaces}%
\makeatother
\begin{document}
(2.2,-0.3)(2.0,0.3)(2.6,1.3)(3.2,1.7)&%
(5.0,0.1)(6.8,1.3)(5.4,3.1)(3.6,1.9)&%
(2.2,-0.3)(2.8,-0.7)(4.0,-0.5)(4.6,-0.1)&%
(2.8,1.9)(0.4,2.7)(0.0,1.1)(1.8,-0.1)&%
(4.6,-0.5)(4.6,-2.9)(3.0,-3.1)(2.2,-0.7)&%
(3.6,1.9)(4.8,1.5)(5.0,0.7)(5.0,0.1)&%
(1.8,-0.1)(1.6,0.5)(2.2,1.5)(2.8,1.9)&%
(2.2,-0.7)(2.8,-1.1)(4.0,-0.9)(4.6,-0.5)}
\begin{pspicture}(0,-3.12)(6.82,3.12)
\psset{linewidth=.04,linecap=1}
%draw curves without arrows
\multido{\i=1+1}{9}{\checkthedata(\i)\expandafter\psbezier\cachedata}
%draw inside arrows
\psset{arrowscale=2}
\multido{\i=1+1}{9}{\checkthedata(\i)\expandafter\psbezierpnodes\cachedata{R}%
\ArrowNotch{R}{27}{>}{Q}\psline{->}(Q)(R27)}% Q, the arrow notch, lies on the curve
\end{pspicture}
\end{document}

Michael