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
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);
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;
27 shape = nt3d.rotate_about_origin(shape, [
0,
0,
1], distortion_angle*Math.PI*
2);
29 return nt3d.closed_extrude(
32 nt3d.shapenormals_from_closed_path(path),
33 nt3d.pathnormals_from_point(path, [
0,
0,
0]));
35 var params = [["Sphere radius",
100],
36 ["Extrusion radius",
5],
38 ["Angle of circle (in turns) (useful when steps_around is small)",
.125],
40 ["Angle of distortion (in turns)",
.25],
42 ["Steps along",
500]];
45 <body onload=
"nt3d.framework(wrap_sphere, params)">
47 <p>Extrude something in a spiral along the surface of a sphere.
</p>