]> git.scottworley.com Git - nt3d/commitdiff
Cones.
authorScott Worley <ScottWorley@ScottWorley.com>
Thu, 20 Dec 2012 09:18:52 +0000 (01:18 -0800)
committerScott Worley <ScottWorley@ScottWorley.com>
Thu, 20 Dec 2012 09:18:52 +0000 (01:18 -0800)
(Cones are the first primitive solid because 3-sided cones are basically
cheap arrows that can be littered all over the place for debugging.)

cone_primitive.html [new file with mode: 0644]
nt3d.js

diff --git a/cone_primitive.html b/cone_primitive.html
new file mode 100644 (file)
index 0000000..19a7686
--- /dev/null
@@ -0,0 +1,18 @@
+<html>
+  <head>
+    <title>Cone primitive</title>
+    <script type="text/javascript" src="nt3d.js"></script>
+    <script type="text/javascript">
+      function cone_primitive(height, radius, steps) {
+       return nt3d.cone([0,0,0], [0,0,height], radius, steps);
+      }
+      var params = [["Height", 100],
+                    ["Radius", 50],
+                    ["Steps", 30]];
+    </script>
+  </head>
+  <body onload="nt3d.framework(cone_primitive, params)">
+    <h1>Cone primitive</h1>
+    <p>There's a cone primitive.</p>
+  </body>
+</html>
diff --git a/nt3d.js b/nt3d.js
index 7472548fddfb800f2df62055983b90dda57a3878..0443913962128ee0a511cb805d9ac404d24a509b 100644 (file)
--- a/nt3d.js
+++ b/nt3d.js
@@ -55,6 +55,13 @@ nt3d = {
                }
                return points;
        },
+       cone: function(base_center, apex, radius, steps) {
+               var base = this.circle(radius, steps);
+               base = this.rotate_onto(base, [0,0,1], this.sub(apex, base_center));
+               base = this.translate(base, base_center);
+               return this.closed_trianglefan([apex].concat(base)).concat(
+                      this.trianglefan(base.reverse()));
+       },
        extrude: function(shape, path, shapenormals, pathnormals) {
                var guts_result = nt3d._extrude_guts(shape, path, shapenormals, pathnormals);
                // Add the end-caps