chiark / gitweb /
genscad
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 5 Nov 2017 00:59:13 +0000 (00:59 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 5 Nov 2017 01:02:31 +0000 (01:02 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
genscad [new file with mode: 0755]
moebius-demo.scad [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..cd6d815
--- /dev/null
@@ -0,0 +1 @@
+moebius-core.scad
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..bf04a5e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+
+all: moebius-core.scad
+
+moebius-core.scad: genscad
+               ./$< >$@.tmp && mv -f $@.tmp $@
diff --git a/genscad b/genscad
new file mode 100755 (executable)
index 0000000..26a21e7
--- /dev/null
+++ b/genscad
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+from __future__ import print_function
+
+import signal
+signal.signal(signal.SIGINT, signal.SIG_DFL)
+
+from moebius import *
+
+nomsize = 20
+thick = 2.5
+
+nv = 40
+nw = 40
+
+m = Moebius(nv, nw)
+
+
+stl_points = []
+stl_point_indices = {}
+stl_triangles = []
+
+def stl_writeout():
+  print('module MoebiusCore(){ scale(%s) polyhedron(points=[' % nomsize)
+  for p in stl_points: print(p, ',')
+  print('],faces=[')
+  for t in stl_triangles: print(repr(t), ',')
+  print('],convexity=10); }')
+
+def stl_point(p):
+  l = list(p)
+  s = repr(l)
+  try:
+    ix = stl_point_indices[s]
+  except KeyError:
+    ix = len(stl_points)
+    stl_points.append(s)
+    stl_point_indices[s] = ix
+  return ix
+
+def stl_triangle(a,b,c):
+  ''' a b c  are clockwise from inside '''
+  stl_triangles.append([ stl_point(p) for p in (a,b,c) ])
+
+def stl_quad(cnrs):
+  ''' cnrs[0] [1] [3] [2] are clockwise from inside '''
+  stl_triangle(cnrs[0], cnrs[1], cnrs[3])
+  stl_triangle(cnrs[0], cnrs[3], cnrs[2])
+
+relthick = thick/(nomsize*2)
+
+for v in range(0, nv):
+  for w in range(0, nw):
+    stl_quad([ m.point_offset(v+a, w+b,  relthick)
+               for a in (0, 1)
+               for b in (0, 1) ])
+    stl_quad([ m.point_offset(v+a, w+b, -relthick)
+               for a in (1, 0)
+               for b in (1, 0) ])
+
+stl_writeout()
diff --git a/moebius-demo.scad b/moebius-demo.scad
new file mode 100644 (file)
index 0000000..b25e489
--- /dev/null
@@ -0,0 +1,3 @@
+include <moebius-core.scad>
+
+MoebiusCore();