|
6 | 6 | <body> |
7 | 7 | <a href="javascript:link1()">Ellipsoid</a>, |
8 | 8 | <a href="javascript:link2()">Klein bottle</a>, |
9 | | -<a href="javascript:link3()">Möbius strip</a> |
| 9 | +<a href="javascript:link3()">Möbius strip</a>, |
| 10 | +<a href="javascript:link4()">Surface of revolution for f(x) = sin x</a> |
| 11 | +<a href="javascript:link5()">Surface of revolution for f(x) = x<sup>2</sup></a> |
10 | 12 | <br> |
11 | 13 | <canvas width="600" height="450" id=canvas></canvas> |
12 | 14 | <script id="demo"> |
|
34 | 36 | } |
35 | 37 | } |
36 | 38 |
|
| 39 | +var RevolutionSurface=function(func,minval,maxval){ |
| 40 | + this.func=func |
| 41 | + this.minval=minval |
| 42 | + this.maxval=maxval |
| 43 | + this.evaluate=function(u,v,output){ |
| 44 | + v=1-v; |
| 45 | + v*=Math.PI*2; |
| 46 | + u=minval+(maxval-minval)*u; |
| 47 | + var r=this.func(u); |
| 48 | + output[0]=u; |
| 49 | + output[1]=r*Math.cos(v); |
| 50 | + output[2]=r*Math.sin(v); |
| 51 | + return 3; |
| 52 | + } |
| 53 | +} |
| 54 | + |
37 | 55 | var KleinBottle=function(){ |
38 | 56 | this.evaluate=function(u,v,output){ |
39 | 57 | u*=Math.PI*2; |
|
82 | 100 | } |
83 | 101 | } |
84 | 102 |
|
85 | | - |
86 | | - |
87 | 103 | var ColorGradient={ |
88 | 104 | evaluate:function(u,v,output){ |
89 | 105 | output[0]=1.0-u; |
|
100 | 116 | .color(ColorGradient) |
101 | 117 | .setAutoNormal(true) |
102 | 118 | .evalSurface(mesh,Mesh.TRIANGLES,50,50); |
103 | | - console.log(mesh) |
104 | 119 | return mesh; |
105 | 120 | } |
106 | 121 |
|
|
119 | 134 | scene.addShape(shape=scene.makeShape(makeMesh(new MoebiusStrip()))); |
120 | 135 | } |
121 | 136 |
|
| 137 | +function link4(){ |
| 138 | + scene.removeShape(shape); |
| 139 | + scene.addShape(shape=scene.makeShape(makeMesh(new RevolutionSurface(function(x){ |
| 140 | + return Math.sin(x) |
| 141 | + },-Math.PI,Math.PI)))); |
| 142 | +} |
| 143 | + |
| 144 | +function link5(){ |
| 145 | + scene.removeShape(shape); |
| 146 | + scene.addShape(shape=scene.makeShape(makeMesh(new RevolutionSurface(function(x){ |
| 147 | + return x*x |
| 148 | + },-1,1)))); |
| 149 | +} |
| 150 | + |
| 151 | +function link5(){ |
| 152 | + scene.removeShape(shape); |
| 153 | + scene.addShape(shape=scene.makeShape(makeMesh(new RevolutionSurface(function(x){ |
| 154 | + return x*x |
| 155 | + },-1,1)))); |
| 156 | +} |
122 | 157 |
|
123 | 158 | // Create the 3D scene; find the HTML canvas and pass it |
124 | 159 | // to Scene3D. |
|
0 commit comments