diff options
author | Norbert Preining <preining@logic.at> | 2007-11-27 15:41:48 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2007-11-27 15:41:48 +0000 |
commit | 959a2cbbbf85d2247595d38365fcc26b6056c5f7 (patch) | |
tree | 01bb086c86e944e4212268937352d1c7f1ea3df4 /Master/texmf-dist/metapost | |
parent | 662990e06c128ef614f35ce9426ffebe94d99c04 (diff) |
new metapost package bpolynomial
git-svn-id: svn://tug.org/texlive/trunk@5626 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/metapost')
-rw-r--r-- | Master/texmf-dist/metapost/bpolynomial/bpolynomial.mp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Master/texmf-dist/metapost/bpolynomial/bpolynomial.mp b/Master/texmf-dist/metapost/bpolynomial/bpolynomial.mp new file mode 100644 index 00000000000..6840bb04038 --- /dev/null +++ b/Master/texmf-dist/metapost/bpolynomial/bpolynomial.mp @@ -0,0 +1,66 @@ +%%% bpolynomial.mp +%%% Copyright 2007 Stephan Hennig <stephanhennig@arcor.de> +% +% This work may be distributed and/or modified under the conditions of +% the LaTeX Project Public License, either version 1.3 of this license +% or (at your option) any later version. The latest version of this +% license is in http://www.latex-project.org/lppl.txt +% + +if known bpolynomial_fileversion: endinput fi; +string bpolynomial_fileversion; +bpolynomial_fileversion := "v0.3 (2007/11/26)"; +message "Loading bpolynomial " & bpolynomial_fileversion; + + +%%% This macro defines two macros @#.eval and @#.getPath. +%%% Parameters are the coefficients of the polynomial a*x^3 + b*x^2 + c*x + d. +vardef newBPolynomial@#(expr ca,cb,cc,cd)= +numeric @#.a, @#.b, @#.c, @#.d; + + %%% Save coefficients for later access. + %%% For instance, variable @#.a refers to coefficient a of polynomial @#. + @#.a := ca; + @#.b := cb; + @#.c := cc; + @#.d := cd; + + %%% Define a macro that returns polynomial values. + %%% Parameter is an x value. + vardef @#.eval(expr x)= + (((@#.a*x + @#.b)*x + @#.c)*x + @#.d) + enddef; + + %%% Define a macro that returns a path of the polynomial + %%% on a given intervall [xl, xr]. + vardef @#.getPath(expr xl,xr)= + save xA,xB,xC,xD,yA,yB,yC,yD; + save dx; + numeric xA,xB,xC,xD,yA,yB,yC,yD; + numeric dx; + dx := xr - xl; + %%% Original equation system for x values. +% xA = xl; +% 3(xB - xA) = dx; +% 3(xC - 2xB + xA) = 0; +% xD - 3xC + 3xB - xA = 0; + %%% Modified equation system. + xA := xl; + xB := xl + dx/3; + xC := xr - dx/3; + xD := xr; + %%% Original equation system for y values. +% yA = ((@#.a*xl + @#.b)*xl + @#.c)*xl + @#.d; +% 3(yB - yA) = dx*((3@#.a*xl + 2@#.b)*xl + @#.c); +% 3(yC - 2yB + yA) = dx*dx*(3@#.a*xl + @#.b); +% yD - 3yC + 3yB - yA = @#.a*dx*dx*dx; + %%% Modified equation system. + yA := @#.eval(xl); + 3(yB - yA) = dx*((3@#.a*xl + 2@#.b)*xl + @#.c); + 3(yC - 2yB + yA) = dx*dx*(3@#.a*xl + @#.b); + yD := @#.eval(xr); + %%% Return path A..controls B and C..D. + (xA,yA)..controls (xB,yB) and (xC,yC)..(xD,yD) + enddef; + +enddef; |