diff --git a/feedthrough1.FCStd b/feedthrough1.FCStd index 42bb5dc..7470456 100644 Binary files a/feedthrough1.FCStd and b/feedthrough1.FCStd differ diff --git a/feedthrough1_mesh.FCStd b/feedthrough1_mesh.FCStd new file mode 100644 index 0000000..dcb5b21 Binary files /dev/null and b/feedthrough1_mesh.FCStd differ diff --git a/secondary_mesh_planning.py b/secondary_mesh_planning.py index 4612de8..15b694d 100644 --- a/secondary_mesh_planning.py +++ b/secondary_mesh_planning.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import tempfile +import subprocess import colorsys import textwrap import math @@ -7,6 +9,7 @@ from pathlib import Path import webbrowser import scipy import numpy as np +import os import click @@ -79,9 +82,10 @@ class Tag: @click.option('--mesh-width', type=float, default=15) @click.option('--start', type=click.Choice(['center', 'offset'])) @click.option('--initial-radius', type=float, default=14) +@click.option('--wire-diameter', type=float, default=3, help='Wire diameter for STL export') @click.argument('out_svg', type=click.Path(dir_okay=False, path_type=Path)) -@click.argument('out_txt', type=click.Path(dir_okay=False, path_type=Path)) -def cli(out_svg, out_txt, mesh_thickness, offset, mesh_space, mesh_width, start, initial_radius, steps): +@click.argument('out_stl', type=click.Path(dir_okay=False, path_type=Path), required=False) +def cli(out_svg, out_stl, wire_diameter, mesh_thickness, offset, mesh_space, mesh_width, start, initial_radius, steps): tags = [] dim_tags = [] @@ -256,49 +260,68 @@ def cli(out_svg, out_txt, mesh_thickness, offset, mesh_space, mesh_width, start, dim_tags += dimension((px - sign*current_radius, 0), (px - sign*(current_radius-2*offset), 0), h=10, offset_1=mesh_width/2) - points = [(0, 0, 0)] radii.append(radii[-1] + 20) - h = 18 - with open(out_txt, 'w') as f: - for i, r in enumerate(radii): - sign_i = (i%2)*2 - 1 - offset_i = 0 if i%2 == 0 else offset - a = math.pi/3 if i == 0 else -sign_i * math.pi/2 + h = 20 - wire_diameter + h_off = -h/2 - wire_diameter/2 + points = [(0, 0, +h_off)] + for i, r in enumerate(radii): + sign_i = (i%2)*2 - 1 + offset_i = 0 if i%2 == 0 else offset + a = math.pi/3 if i == 0 else -sign_i * math.pi/2 - x = offset_i + math.cos(a)*r - y = math.sin(a)*r - z = sign_i*h/2 - points.append((x, y, z)) + x = offset_i + math.cos(a)*r + y = math.sin(a)*r + z = sign_i*h/2 + h_off + points.append((x, y, z)) - a = -sign_i * math.pi/2 - a -= math.pi/4 - r += 15 - x = offset_i + math.cos(a)*r - y = math.sin(a)*r - z = sign_i*h/2 - points.append((x, y, z)) + a = -sign_i * math.pi/2 + a -= math.pi/4 + r += 15 + x = offset_i + math.cos(a)*r + y = math.sin(a)*r + z = sign_i*h/2 + h_off + points.append((x, y, z)) - if i == len(radii)-1: - break + if i == len(radii)-1: + break - a -= math.pi/2 - x = offset_i + math.cos(a)*r - y = math.sin(a)*r - z = -sign_i*h/2 - points.append((x, y, z)) + a -= math.pi/2 + x = offset_i + math.cos(a)*r + y = math.sin(a)*r + z = -sign_i*h/2 + h_off + points.append((x, y, z)) - lens_cum = np.zeros(len(points)) - total = 0 - for i, (p1, p2) in enumerate(zip(points[:-1], points[1:])): - total += math.dist(p1, p2) - lens_cum[i+1] = total - lens_cum /= lens_cum[-1] - print(lens_cum) + lens_cum = np.zeros(len(points)) + total = 0 + for i, (p1, p2) in enumerate(zip(points[:-1], points[1:])): + total += math.dist(p1, p2) + lens_cum[i+1] = total + lens_cum /= lens_cum[-1] - points = scipy.interpolate.make_interp_spline(lens_cum, points)(np.linspace(0, 1, 500)) - f.write(', '.join(f'[{x:.3f},{y:.3f},{z:.3f}]' for x, y, z in points)) - print(f'wrote {len(points)} points') + points = scipy.interpolate.make_interp_spline(lens_cum, points)(np.linspace(0, 1, 500)) + + if out_stl: + with tempfile.NamedTemporaryFile('w', suffix='.scad') as f: + points_array = ', '.join(f'[{x:.3f},{y:.3f},{z:.3f}]' for x, y, z in points) + f.write(f''' + points = [{points_array}]; + + $fn = 17; + d = {wire_diameter}; + + rotate([0, 0, 270]) + for (i=[0:500-2]) + hull() {{ + translate(points[i]) sphere(d=d); + translate(points[i+1]) sphere(d=d); + }} + ''') + f.flush() + print(f'wrote {len(points)} points, rendering') + openscad = os.environ.get('OPENSCAD', 'openscad') + openscad_flags = os.environ.get('OPENSCAD_FLAGS', '').split() + subprocess.run([openscad, '-o', str(out_stl), *openscad_flags, f.name], check=True) tags.append(Tag('path', fill='none', stroke='magenta', stroke_width='0.5mm', stroke_linecap='round', stroke_linejoin='round', d='M ' + ' L '.join(f'{x:.3f},{y:.3f}' for x, y, z in points)))