diff options
author | Stan Seibert <stan@mtrr.org> | 2012-05-17 15:39:23 -0400 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2021-05-09 08:42:39 -0700 |
commit | 341892cf947e1a3c2faa39a6acb413817b838817 (patch) | |
tree | 09faf4975c2f9fd1d4f35c1ef8e668034121e5af | |
parent | 199f120666daf148c883f2380fede796af040630 (diff) | |
download | chroma-341892cf947e1a3c2faa39a6acb413817b838817.tar.gz chroma-341892cf947e1a3c2faa39a6acb413817b838817.tar.bz2 chroma-341892cf947e1a3c2faa39a6acb413817b838817.zip |
Add the ability to linear_extrude a mesh without the endcaps.
-rw-r--r-- | chroma/make.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/chroma/make.py b/chroma/make.py index 2f1d9a5..9c4c38f 100644 --- a/chroma/make.py +++ b/chroma/make.py @@ -19,12 +19,14 @@ def mesh_grid(grid): return mesh -def linear_extrude(x1, y1, height, x2=None, y2=None, center=None): +def linear_extrude(x1, y1, height, x2=None, y2=None, center=None, endcaps=True): """ Return the solid mesh formed by linearly extruding the polygon formed by the x and y points `x1` and `y1` by a distance `height`. If `x2` and `y2` are given extrude by connecting the points `x1` and `y1` to `x2` and `y2`; - this allows the creation of tapered solids. + this allows the creation of tapered solids. If `endcaps` is False, then + the triangles on the endcaps will be left off, and the mesh will not be + closed. .. note:: The path traced by the points `x` and `y` should go counter-clockwise, @@ -49,7 +51,12 @@ def linear_extrude(x1, y1, height, x2=None, y2=None, center=None): n = len(x1) - vertex_iterators = [izip(repeat(0,n),repeat(0,n),repeat(-height/2.0,n)),izip(x1,y1,repeat(-height/2.0,n)),izip(x2,y2,repeat(height/2.0,n)),izip(repeat(0,n),repeat(0,n),repeat(height/2.0,n))] + vertex_iterators = [izip(x1,y1,repeat(-height/2.0,n)), + izip(x2,y2,repeat(height/2.0,n))] + if endcaps: + vertex_iterators = [izip(repeat(0,n),repeat(0,n),repeat(-height/2.0,n))] \ + + vertex_iterators \ + + [izip(repeat(0,n),repeat(0,n),repeat(height/2.0,n))] vertices = np.fromiter(flatten(roundrobin(*vertex_iterators)), float) vertices = vertices.reshape((len(vertices)//3,3)) |