summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pst-bspline/pst-bspline.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/pst-bspline/pst-bspline.tex')
-rw-r--r--Master/texmf-dist/tex/generic/pst-bspline/pst-bspline.tex163
1 files changed, 148 insertions, 15 deletions
diff --git a/Master/texmf-dist/tex/generic/pst-bspline/pst-bspline.tex b/Master/texmf-dist/tex/generic/pst-bspline/pst-bspline.tex
index eaea89f9b77..a16112455a1 100644
--- a/Master/texmf-dist/tex/generic/pst-bspline/pst-bspline.tex
+++ b/Master/texmf-dist/tex/generic/pst-bspline/pst-bspline.tex
@@ -8,13 +8,15 @@
\ifx\PSTricksLoaded\endinput \else\input pstricks \fi
\ifx\PSTnodeLoaded\endinput \else\input pst-node \fi
\ifx\PSTXKeyLoaded\endinput \else\input pst-xkey \fi
-\def\fileversion{1.41}
-\def\filedate{2010/10/19}
+\def\fileversion{1.44}
+\def\filedate{2011/07/29}
\message{`pst-bspline' v\fileversion, \filedate\space Bspline routines for pstricks (ms)}
%
\edef\TheAtCode{\the\catcode`\@} \catcode`\@=11\relax
\pst@addfams{pst-bspline}
+\pstheader{pst-bspline.pro}
+
\SpecialCoor
%\newcount\pst@args%used in several macros--now defined in pst-node.tex
@@ -152,12 +154,12 @@
\advance\bsp@cntB by \@ne%
\psbezier[arrows=-\bsp@arrowB,showpoints=false](\bsp@root S\the\bsp@cntA)%
(\bsp@root R\the\bsp@cntA)(\bsp@root L\the\bsp@cntB)(\bsp@root S\the\bsp@cntB)%
- \ifPst@showframe \psdot[linecolor=red](\bsp@root L\the\bsp@cntB) \fi%
+% \ifPst@showframe \psdot[linecolor=red](\bsp@root L\the\bsp@cntB) \fi%
\fi% end \ifbsp@closed
-\ifPst@showframe%
- \psdot[linecolor=red](\bsp@root R0)%
- \psdot[linecolor=red](\bsp@root L\the\bsp@args)%
-\fi%
+%\ifPst@showframe%
+% \psdot[linecolor=red](\bsp@root R0)%
+% \psdot[linecolor=red](\bsp@root L\the\bsp@args)%
+%\fi%
\ifshowpoints%
\multido{\i=0+1}{\bsp@args}{\psdot(\bsp@root S\i)}%
\fi%
@@ -247,7 +249,7 @@
\fi%
\newcount\top@ndx \top@ndx=\top@mone%
\advance\top@ndx by \@ne%number of nodes to interpolate
-\
+%\
\newcount\top@mtwo \top@mtwo=\top@mone \advance\top@mtwo\m@ne%
% After copying S0 to S101, \top@ndx, \top@mone, \top@mtwo are top index, top index-1, top index-two---101, 100, 99 in the example
\make@mcoeff{\the\top@ndx}%
@@ -307,12 +309,11 @@
\multiply\np@cnt \tw@\advance\np@cnt \tw@% count of points in array
\pstVerb{ gsave tx@Dict begin %
/psxu \pst@number\psxunit\space def /psyu \pst@number\psyunit\space def %
- /uratio psyu psxu div def % so that perp to a, b is -b*uratio a
+ /uratio psyu psxu div dup mul def % so that perp to a, b is -b*uratio, a
/nseg #2 def /nplotpt \psk@plotpoints\space def %
/clipary #2 nplotpt mul 4 mul 4 add array def %
/lindex 2 def /uindex \the\ary@max\space 1 sub def %
/dt 1 \psk@plotpoints\space div def %
-% /halfthck #3 2 div def %
end grestore }%
\multido{\iA=0+1,\iB=1+1}{#2}{%
% pass control points of this segment to PostScript variables
@@ -320,7 +321,6 @@
gsave tx@Dict begin %
STV CP T \psGetNodeCenter{#1\iA}\space \psGetNodeCenter{#1BR\iA}\space \psGetNodeCenter{#1BL\iB}\space \psGetNodeCenter{#1\iB}\space %
/bez@1.x #1\iA.x def /bez@1.y #1\iA.y def %initial point on segment
- %(START) = bez@1.x = bez@1.y = SB1.x = %
/bez@2.x #1BR\iA.x bez@1.x sub def %adjusted control points (less init pt)
/bez@2.y #1BR\iA.y bez@1.y sub def %
/bez@3.x #1BL\iB.x bez@1.x sub def %
@@ -340,9 +340,9 @@
/Func % position
( bez@3x t mul bez@2x add t mul bez@1x add t mul bez@1.x add psxu mul %
bez@3y t mul bez@2y add t mul bez@1y add t mul bez@1.y add psyu mul ) cvx def %
-%/FuncT % tangent
-% ( bez@1x t bez@2xT mul add t t bez@3xT mul mul add %
-% bez@1y t bez@2yT mul add t t bez@3yT mul mul add ) cvx def
+% /FuncT % tangent
+% ( bez@2xT t bez@3xT mul add t mul bez@1x add %
+% bez@2yT t bez@3yT mul add t mul bez@1y add ) cvx def
/FuncN % unit normal times delta
( bez@2yT t bez@3yT mul add t mul bez@1y add uratio mul neg
bez@2xT t bez@3xT mul add t mul bez@1x add 2 copy Pyth dup %
@@ -363,7 +363,7 @@
/lindex lindex 2 add def /uindex uindex 2 sub def ){tmp@P}%
}% end multido \i
}% end multido \iA
-% if periodic, we have to adjust 2 points so as not too leave a wege in the
+% if periodic, we have to adjust 2 points so as not too leave a wedge in the
% clipping region. We have to set Q_{nk} to Q_0 and R_{nk} to R_0
% R_{nk} is at position 2*nk, 2*nk+1 and Q_{nk} is at the next pair
%\ifbsp@per %
@@ -393,5 +393,138 @@
\fi%
}%
\ignorespaces}%
+%
+\def\bsp@setup#1#2#3#4{%
+%#1=bsp root, #2=num #3=\top@ndx, #4=top@ndx-1, #4
+ \pstVerb{tx@Dict begin gsave STV CP T /bsp@desc #2 array def }%
+% \def\num{#2}
+ \multido{\iA=#4+-1,\iB=#3+-1}{#2}{%\show\num
+ \pstVerb{%
+ \psGetNodeCenter{#1S\iA}\space \psGetNodeCenter{#1R\iA}\space \psGetNodeCenter{#1L\iB}\space \psGetNodeCenter{#1S\iB}\space %
+ /bez@0x #1S\iA.x def /bez@0y #1S\iA.y def %initial point on segment
+ /bez@1x #1R\iA.x bez@0x sub 3 mul def % for position--w1=3z1
+ /bez@1y #1R\iA.y bez@0y sub 3 mul def
+ /bez@2x #1L\iB.x bez@0x sub #1R\iA.x bez@0x sub 2 mul sub 3 mul def % w2=3(z2-2z1)
+ /bez@2y #1L\iB.y bez@0y sub #1R\iA.y bez@0y sub 2 mul sub 3 mul def % w2=3(z2-2z1)
+ /bez@3x #1S\iB.x bez@1x add #1L\iB.x 3 mul sub bez@0x 2 mul add def % w3=z3+3z1-3z2
+ /bez@3y #1S\iB.y bez@1y add #1L\iB.y 3 mul sub bez@0y 2 mul add def % w3=z3+3z1-3z2
+ bsp@desc \iA\space mark bez@2y 2 mul bez@3y 3 mul bez@2x 2 mul bez@3x 3 mul bez@0y %
+ bez@1y bez@2y bez@3y bez@0x bez@1x bez@2x bez@3x ] put }%
+ }% end multido
+ \pstVerb{ grestore end }% closed tx@Dict, which contains array named bsp@desc
+}% bsp@setup
+\def\bspcurvepointsE{\pst@object{bspcurvepointsE}}%
+\def\bspcurvepointsE@i#1#2#3{\bspcurvepoints@ii{#1}{#2}{E}{#3}}%
+\def\bspcurvepoints{\pst@object{bspcurvepoints}}%
+\def\bspcurvepoints@i#1#2#3{\bspcurvepoints@ii{#1}{#2}{}{#3}}%
+\def\bspcurvepoints@ii#1#2#3#4{{%optional [plotpoints=xx]
+% #1=bsp root,#2=maxindex,#3=E/{},#4=root name for new PS arrays,
+ \pst@killglue%
+ \newcount\bsp@numndx
+ \bsp@numndx=#2 \relax%
+ \ifx#3E\relax
+ \advance \bsp@numndx \m@ne \edef\top@ndx{\the\bsp@numndx}
+ \advance \bsp@numndx \m@ne \edef\topm@ndx{\the\bsp@numndx}%
+ \else%
+ \edef\top@ndx{\the\bsp@numndx}%
+ \pst@cntc=\bsp@numndx\advance\pst@cntc \m@ne%
+ \edef\topm@ndx{\the\pst@cntc}%
+ \fi%
+ \pst@cntb=\bsp@numndx %\advance\pst@cntb \@ne\relax%
+ % set up the bsp ps array
+ \edef\cmd{\noexpand\bsp@setup{#1}{\the\bsp@numndx}{\top@ndx}{\topm@ndx}}\cmd%
+ \use@par%
+ \pst@cntc=\psk@plotpoints\relax%\psk@plotpoints=plotpoints-1
+ \pst@cnta=\pst@cntc \multiply\pst@cnta by \pst@cntb%
+ \edef\bsp@nsegs{\the\bsp@numndx}%\show\bsp@nsegs%
+ \advance\pst@cnta by \@ne\relax%=(plotpoints-1)*nsegs+1
+ \edef\@arraysize{\the\pst@cnta}%
+% \show\@arraysize
+ \pstVerb{ tx@Dict begin %
+ /psxu \pst@number\psxunit\space def /psyu \pst@number\psyunit\space def %
+ /unitratio \pst@number\psyunit \pst@number\psxunit div def %
+ /unitratiosq unitratio dup mul def %
+ /dt 1 \psk@plotpoints\space div def %
+ /#4.X \@arraysize\space array def %
+ /#4.Y \@arraysize\space array def %
+ /#4Delta.X \@arraysize\space array def %
+ /#4Delta.Y \@arraysize\space array def %
+ /#4Normal.X \@arraysize\space array def %
+ /#4Normal.Y \@arraysize\space array def %
+ /theseg 0 def %\the\bsp@numndx\space 1 sub def %
+ bsp@desc theseg get % the first segment
+ /cnt 1 def % counter for arrays
+ dup dup dup 8 get psxu mul 4 1 roll 4 get psyu mul 3 1 roll %
+ 9 get exch 5 get %4 copy = = = = % initial x, y, x', y'
+ unitratiosq mul neg #4Normal.X 0 3 -1 roll put #4Normal.Y 0 3 -1 roll put %
+ 2 copy #4.Y 0 3 -1 roll put #4.X 0 3 -1 roll put %
+ /priory ED /priorx ED % arrays now initialized
+ \bsp@nsegs\space {% repeat nsegs times
+ bsp@desc theseg get aload pop /x3 ED /x2 ED /x1 ED /x0 ED %
+ /y3 ED /y2 ED /y1 ED /y0 ED %
+ /xT3 ED /xT2 ED /yT3 ED /yT2 ED %
+ /Func ( x3 t mul x2 add t mul x1 add t mul x0 add psxu mul %
+ y3 t mul y2 add t mul y1 add t mul y0 add psyu mul ) cvx def %
+ /FuncN ( yT2 t yT3 mul add t mul y1 add unitratiosq mul neg %
+ xT2 t xT3 mul add t mul x1 add ) cvx def %
+ /theseg theseg 1 add def %
+ /j 1 def \psk@plotpoints\space {% repeat for each plotpt
+ /t j dt mul def Func 2 copy 2 copy FuncN % x y x y x y xN yN
+ #4Normal.Y cnt 3 -1 roll put %
+ #4Normal.X cnt 3 -1 roll put %
+ #4.Y cnt 3 -1 roll put %
+ #4.X cnt 3 -1 roll put % x y x y on stack
+ priory sub #4Delta.Y cnt 3 -1 roll put %
+ priorx sub #4Delta.X cnt 3 -1 roll put % x y on stack
+ /priory ED /priorx ED /j j 1 add def /cnt cnt 1 add def } repeat %
+ } repeat %#4.Y == %
+ end }% end pstVerb
+ \pst@cnta=\@arraysize \relax\advance\pst@cnta \m@ne %
+ \expandafter\xdef \csname #4pointcount\endcsname {\the\pst@cnta}%
+ \typeout{Created points #40 .. #4\the\pst@cnta}%
+}\ignorespaces}%
+\def\bspFnNode#1#2#3#4{%
+% #1=root name for B-spline control points, #2=top index
+% #3=x value, #4=name of node to place at (x,f(x))
+% This works only for a bspline function graph, not a general bspline curve
+\pnode(! bsp@desc length /n ED %
+ /x #3 def %
+ x bsp@desc 0 get 8 get dup /xt ED lt { /x xt def } if %
+ x bsp@desc n 1 sub get 8 4 getinterval aload pop add add add %endpt of last segment
+ dup /xt ED gt { /x xt def } if %
+ /j 0 def %
+ n {% repeat
+ x bsp@desc j get 8 get dup /xt ED le { exit } if /j j 1 add def %
+ } repeat %
+ j 0 gt { /j j 1 sub def } if %j is index of bezier segment containing x
+ bsp@desc j get dup dup dup %
+ 11 get exch 10 get 4 2 roll 9 get exch 8 get x sub cubic_roots %
+ /t ED pop pop %
+ t 1 gt { /t 1 def } if % zroot is the t value at which x=x(t)
+ x bsp@desc j get 4 4 getinterval aload pop % leaves y0, y1, y2, y3 on stack
+ t mul add t mul add t mul add % x y now on stack
+ ){#4}%
+}% end bspFnNode
+%
+\def\bspNode#1#2#3#4{%
+%src maxindex t target
+\pnode(! bsp@desc length /n ED %
+ /t #3 def %
+ t 0 lt { /t 0 def } if %
+ t n gt { /t n def } if % clamp t to [0,n]
+ /j t cvi def j n eq { /j n 1 sub def } if %
+ /t t j sub def % t in [0,1]
+ bsp@desc j get dup %
+ 8 4 getinterval aload pop t mul add t mul add t mul add % desc[[j]] x(t)
+ exch 4 4 getinterval aload pop t mul add t mul add t mul add % x(t) y(t)
+ ){#4}%
+}% end bspNode
+%
+\def\bspcurvenodes#1#2{%
+%#1= basename for points on curve, #2=basename for nodes
+\multido{\iA=0+1}{\csname #1pointcount\endcsname}{%
+\pnode(! #1.X \iA\space get #1.Y \iA\space get ){#2\iA}}%
+}%
+%
\catcode`\@=\TheAtCode\relax
\endinput \ No newline at end of file