chiark / gitweb /
viewdims variable
[moebius2.git] / sgtatham / z.max
1 /* -*- c -*-
2 maxima -b z.max | perl -pe 's/\\\n//sg' | tail -1 | perl -pe 'BEGIN{print "set urange [0:1]\nset vrange [0:pi]\nset parametric\nset hidden\nset isosamples 30\nsplot "} s/^.*\[(.*)\].*$/$1/; s/%pi/pi/g; s:\^:**:g' | gnuplot -persist
3 */
4
5 /*
6  * Construct a series of transformations which turn the unit
7  * circle in the x-y plane into something which might plausibly
8  * form the edge of an ordinary embedding of a Mobius strip. Each
9  * transformation must a homeomorphism of R^3, and hence in
10  * particular invertible.
11  *
12  * The individual transformations are as follows:
13  * 
14  *  - f applies a twist about the x-axis, by rotating the plane
15  *    x=k by an amount proportional to k, for all k in R. The
16  *    twist is set up so that the x=1 end of the unit circle
17  *    remains where it started, and the x=-1 end is in the same
18  *    place but rotated 180 degrees so that it's heading in the
19  *    opposite direction.
20  * 
21  *  - g is a squash in the z-direction, squishing the twisted
22  *    circle down into something that's closer to a flat
23  *    figure-eight.
24  * 
25  *  - h elevates the two extreme-x ends of the circle in the z
26  *    direction.
27  * 
28  * So what we do is to take a unit circle; apply those
29  * transformations in order to make it an ordinary Mobius-strip
30  * edge; now construct an actual Mobius strip as the union of all
31  * straight line segments connecting pairs of points on that
32  * transformed circle which were originally 180 degrees apart;
33  * then apply the inverse homeomorphism to restore the edge to
34  * circularity.
35  * 
36  * (We rely on the fact that our transformations have mangled the
37  * unit circle into a state in which none of those line segments
38  * intersect each other. Otherwise we'd end up with a
39  * self-intersecting surface.)
40  */
41 f(x,y,z) := [x, y*sin(%pi*x/2) + z*cos(%pi*x/2), -y*cos(%pi*x/2) + z*sin(%pi*x/2)];
42 g(x,y,z) := [x, y, z/1.5];
43 h(x,y,z) := [x, y, z+x^2];
44
45 finv(x,y,z) := [x, y*sin(%pi*x/2) - z*cos(%pi*x/2), y*cos(%pi*x/2) + z*sin(%pi*x/2)];
46 ginv(x,y,z) := [x, y, z*1.5];
47 hinv(x,y,z) := [x, y, z-x^2];
48
49 fv(v) := f(v[1],v[2],v[3]);
50 gv(v) := g(v[1],v[2],v[3]);
51 hv(v) := h(v[1],v[2],v[3]);
52
53 finvv(v) := finv(v[1],v[2],v[3]);
54 ginvv(v) := ginv(v[1],v[2],v[3]);
55 hinvv(v) := hinv(v[1],v[2],v[3]);
56
57 hgf(v) := hv(gv(fv(v)));
58 fghinv(v) := finvv(ginvv(hinvv(v)));
59
60 circle(t) := [cos(t), sin(t), 0];
61
62 ms(t,u) := fghinv(u*hgf(circle(t)) + (1-u)*hgf(-circle(t)));
63
64 string(ms(v,u));