diff --git a/README.md b/README.md index f189312..2613286 100644 --- a/README.md +++ b/README.md @@ -18,14 +18,6 @@ To-do items, wanted features, bugs: - Parametrize gen_twisted_boundary over boundaries and 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, despite larger numbers of them? Is it something in how I twist the frames? @@ -47,3 +39,16 @@ Other notes: - 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 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. diff --git a/examples.py b/examples.py index eaabb4a..96b167e 100755 --- a/examples.py +++ b/examples.py @@ -161,7 +161,17 @@ def twist_nonlinear(dx0 = 2, dz=0.2, count=3, scale=0.99, layers=100): return mesh 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) return mesh @@ -169,20 +179,21 @@ def twist_from_gen(): # turn = How many full turns to make in inner twist # count = How many inner twists to have 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: 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) -# 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(): fns = { ram_horn: "ramhorn.stl", diff --git a/meshgen.py b/meshgen.py index 17acd81..26df4ed 100644 --- a/meshgen.py +++ b/meshgen.py @@ -6,32 +6,32 @@ import trimesh # Generate a frame with 'count' boundaries in the XZ plane. # Each one rotates by 'ang' as it moves by 'dz'. # dx0 is center-point distance from each to the origin. -def gen_twisted_boundary(count=4, dx0=2, dz=0.2, ang=0.1): - 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) +def gen_twisted_boundary(bs=None, count=4, dx0=2, dz=0.2, ang=0.1): + if bs is None: + 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] # Generate 'seed' transformations: xfs = [meshutil.Transform().translate(dx0, 0, 0).rotate([0,1,0], numpy.pi * 2 * i / count) for i in range(count)] # (we'll increment the transforms in xfs as we go) while True: xfs_new = [] - bs = [] for i, xf in enumerate(xfs): # Generate a boundary from running transform: - b_i = xf.apply_to(b) - bs.append(b_i) + bs2 = [xf.apply_to(b) for b in bs] # Increment transform i: xf2 = xf.rotate([0,1,0], ang) xfs_new.append(xf2) xfs = xfs_new - yield bs + yield bs2 # This is to see how well it works to compose generators: def gen_inc_y(gen, dy=0.1):