From bbe27d79cac5c8406b69041f56588bfe0b642734 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 5 Nov 2017 19:09:16 +0000 Subject: [PATCH] wip pins Signed-off-by: Ian Jackson --- genscad | 44 +++++++++++++++++++++++++++++++++++++++++++- moebius-demo.scad | 10 ++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/genscad b/genscad index b2b83bf..26814fe 100755 --- a/genscad +++ b/genscad @@ -10,6 +10,8 @@ from moebius import * nomsize = 20 thick = 1.0 +sliceat = 1.675; + nv = 80 nw = 80 @@ -74,6 +76,46 @@ def make_moebius(objname): for b in (-1, +1) ]) so.writeout(objname, nomsize) -make_moebius('MoebiusCore') +def make_pinlocations(): + bests = [ None, None ] # bests[ y>=0 ] = (locn, normal) + def goodness(info): + # we find the one with biggest Z (actually, the least -ve) + return ( + 0 * np.linalg.norm(info[0][0:2]) + -abs(info[1][2]) + ) + return abs(info[1][1]) + + for v in range(0, nv): + for w in range(0, nw): + core_quad = [ m.point(v+a, w+b) + for a in (1, 0) + for b in (1, 0) ] + for p,q in [ (core_quad[i], core_quad[(i+1) % 4]) + for i in range(0,4) ]: + normal = (m.point_offset(v, w, 0.5) - core_quad[0] + + m.point_offset(v+1,w+1, 0.5) - core_quad[3]); + if normal[2] > 0: # inwards, make outwards + normal = -normal + + #print(repr((p,q)), file=sys.stderr) + if (p[2] > -sliceat) == (q[2] > -sliceat): continue + + lincomb = (-sliceat - p[2]) / (q[2] - p[2]) + here = p * (1-lincomb) + q * lincomb; + best_key = here[1] >= 0 + prospective = (here,normal) + if (bests[best_key] is None or + goodness(prospective) > goodness(bests[best_key])): + bests[best_key] = prospective + def print_bests(name, info_index): + print('moebius_pin_%s=[' % name) + for b in bests: print(repr(list(b[info_index])),',') + print('];') + print_bests('locns', 0) + print_bests('normals', 1) + +make_moebius('MoebiusCore') +make_pinlocations() print('moebiuscore_nomsize=%s;' % repr(nomsize)) diff --git a/moebius-demo.scad b/moebius-demo.scad index 9d99c56..1b2c6ff 100644 --- a/moebius-demo.scad +++ b/moebius-demo.scad @@ -9,3 +9,13 @@ intersection(){ translate([0,0, 200-sliceat]) cube(center=true, 400); } + +%for (i=[0,1]) { + hull(){ + translate( moebius_pin_locns[i] * moebiuscore_nomsize ) + sphere(2 + i); + translate( moebius_pin_locns[i] * moebiuscore_nomsize + + moebius_pin_normals[i] * moebiuscore_nomsize*0.5 ) + sphere(2 + i); + } +} -- 2.30.2