X-Git-Url: https://scm.cri.ensmp.fr/git/linpy.git/blobdiff_plain/a8257bb17a1098f69625387a467170cac4b9f483..809c5b59db7b6be224146b8d957453a0f9fb43aa:/examples/menger.py?ds=sidebyside diff --git a/examples/menger.py b/examples/menger.py index dcba976..8d258b1 100755 --- a/examples/menger.py +++ b/examples/menger.py @@ -20,21 +20,22 @@ import matplotlib.pyplot as plt from math import ceil from matplotlib import pylab -from mpl_toolkits.mplot3d import Axes3D -from linpy import * +from linpy import Le, Polyhedron, symbols x, y, z = symbols('x y z') _x, _y, _z = x.asdummy(), y.asdummy(), z.asdummy() + def translate(domain, *, dx=0, dy=0, dz=0): domain &= Polyhedron([x - _x + dx, y - _y + dy, z - _z + dz]) domain = domain.project([x, y, z]) domain = domain.subs({_x: x, _y: y, _z: z}) return domain + def _menger(domain, size): result = domain result |= translate(domain, dx=0, dy=size, dz=0) @@ -58,6 +59,7 @@ def _menger(domain, size): result |= translate(domain, dx=2*size, dy=2*size, dz=2*size) return result + def menger(domain, count=1, cut=False): size = 1 for i in range(count): @@ -70,9 +72,11 @@ def menger(domain, count=1, cut=False): if __name__ == '__main__': parser = argparse.ArgumentParser( description='Compute a Menger sponge.') - parser.add_argument('-n', '--iterations', type=int, default=2, + parser.add_argument( + '-n', '--iterations', type=int, default=2, help='number of iterations (default: 2)') - parser.add_argument('-c', '--cut', action='store_true', default=False, + parser.add_argument( + '-c', '--cut', action='store_true', default=False, help='cut the sponge') args = parser.parse_args() cube = Le(0, x) & Le(x, 1) & Le(0, y) & Le(y, 1) & Le(0, z) & Le(z, 1)