[pstricks] Quartic Bezier curves (of fourth order)
Herbert Voss
Herbert.Voss at FU-Berlin.DE
Wed Mar 19 20:59:28 CET 2008
a solution created with hot needles ...
Herbert
\documentclass{article}
\usepackage{pst-plot}
\makeatletter
\pst at def{BezierQuartic}<
] /Points ED % y4 x4 y3 x3 y2 x2 y1 x1 y0 x0
/GetBezierCoor {
/t ED % t on stack
/t1 1 t sub def
% the x coordinate
Points 8 get t 4 exp mul % x0*B0(t)
Points 6 get t 3 exp 4 mul mul t1 mul add % x1*B1(t)
Points 4 get t 2 exp 6 mul mul t1 2 exp mul add % x2*B2(t)
Points 2 get t 4 mul mul t1 3 exp mul add % x3*B3(t)
Points 0 get t1 4 exp mul add % x4*B4(t)
% the y coordinate
Points 9 get t 4 exp mul % y0*B0(t)
Points 7 get t 3 exp 4 mul mul t1 mul add % y1*B1(t)
Points 5 get t 2 exp 6 mul mul t1 2 exp mul add % y2*B2(t)
Points 3 get t 4 mul mul t1 3 exp mul add % y3*B3(t)
Points 1 get t1 4 exp mul add % y4*B4(t)
} def
/epsilon 0.01 def
/n 5 def
epsilon GetBezierCoor % next Bezier point
Points 0 get Points 1 get % starting point
ArrowA moveto
epsilon epsilon 1 {
/t ED
t GetBezierCoor
t 0.9999 lt { lineto }{ 1 epsilon sub GetBezierCoor 4 2 roll ArrowB
pop pop pop pop } ifelse
} for >
%\def\tx at BezierQuartic{BezierQuartic }
\def\psbezierIV{\pst at object{psbezierIV}}
\def\psbezierIV at i{%
\pst at getarrows{%
\begin at OpenObj
\pst at getcoors[\psbezierIV at ii%
}}
\def\psbezierIV at ii{%
\addto at pscode{%
\tx at BezierQuartic
\ifshowpoints \tx at BezierShowPoints \fi
}%
\end at OpenObj}
%
\makeatother
\begin{document}
\psset{xunit=0.2cm}
\begin{pspicture}(40,15)
\psbezierIV[linewidth=2pt,showpoints=true]{<->}(0,0)(10,5)(20,13)(30,5)(40,0)
\end{pspicture}
\end{document}
More information about the PSTricks
mailing list