]> git.scottworley.com Git - nt3d/blobdiff - torus_by_extrude.html
A helper function for generating pathnormals
[nt3d] / torus_by_extrude.html
index 323ad1472d006161824fc71a4949b227e8dccf8f..10ae92e50c7bdaaa3f1c3ab0ecd9d570c8c394d3 100644 (file)
@@ -3,19 +3,18 @@
     <title>Torus by extrude</title>
     <script type="text/javascript" src="nt3d.js"></script>
     <script type="text/javascript">
     <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);
+      function torus_by_extrude(torus_radius, cross_section_radius, rotation, long_steps, short_steps) {
        var path = nt3d.circle(torus_radius, long_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);
+       path = nt3d.rotate_about_origin(path, [0,1,0], rotation * 2*Math.PI);
+       return nt3d.closed_extrude(
+         path,
+         nt3d.circle(cross_section_radius, short_steps),
+         nt3d.shapenormals_from_closed_path(path),
+         [0, 0, 1]);
       }
       var params = [["Torus radus", 100],
                     ["Cross section radius", 40],
       }
       var params = [["Torus radus", 100],
                     ["Cross section radius", 40],
+                    ["Rotation (turns)", 0.001],
                     ["Steps around the long way", 50],
                     ["Steps around the short way", 16]];
     </script>
                     ["Steps around the long way", 50],
                     ["Steps around the short way", 16]];
     </script>