chiark / gitweb /
mesh: generates a file, but it is wrong
[moebius3.git] / meshscad
1 #!/usr/bin/python
2
3 from __future__ import print_function
4
5 import signal
6 signal.signal(signal.SIGINT, signal.SIG_DFL)
7
8 from moebius import *
9 from scad import *
10
11 nomsize = 50;
12 wire = 3.0;
13
14 # number of wires
15 kv = 10
16 kw = 10
17
18 # resolution
19 nv = 40
20 nw = 40
21 ns = 10 # around tube
22
23 nv += -nv % kv
24 nw += -nw % kw
25
26 each_v = nv / kv
27 each_w = nw / kw
28
29 m = Moebius(nv, nw)
30
31 def round_wire(p, vec_surfacenormal, vec_acrosswire, sigma):
32   r = (p +
33        wire/nomsize * (vec_surfacenormal * sin(sigma) +
34                        vec_acrosswire * cos(sigma)))
35   #print(' round_wire',p,vec_surfacenormal, vec_acrosswire, sigma, r,
36   #      file=sys.stderr)
37   return r
38
39 def make_moebius(objname):
40   print('module %s(){' % objname)
41   # wires:
42   extents = [ ScadObject() for v in range(0,nv) ] # along extents
43   travers = [ ScadObject() for w in range(0,nw) ] # along traverses
44   for v in range(0, nv):
45     for w in range(0, nw):
46       for s in range(0, ns):
47         print('VWS',v,w,s, file=sys.stderr)
48         sigmas = [ (s + sx)/ns * tau for sx in 0,1 ]
49         if not w % each_w:
50           extents[w].quad([ round_wire(p, norm, trav, sigmas[sx])
51                             for a in 0,1
52                             for p, norm, extt, trav in (m.details(v+a, w),)
53                             for sx in 0,1 ])
54         if not v % each_v:
55           travers[v].quad([ round_wire(p, norm, extt, sigmas[sx])
56                             for b in 0,1
57                             for p, norm, extt, trav in (m.details(v, w+b),)
58                             for sx in 0,1 ])
59   for v in range(0, nv):
60     print('// extent v=', v)
61     extents[v].writeout_core(nomsize)
62   for w in range(0, nw):
63     print('// travers w=', w)
64     travers[w].writeout_core(nomsize)
65   print('}')
66
67 make_moebius('MoebiusMesh')
68 print('moebiuscore_nomsize=%s;' % repr(nomsize))