summaryrefslogtreecommitdiff
path: root/graphics/epix/samples/twisted_cubic.xp
blob: 8e9ec5d4b7cd55724e12f9ce578041fe4e7ef1dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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();
}