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
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);
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;
27 shape = nt3d.rotate_about_origin(shape, [
0,
0,
1], params.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 ["circle_angle",
.125, "Angle of circle (in turns) (useful when steps_around is small)"],
40 ["distortion_angle",
.25, "Distortion Angle (in turns)"],
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>