]>
Commit | Line | Data |
---|---|---|
1 | <html> | |
2 | <head> | |
3 | <title>Wrap Sphere</title> | |
4 | <script type="text/javascript" src="nt3d.js"></script> | |
5 | <script type="text/javascript"> | |
6 | function wrap_sphere(params) { | |
7 | // Spiral path along sphere surface | |
8 | var path = []; | |
9 | for (var i = 0; i < params.steps_along; i++) { | |
10 | var progress_0to2 = i / (params.steps_along/2); | |
11 | var progress_0to1andback = progress_0to2 < 1 ? progress_0to2 : 2 - progress_0to2; | |
12 | var progress_neg1to1andback = progress_0to1andback * 2 - 1; | |
13 | var z = progress_neg1to1andback * params.sphere_radius; | |
14 | var r = Math.sqrt(params.sphere_radius*params.sphere_radius - z*z); | |
15 | var phase_adjust = progress_0to2 < 1 ? 0 : Math.PI; | |
16 | var x = r*Math.cos(progress_0to1andback*params.turns*2*Math.PI + phase_adjust); | |
17 | var y = r*Math.sin(progress_0to1andback*params.turns*2*Math.PI + phase_adjust); | |
18 | path.push([x,y,z]); | |
19 | } | |
20 | ||
21 | // Shape to be extruded | |
22 | var shape = nt3d.circle(params.extrusion_radius, params.steps_around); | |
23 | shape = nt3d.rotate_about_origin(shape, [0,0,1], params.circle_angle*Math.PI*2); | |
24 | for (var i = 0; i < shape.length; i++) { | |
25 | shape[i][0] *= params.aspect_ratio; | |
26 | } | |
27 | shape = nt3d.rotate_about_origin(shape, [0,0,1], params.distortion_angle*Math.PI*2); | |
28 | ||
29 | return nt3d.closed_extrude( | |
30 | path, | |
31 | shape, | |
32 | nt3d.shapenormals_from_closed_path(path), | |
33 | nt3d.pathnormals_from_point(path, [0, 0, 0])); | |
34 | } | |
35 | var params = [["sphere_radius", 100], | |
36 | ["extrusion_radius", 5], | |
37 | ["turns", 3], | |
38 | ["circle_angle", .125, "Angle of circle (in turns) (useful when steps_around is small)"], | |
39 | ["aspect_ratio", 2], | |
40 | ["distortion_angle", .25, "Distortion Angle (in turns)"], | |
41 | ["steps_around", 4], | |
42 | ["steps_along", 500]]; | |
43 | </script> | |
44 | </head> | |
45 | <body onload="nt3d.framework(wrap_sphere, params)"> | |
46 | <h1>Wrap Sphere</h1> | |
47 | <p>Extrude something in a spiral along the surface of a sphere.</p> | |
48 | </body> | |
49 | </html> |