]> git.scottworley.com Git - nt3d/commitdiff
Triangle fans
authorScott Worley <ScottWorley@ScottWorley.com>
Tue, 18 Dec 2012 09:34:16 +0000 (01:34 -0800)
committerScott Worley <ScottWorley@ScottWorley.com>
Tue, 18 Dec 2012 09:34:16 +0000 (01:34 -0800)
box_by_trianglefan.html [new file with mode: 0644]
nt3d.js

diff --git a/box_by_trianglefan.html b/box_by_trianglefan.html
new file mode 100644 (file)
index 0000000..1972560
--- /dev/null
@@ -0,0 +1,27 @@
+<html>
+  <head>
+    <title>Box by trianglefan</title>
+    <script type="text/javascript" src="nt3d.js"></script>
+    <script type="text/javascript">
+      function box_by_trianglefan(size_as_string) {
+        var size = parseFloat(size_as_string);
+        var origin = [0,    0,    0   ];
+        var x      = [size, 0,    0   ];
+        var y      = [0,    size, 0   ];
+        var z      = [0,    0,    size];
+        var xy     = [size, size, 0   ];
+        var xz     = [size, 0,    size];
+        var yz     = [0,    size, size];
+        var xyz    = [size, size, size];
+       return [].concat(
+         nt3d.trianglefan([origin, x, xz, z, yz, y, xy, x]),
+         nt3d.trianglefan([xyz, yz, z, xz, x, xy, y, yz]));
+      }
+      var params = [["Size", 1]];
+    </script>
+  </head>
+  <body onload="nt3d.framework(box_by_trianglefan, params)">
+    <h1>Box by trianglefan</h1>
+    <p>Make a box with two triangle fans from opposite corners.</p>
+  </body>
+</html>
diff --git a/nt3d.js b/nt3d.js
index ba2315fd777ad28c43ac0dd956a33f967739cb8e..623c0f1b3756940087c0bcc07f0a364891a1a532 100644 (file)
--- a/nt3d.js
+++ b/nt3d.js
@@ -23,6 +23,13 @@ nt3d = {
                return this.triangle(a, b, c).concat(
                       this.triangle(c, d, a));
        },
                return this.triangle(a, b, c).concat(
                       this.triangle(c, d, a));
        },
+       trianglefan: function(fan) {
+               var result = [];
+               for (var i = 2; i < fan.length; i++) {
+                       result.push(fan[0], fan[i-1], fan[i]);
+               }
+               return result;
+       },
        quadstrip: function(strip) {
                if (strip.length % 2 != 0) {
                        alert("quadstrip length not divisble by 2!");
        quadstrip: function(strip) {
                if (strip.length % 2 != 0) {
                        alert("quadstrip length not divisble by 2!");