WIP
This commit is contained in:
parent
4b2fc71abe
commit
d3d9253866
3 changed files with 60 additions and 37 deletions
Binary file not shown.
BIN
feedthrough1_mesh.FCStd
Normal file
BIN
feedthrough1_mesh.FCStd
Normal file
Binary file not shown.
|
|
@ -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)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue