]> git.scottworley.com Git - nt3d/blame_incremental - wrap_sphere.html
Explicitly bounds-check in angle_between()
[nt3d] / wrap_sphere.html
... / ...
CommitLineData
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(sphere_radius, extrusion_radius, turns, circle_angle, aspect_ratio, distortion_angle, steps_around, steps_along) {
7 // Spiral path along sphere surface
8 var path = [];
9 for (var i = 0; i < steps_along; i++) {
10 var progress_0to2 = i / (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 * sphere_radius;
14 var r = Math.sqrt(sphere_radius*sphere_radius - z*z);
15 var phase_adjust = progress_0to2 < 1 ? 0 : Math.PI;
16 var x = r*Math.cos(progress_0to1andback*turns*2*Math.PI + phase_adjust);
17 var y = r*Math.sin(progress_0to1andback*turns*2*Math.PI + phase_adjust);
18 path.push([x,y,z]);
19 }
20
21 // Shape to be extruded
22 var shape = nt3d.circle(extrusion_radius, steps_around);
23 shape = nt3d.rotate_about_origin(shape, [0,0,1], circle_angle*Math.PI*2);
24 for (var i = 0; i < shape.length; i++) {
25 shape[i][0] *= aspect_ratio;
26 }
27 shape = nt3d.rotate_about_origin(shape, [0,0,1], 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 ["Angle of circle (in turns) (useful when steps_around is small)", .125],
39 ["Aspect ratio", 2],
40 ["Angle of distortion (in turns)", .25],
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>