From 1a527ba2565b7af969a72080041eb2fe9b476bc5 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 5 Nov 2017 22:28:52 +0000 Subject: [PATCH] work on norm matrix Signed-off-by: Ian Jackson --- genscad | 30 ++++++++++++++++++++++++++++-- moebius-demo.scad | 7 ++----- moebius.py | 3 +++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/genscad b/genscad index 3440d18..9063c36 100755 --- a/genscad +++ b/genscad @@ -109,12 +109,38 @@ def make_pinlocations(): if (bests[best_key] is None or goodness(prospective) > goodness(bests[best_key])): bests[best_key] = prospective - def print_bests(name, info_index): + def print_best_list(name, l): print('moebius_pin_%s=[' % name) - for b in bests: print(repr(list(b[info_index])),',') + for i in l: print(repr(list(i)),',') print('];') + def print_bests(name, info_index): + print_best_list(name, [b[info_index] for b in bests]) print_bests('locns', 0) print_bests('normals', 1) + upwardses = [] + alongs = [] + matrices = [] + for b in bests: + along = unit_v(np.cross(b[1], unit_z)) + upwards = np.cross(b[1], along) + matrix = [ b[1], + upwards, + along ] + print('initial', matrix, file=sys.stderr) + matrix = np.concatenate((matrix, [[0,0,0]])) + print('concatd', matrix, file=sys.stderr) + matrix = np.array(matrix).T + print('transposed', matrix, file=sys.stderr) + matrix = np.concatenate((matrix, [[0,0,0,1]])) + print('concat2', matrix, file=sys.stderr) + matrix = [ list(row) for row in matrix ] + print('listed', matrix, file=sys.stderr) + alongs .append(along) + upwardses.append(upwards) + matrices. append(matrix) + print_best_list('upwardses',upwardses) + print_best_list('alongs', alongs) + print_best_list('matrix', matrices) make_moebius('MoebiusCore') make_pinlocations() diff --git a/moebius-demo.scad b/moebius-demo.scad index 9736899..8f827bd 100644 --- a/moebius-demo.scad +++ b/moebius-demo.scad @@ -98,11 +98,8 @@ module Pin(){ module PinDemo(){ for (i=[0,1]) { translate( moebius_pin_locns[i] * moebiuscore_nomsize ) { - hull(){ - sphere(2 + i); - translate( moebius_pin_normals[i] * moebiuscore_nomsize*0.5 ) - sphere(2 + i); - } + multmatrix(moebius_pin_matrix[i]) + cube(center=true, [1,4,9]); } } } diff --git a/moebius.py b/moebius.py index d9e452d..3cea68d 100644 --- a/moebius.py +++ b/moebius.py @@ -15,6 +15,9 @@ unit_x = np.array((1,0,0)) unit_y = np.array((0,1,0)) unit_z = np.array((0,0,1)) +def unit_v(v): + return v / np.linalg.norm(v) + class DoubleCubicBezier(): def __init__(db, cp): single = BezierSegment(cp) -- 2.30.2