Splines do the job.
This commit is contained in:
parent
0e122aa16e
commit
4b2fc71abe
2 changed files with 39 additions and 17 deletions
Binary file not shown.
|
|
@ -5,6 +5,8 @@ import textwrap
|
|||
import math
|
||||
from pathlib import Path
|
||||
import webbrowser
|
||||
import scipy
|
||||
import numpy as np
|
||||
|
||||
import click
|
||||
|
||||
|
|
@ -257,26 +259,46 @@ def cli(out_svg, out_txt, mesh_thickness, offset, mesh_space, mesh_width, start,
|
|||
points = [(0, 0, 0)]
|
||||
|
||||
radii.append(radii[-1] + 20)
|
||||
rt = 10
|
||||
dx = rt - offset
|
||||
n = 0
|
||||
e = 30
|
||||
h = 18
|
||||
with open(out_txt, 'w') as f:
|
||||
for i in range(steps):
|
||||
rp, rt = rt, (radii[i] + radii[i+1])/2
|
||||
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
|
||||
|
||||
for j in range(e):
|
||||
k = i + j/e
|
||||
a = k**0.85 * math.pi # - k/steps * math.pi * 0.3
|
||||
r = rp + (rt-rp)*j/e
|
||||
x = dx + offset - math.cos(a)*r
|
||||
y = math.sin(a)*r
|
||||
points.append((x, y))
|
||||
x = offset_i + math.cos(a)*r
|
||||
y = math.sin(a)*r
|
||||
z = sign_i*h/2
|
||||
points.append((x, y, z))
|
||||
|
||||
z = (math.cos(a/2 + 0.3*math.pi)**4) * 18
|
||||
f.write(f'[{x}, {y}, {z}],')
|
||||
n += 1
|
||||
print(f'wrote {n} points')
|
||||
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))
|
||||
|
||||
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))
|
||||
|
||||
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)
|
||||
|
||||
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')
|
||||
|
||||
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