Tried to parametrize gen_twisted_boundary

This commit is contained in:
Chris Hodapp 2019-10-10 01:37:49 +02:00
parent ea64900fef
commit 6b6d500d27
3 changed files with 49 additions and 33 deletions

View File

@ -18,14 +18,6 @@ To-do items, wanted features, bugs:
- Parametrize gen_twisted_boundary over boundaries and - Parametrize gen_twisted_boundary over boundaries and
do my nested spiral do my nested spiral
- Encode the notions of "generator which transforms an
existing list of boundaries", "generator which transforms
another generator"
- This has a lot of functions parametrized over a lot
of functions. Need to work with this somehow.
- Work directly with lists of boundaries. The only thing
I ever do with them is apply transforms to all of them, or
join adjacent ones with corresponding elements.
- Why do I get the weird zig-zag pattern on the triangles, - Why do I get the weird zig-zag pattern on the triangles,
despite larger numbers of them? Is it something in how I despite larger numbers of them? Is it something in how I
twist the frames? twist the frames?
@ -47,3 +39,16 @@ Other notes:
- Picking at random the diagonal on the quad to triangulate with - Picking at random the diagonal on the quad to triangulate with
does seem to turn 'error' just to noise, and in its own way this does seem to turn 'error' just to noise, and in its own way this
is preferable. is preferable.
# Abstractions
- Encode the notions of "generator which transforms an
existing list of boundaries", "generator which transforms
another generator"
- This has a lot of functions parametrized over a lot
of functions. Need to work with this somehow. (e.g. should
it subdivide this boundary? should it merge opening/closing
boundaries?)
- Work directly with lists of boundaries. The only thing
I ever do with them is apply transforms to all of them, or
join adjacent ones with corresponding elements.

View File

@ -161,7 +161,17 @@ def twist_nonlinear(dx0 = 2, dz=0.2, count=3, scale=0.99, layers=100):
return mesh return mesh
def twist_from_gen(): def twist_from_gen():
gen = meshgen.gen_inc_y(meshgen.gen_twisted_boundary()) b = numpy.array([
[0, 0, 0],
[1, 0, 0],
[1, 0, 1],
[0, 0, 1],
], dtype=numpy.float64) - [0.5, 0, 0.5]
b = meshutil.subdivide_boundary(b)
b = meshutil.subdivide_boundary(b)
b = meshutil.subdivide_boundary(b)
bs = [b]
gen = meshgen.gen_inc_y(meshgen.gen_twisted_boundary(bs))
mesh = meshgen.gen2mesh(gen, 100, True) mesh = meshgen.gen2mesh(gen, 100, True)
return mesh return mesh
@ -169,20 +179,21 @@ def twist_from_gen():
# turn = How many full turns to make in inner twist # turn = How many full turns to make in inner twist
# count = How many inner twists to have # count = How many inner twists to have
def twisty_torus(frames = 200, turns = 4, count = 4, rad = 4): def twisty_torus(frames = 200, turns = 4, count = 4, rad = 4):
b = numpy.array([
[0, 0, 0],
[1, 0, 0],
[1, 0, 1],
[0, 0, 1],
], dtype=numpy.float64) - [0.5, 0, 0.5]
b = meshutil.subdivide_boundary(b)
b = meshutil.subdivide_boundary(b)
b = meshutil.subdivide_boundary(b)
bs = [b]
# In order to make this line up properly: # In order to make this line up properly:
angle = numpy.pi * 2 * turns / frames angle = numpy.pi * 2 * turns / frames
gen = meshgen.gen_torus_xy(meshgen.gen_twisted_boundary(count=count, ang=angle), rad=rad, frames=frames) gen = meshgen.gen_torus_xy(meshgen.gen_twisted_boundary(bs=bs, count=count, ang=angle), rad=rad, frames=frames)
return meshgen.gen2mesh(gen, 0, flip_order=True, loop=True) return meshgen.gen2mesh(gen, 0, flip_order=True, loop=True)
# frames = How many step to build this from:
# turn = How many full turns to make in inner twist
# count = How many inner twists to have
def twisty_torus_opt(frames = 200, turns = 4, count = 4, rad = 4):
# In order to make this line up properly:
angle = numpy.pi * 2 * turns / frames
gen = meshgen.gen_torus_xy(meshgen.gen_twisted_boundary(count=count, ang=angle), rad=rad, frames=frames)
return meshgen.gen2mesh(gen, 0, flip_order=True, loop=True, join_fn=meshutil.join_boundary_optim)
def main(): def main():
fns = { fns = {
ram_horn: "ramhorn.stl", ram_horn: "ramhorn.stl",

View File

@ -6,32 +6,32 @@ import trimesh
# Generate a frame with 'count' boundaries in the XZ plane. # Generate a frame with 'count' boundaries in the XZ plane.
# Each one rotates by 'ang' as it moves by 'dz'. # Each one rotates by 'ang' as it moves by 'dz'.
# dx0 is center-point distance from each to the origin. # dx0 is center-point distance from each to the origin.
def gen_twisted_boundary(count=4, dx0=2, dz=0.2, ang=0.1): def gen_twisted_boundary(bs=None, count=4, dx0=2, dz=0.2, ang=0.1):
b = numpy.array([ if bs is None:
[0, 0, 0], b = numpy.array([
[1, 0, 0], [0, 0, 0],
[1, 0, 1], [1, 0, 0],
[0, 0, 1], [1, 0, 1],
], dtype=numpy.float64) - [0.5, 0, 0.5] [0, 0, 1],
b = meshutil.subdivide_boundary(b) ], dtype=numpy.float64) - [0.5, 0, 0.5]
b = meshutil.subdivide_boundary(b) b = meshutil.subdivide_boundary(b)
b = meshutil.subdivide_boundary(b) b = meshutil.subdivide_boundary(b)
b = meshutil.subdivide_boundary(b)
bs = [b]
# Generate 'seed' transformations: # Generate 'seed' transformations:
xfs = [meshutil.Transform().translate(dx0, 0, 0).rotate([0,1,0], numpy.pi * 2 * i / count) xfs = [meshutil.Transform().translate(dx0, 0, 0).rotate([0,1,0], numpy.pi * 2 * i / count)
for i in range(count)] for i in range(count)]
# (we'll increment the transforms in xfs as we go) # (we'll increment the transforms in xfs as we go)
while True: while True:
xfs_new = [] xfs_new = []
bs = []
for i, xf in enumerate(xfs): for i, xf in enumerate(xfs):
# Generate a boundary from running transform: # Generate a boundary from running transform:
b_i = xf.apply_to(b) bs2 = [xf.apply_to(b) for b in bs]
bs.append(b_i)
# Increment transform i: # Increment transform i:
xf2 = xf.rotate([0,1,0], ang) xf2 = xf.rotate([0,1,0], ang)
xfs_new.append(xf2) xfs_new.append(xf2)
xfs = xfs_new xfs = xfs_new
yield bs yield bs2
# This is to see how well it works to compose generators: # This is to see how well it works to compose generators:
def gen_inc_y(gen, dy=0.1): def gen_inc_y(gen, dy=0.1):