summaryrefslogtreecommitdiff
path: root/graphics/asymptote/examples/genustwo.asy
blob: 79e07e22684a8a7d618fb1be690159f23cb47c84 (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
size(10cm,0);
import smoothcontour3;
currentprojection=perspective((18,20,10));
if(settings.render < 0) settings.render=8;

real tuberadius = 0.69;

// Convert to cylindrical coordinates to draw
// a circle revolved about the z axis.
real toruscontour(real x, real y, real z) {
  real r = sqrt(x^2 + y^2);
  return (r-2)^2 + z^2 - tuberadius^2;
}

// Take the union of the two tangent tori (by taking
// the product of the functions defining them). Then
// add (or subtract) a bit of noise to smooth things
// out.
real f(real x, real y, real z) {
  real f1 = toruscontour(x - 2 - tuberadius, y, z);
  real f2 = toruscontour(x + 2 + tuberadius, y, z);
  return f1 * f2 - 0.1;
}

// The noisy function extends a bit farther than the union of
// the two tori, so include a bit of extra space in the box.
triple max = (2*(2+tuberadius), 2+tuberadius, tuberadius)
  + (0.1, 0.1, 0.1);
triple min = -max;

// Draw the implicit surface.
draw(implicitsurface(f, min, max, overlapedges=true,
                     nx=20, nz=5),
     surfacepen=material(diffusepen=gray(0.6),
                         emissivepen=gray(0.3),
                         specularpen=gray(0.1)));