]> git.scottworley.com Git - nt3d/commitdiff
Torus by extrude demo
authorScott Worley <ScottWorley@ScottWorley.com>
Thu, 20 Dec 2012 09:11:52 +0000 (01:11 -0800)
committerScott Worley <ScottWorley@ScottWorley.com>
Thu, 20 Dec 2012 09:11:52 +0000 (01:11 -0800)
nt3d.js
torus_by_extrude.html [new file with mode: 0644]

diff --git a/nt3d.js b/nt3d.js
index bae29f2fa351aa5a9e90cd5bdc29f4a3806baad0..7472548fddfb800f2df62055983b90dda57a3878 100644 (file)
--- a/nt3d.js
+++ b/nt3d.js
@@ -46,6 +46,15 @@ nt3d = {
        closed_quadstrip: function(strip) {
                return this.quadstrip(strip.concat([strip[0], strip[1]]));
        },
+       circle: function(r, n) {
+               var points = [];
+               for (var i = 0; i < n; i++) {
+                       points.push([r*Math.cos(2*Math.PI*i/n),
+                                    r*Math.sin(2*Math.PI*i/n),
+                                    0]);
+               }
+               return points;
+       },
        extrude: function(shape, path, shapenormals, pathnormals) {
                var guts_result = nt3d._extrude_guts(shape, path, shapenormals, pathnormals);
                // Add the end-caps
diff --git a/torus_by_extrude.html b/torus_by_extrude.html
new file mode 100644 (file)
index 0000000..323ad14
--- /dev/null
@@ -0,0 +1,27 @@
+<html>
+  <head>
+    <title>Torus by extrude</title>
+    <script type="text/javascript" src="nt3d.js"></script>
+    <script type="text/javascript">
+      function torus_by_extrude(torus_radius, cross_section_radius, long_steps, short_steps) {
+       var cross_section = nt3d.circle(cross_section_radius, short_steps);
+       var path = nt3d.circle(torus_radius, long_steps);
+       var cross_section_normals = nt3d.rotate_about_origin(path, [0,0,1], Math.PI/2);
+       var path_normals = [];
+       path_normals.length = long_steps;
+       for (var i = 0; i < long_steps; i++) {
+               path_normals[i] = [0, 0, 1];
+       }
+       return nt3d.closed_extrude(cross_section, path, cross_section_normals, path_normals);
+      }
+      var params = [["Torus radus", 100],
+                    ["Cross section radius", 40],
+                    ["Steps around the long way", 50],
+                    ["Steps around the short way", 16]];
+    </script>
+  </head>
+  <body onload="nt3d.framework(torus_by_extrude, params)">
+    <h1>Torus by extrude</h1>
+    <p>Make a torus by extruding a circle.</p>
+  </body>
+</html>