Commit 9a687f26 authored by pacome's avatar pacome
Browse files

Add box function to create the corners of 2d and3d box

parent dd25dc23
......@@ -820,6 +820,62 @@ class InHull(Shape):
def box(length, corner=None, center=None):
Returns points of a 2d of 3d box
length = (Lx, Ly, Lz): numbers
the lengths of the sides
if Ly (Lz) is None, Ly (Lz) will be equal to Lx
(usefull to quickly draw cubes)
corner = (x0, y0, z0) : numbers
the lower left corner of the (if z0 si None will be 2d)
center = (x0, y0, z0) : numbers
overwrites the corner argument
if center=None the corner will be used
the lower left corner of the (if z0 si None will be 2d)
points: np.ndarray
the points defining the box
if isinstance(length, (int, float)):
length = (length, length)
length = np.asarray(length)
ndim = len(length)
if corner is None:
corner = np.zeros(ndim)
elif isinstance(corner, int):
corner = corner * np.ones(ndim)
corner = np.asarray(corner)
if center is not None:
center = np.asarray(center)
assert len(length) == len(corner), (
'The corner does not have the same'
+ ' size as length / or a corner has'
+ ' been given and length is an int')
points = np.array([[0, 0], [0, length[1]], length[:2], [length[0], 0]])
if ndim == 3:
points = np.vstack((np.c_[points, np.zeros(4)], np.c_[points, np.ones(4) * length[2]]))
if center is None:
points = points + corner
points = points - length / 2 + center
return points
def translate(x, vect):
Translate a point or a list of points by a vector vect
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment