From 11210ce25a543875eb51cff8efc06e7f02984214 Mon Sep 17 00:00:00 2001 From: Anthony LaTorre Date: Wed, 17 Aug 2011 11:54:41 -0400 Subject: move useful bits from view.py into camera.py and get rid of view.py --- make.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'make.py') diff --git a/make.py b/make.py index 0375084..523b10f 100644 --- a/make.py +++ b/make.py @@ -6,7 +6,7 @@ from chroma.itertoolset import * def mesh_grid(grid): return np.vstack(zip(grid[:-1].flatten(),grid[1:].flatten(),np.roll(grid[1:],-1,1).flatten()) + zip(grid[:-1].flatten(),np.roll(grid[1:],-1,1).flatten(),np.roll(grid[:-1],-1,1).flatten())) -def linear_extrude(x1, y1, height, x2=None, y2=None): +def linear_extrude(x1, y1, height, x2=None, y2=None, center=None): """ 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` @@ -41,6 +41,9 @@ def linear_extrude(x1, y1, height, x2=None, y2=None): vertices = np.fromiter(flatten(roundrobin(*vertex_iterators)), float) vertices = vertices.reshape((len(vertices)//3,3)) + if center is not None: + vertices += center + triangles = mesh_grid(np.arange(len(vertices)).reshape((len(x1),len(vertices)//len(x1))).transpose()[::-1]) return Mesh(vertices, triangles, remove_duplicate_vertices=True) @@ -65,6 +68,10 @@ def rotate_extrude(x, y, nsteps=64): return Mesh(vertices, triangles, remove_duplicate_vertices=True) +def box(dx, dy, dz, center=(0,0,0)): + "Return a box with linear dimensions `dx`, `dy`, and `dz`." + return linear_extrude([-dx/2.0,dx/2.0,dx/2.0,-dx/2.0],[-dy/2.0,-dy/2.0,dy/2.0,dy/2.0],height=dz,center=center) + def cube(size=1, height=None): "Return a cube mesh whose sides have length `size`." if height is None: -- cgit