diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/epix/samples/twisted_cubic.xp |
Initial commit
Diffstat (limited to 'graphics/epix/samples/twisted_cubic.xp')
-rw-r--r-- | graphics/epix/samples/twisted_cubic.xp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/graphics/epix/samples/twisted_cubic.xp b/graphics/epix/samples/twisted_cubic.xp new file mode 100644 index 0000000000..8e9ec5d4b7 --- /dev/null +++ b/graphics/epix/samples/twisted_cubic.xp @@ -0,0 +1,106 @@ +/* -*-ePiX-*- */ +#include "epix.h" +using namespace ePiX; + +const double MAX(2.5); + +const double XMIN(-2); + +// twisted cubic +P cubic(double t) +{ + return t*P(1, t, t*t); +} + +// projections to coordinate planes +P cubic12(double t) +{ + const P arg(cubic(t)); + return P(arg.x1(), arg.x2(), XMIN); +} + +P cubic13(double t) +{ + const P arg(cubic(t)); + return P(arg.x1(), XMIN, arg.x3()); +} + +P cubic23(double t) +{ + const P arg(cubic(t)); + return P(XMIN, arg.x2(), arg.x3()); +} + +// draw lines from one path to another +void bars(P f1(double), P f2(double)) +{ + for (int i=0; i<=20; ++i) + line(f1(-1+0.1*i), f2(-1+0.1*i)); +} + +// code to draw entire figure +void draw_frame() +{ + // (x,z)-plane + blue(); + bbold(); + plot(cubic13, -1, 1, 60); + plain(); + bars(cubic13, cubic); + label(cubic13(1), P(0,2), "$x$-$z$", t); + + // (y,z)-plane + green(0.6); + bbold(); + plot(cubic23, -1, 1, 60); + plain(); + bars(cubic23, cubic); + label(cubic23(1), P(0,2), "$y$-$z$", t); + + // (x,y)-plane + magenta(); + bbold(); + plot(cubic12, -1, 1, 60); + plain(); + bars(cubic12, cubic); + label(cubic12(1), P(2,0), "$x$-$y$",r); + + // the cubic + bold(Red(1.6)); + base(Red(0.6), "2pt"); + plot(cubic, -1, 1, 60); +} + +int main() +{ + picture(P(-1,0), P(1.25,1), "4.5 x 2in"); + + begin(); + + screen scr_left(P(-MAX,-MAX), P(MAX,MAX)); + activate(scr_left); + + border(Black(), "1pt"); + + camera.at(sph(10, 0.8, 0.5)); + camera.look_at(P(0,0,-0.25)); + + draw_frame(); + base(Neutral()); + + screen scr_right(P(-MAX,-MAX), P(MAX,MAX)); + activate(scr_right); + + border(Black(), "1pt"); + + camera.at(sph(10, 0.9, 0.5)); + camera.look_at(P(0,0,-0.25)); + + draw_frame(); + + inset(scr_left, P(0.25,0), P(1.25,1)); + inset(scr_right, P(-1,0), P(0,1)); + + end(); +} + |