diff options
author | Karl Berry <karl@freefriends.org> | 2006-01-09 00:49:07 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-01-09 00:49:07 +0000 |
commit | 007f67a693e4d031fd3d792df8e4d5f43e2cb2e7 (patch) | |
tree | 90d17e00e572ecb1e24764b6f29c80e098b08d29 /Master/texmf-dist/doc/latex/metaplot/examples/cpoint.cc | |
parent | 950209b26f70aa87ed07c54f82a95b6f03b7c3a0 (diff) |
doc/latex
git-svn-id: svn://tug.org/texlive/trunk@84 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/metaplot/examples/cpoint.cc')
-rw-r--r-- | Master/texmf-dist/doc/latex/metaplot/examples/cpoint.cc | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/metaplot/examples/cpoint.cc b/Master/texmf-dist/doc/latex/metaplot/examples/cpoint.cc new file mode 100644 index 00000000000..5d145f2c8df --- /dev/null +++ b/Master/texmf-dist/doc/latex/metaplot/examples/cpoint.cc @@ -0,0 +1,93 @@ +/* MetaContour, version 0.1 -------------------------------------- */ +/* Copyright(C) 2004, Brooks Moses */ +/* */ +/* This version of MetaContour is made available under the Gnu */ +/* Public License; see metacontour_main.cc for details. */ +/* */ +/* This is a very pre-release version of MetaContour, distributed */ +/* primarily as an example of a use of MetaPlot. It can be */ +/* compiled with gcc using the line: */ +/* */ +/* g++ metacontour.cc cpoint.cc metacontour_main.cc */ +/* */ +/*-----------------------------------------------------------------*/ + +/* Class for 2D points with one data value each */ + +#include<sstream> +#include"cpoint.h" +using namespace std; + + +//-----cpoint-------------------------------------------------- + +cpoint::cpoint() { + x = 0; + y = 0; + z = 0; +} + +cpoint::cpoint(double xx, double yy, double zz) { + x = xx; + y = yy; + z = zz; +} + +cpoint cpoint::interpolateto(cpoint x2, double z3) { + double w = (z3-z)/(x2.z-z); + if (w > 1) w=1; + if (w < 0) w=0; + double x3 = x + (x2.x-x)*w; + double y3 = y + (x2.y-y)*w; + return cpoint(x3,y3,z3); +} + +cpoint cpoint::partwayto(cpoint x2, double w) { + if (w > 1) w=1; + if (w < 0) w=0; + double x3 = x + (x2.x-x)*w; + double y3 = y + (x2.y-y)*w; + double z3 = z + (x2.z-z)*w; + return cpoint(x3,y3,z3); +} + +// Derivation: +// F = ax + by + cxy + d x,y in [0,1] +// Fx = a + by, Fy = b + cx +// Thus: saddle point S is at (-b/c, -a/c) +// Plugging this in, and solving, we get +// F(S) = (f00*f11 - f01*f10) / (f00 + f11 - f01 - f10) +// +// Note: mapping x1 = (0,0), x2 = (1,0), x3 = (1,1), x4 = (0,1) +// +double cpoint::saddlepoint(cpoint x1, cpoint x2, cpoint x3, cpoint x4) { + return (x1.z * x3.z - x2.z * x4.z) / (x1.z + x3.z - x2.z - x4.z); +} + +string cpoint::metapoint() { + ostringstream pointstring; + pointstring.setf(ios_base::fixed,ios_base::floatfield); + pointstring.precision(5); + pointstring << '(' << x << ',' << y << ')'; + return pointstring.str(); +} + + +//-----cparray------------------------------------------------- + +cparray::cparray(int x, int y) { + if (x<1) x=1; + if (y<1) y=1; + i = x; + j = y; + a = new valarray<cpoint>(x*y); +} + +cparray::~cparray() { + delete a; +} + +cpoint& cparray::operator()(int x, int y) +{ + return (*a)[x*j+y]; +} |