shape#
Classes for common shapes and their manipulation.
- class Shape#
Bases:
object
- __init__(shape_func=<function Shape.<lambda>>)#
Base class for all shapes using constructive solid geometry (CSG). This mutable class holds and manipulates a given shape function.
- Parameters:
shape_func (Callable[[x,y,z], bool]) – Function returning True if (x,y,z) is within this shape.
- transform4(transform_matrix)#
Transform this shape according to a given 4x4 matrix, which can represent any affine transformation (rotate, scale, shear, translate). It is usually of the form [[R, T], [0, 1]], with R a 3x3 rotation matrix and T a 3x1 translation vector. Returns transformed self.
- transform3(transform_matrix)#
Transform this shape according to a given 3x3 matrix (rotate, scale, shear). Returns transformed self.
- transform(transform_matrix)#
Transform this shape according to a given 3x3 matrix (rotate, scale, shear) or 4x4 matrix (like 3x3 plus translations). It is usually of the form [[R, T], [0, 1]], with R a 3x3 rotation matrix and T a 3x1 translation vector. Returns transformed self.
- rotate_x(theta)#
Rotate this shape theta radians counter-clockwise around the x-axis.
- rotate_y(theta)#
Rotate this shape theta radians counter-clockwise around the y-axis.
- rotate_z(theta)#
Rotate this shape theta radians counter-clockwise around the z-axis.
- translate(dx, dy, dz)#
Translate this shape by the vector (dx,dy,dz).
- translate_x(dx)#
Translate this shape by dx along the x-axis.
- translate_y(dy)#
Translate this shape by dy along the y-axis.
- translate_z(dz)#
Translate this shape by dz along the z-axis.
- scale(sx, sy=None, sz=1)#
Scale this shape, using (0,0,0) as the origin. Takes 1, 2 or 3 arguments:
(s): scale by s in all directions.
(sx, sy): scale by sx and sy in the xy-plane, but do not scale z.
(sx, sy, sz): scale by sx, sy and sz in the x-, y- and z-direction respectively.
- mirror_xy()#
Mirror this shape with respect to the xy-plane.
- mirror_yz()#
Mirror this shape with respect to the yz-plane.
- mirror_zx()#
Mirror this shape with respect to the zx-plane.
- invert()#
Invert this shape (logical NOT).
- repeat(min_point, max_point)#
Infinitely repeat everything from this shape enclosed in a bounding box defined by the given minimum and maximum points, while everything outside this box is ignored.
- Parameters:
min_point (tuple[float] of size 3) – Smallest x, y and z coordinates of the bounding box (inclusive).
max_point (tuple[float] of size 3) – Largest x, y and z coordinates of the bounding box (exclusive).
direction. (Setting any coordinate to None will not repeat the shape in this)
- copy()#
Returns a new shape which is a copy of this shape.
- add(other)#
Add given shape to this shape (logical OR). Calling
a.add(b)
,a += b
ora |= b
is the same.- Parameters:
other (Shape)
- sub(other)#
Subtract given shape from this shape (logical AND NOT). Calling
a.sub(b)
ora -= b
is the same.- Parameters:
other (Shape)
- class Ellipsoid#
Bases:
Shape
- __init__(diamx, diamy, diamz)#
Ellipsoid with given diameters diamx, diamy, diamz.
- class Sphere#
Bases:
Ellipsoid
- __init__(diam=None, radius=None)#
Sphere with given diameter or radius.
- class Ellipse#
Bases:
Shape
- __init__(diamx, diamy)#
Ellipse in the xy-plane with given diameters diamx and diamy.
- class Cone#
Bases:
Shape
- __init__(diam, height)#
3D cone with the vertex down. It has a given diameter at a given height.
- class Cylinder#
Bases:
Shape
- __init__(diam, height)#
Cylinder along z with given diameter and height.
- class Cuboid#
Bases:
Shape
- __init__(sidex, sidey, sidez)#
3D rectangular slab with given sides, including minimum, excluding maximum.
- class Rectangle#
Bases:
Shape
- __init__(sidex, sidey)#
2D Rectangle in the xy-plane with given sides.
- class Torus#
Bases:
Shape
- __init__(major_diam, minor_diam)#
Torus with given major and minor diameters.
- Parameters:
major_diam (float) – Distance between opposite centers of the tube.
minor_diam (When major_diam =) – Diameter of the tube.
high. (The torus is major_diam + minor_diam wide and minor_diam)
minor_diam
hole. (there will be no)
- class DelaunayHull#
Bases:
Shape
- __init__(points)#
The Delaunay hull of a list of 3D points. These points can serve as the vertices of a convex polyhedron.
- Parameters:
points (ndarray of double, shape (npoints, 3))
- class Tetrahedron#
Bases:
DelaunayHull
- __init__(diam)#
Tetrahedron (4-faced platonic solid) where all vertices lie on a sphere with the given diameter.
- class Octahedron#
Bases:
Shape
- __init__(diam)#
Octahedron (8-faced platonic solid) where all vertices lie on a sphere with the given diameter.
- class Dodecahedron#
Bases:
DelaunayHull
- __init__(diam)#
Dodecahedron (12-faced platonic solid) where all vertices lie on a sphere with the given diameter.
- class Icosahedron#
Bases:
DelaunayHull
- __init__(diam)#
Dodecahedron (20-faced platonic solid) where all vertices lie on a sphere with the given diameter.
- class Icosidodecahedron#
Bases:
DelaunayHull
- __init__(diam)#
Icosidodecahedron where all vertices lie on a sphere with the given diameter.
- class Polygon#
Bases:
Shape
- __init__(vertices)#
A polygon in the xy-plane, with a given list of vertices.
- Parameters:
vertices (float ndarray of size (N, 2) or (N, 3)) – If the size is (N, 3), the z-values are simply ignored.
- class RegularPolygon#
Bases:
Polygon
- __init__(N, diam)#
A regular polygon in the xy-plane with N vertices which lie on a circle with given diameter. One point is located at (diam/2, 0).
- class ImageShape#
Bases:
Shape
- __init__(fname, min_point, max_point)#
Use a black and white image as a shape in the xy-plane. The given image file is stretched to the given coordinates. Black is inside the shape (True), white outside (False). Coordinates inside the stretched image assume the value of the nearest pixel. Coordinate outside the edges of the stretched image are treated as outside of the shape (False).
- Parameters:
fname (string) – Filename of the image to use.
min_point (tuple of length 2 or 3) – x and y world coordinates to be mapped to the center of the bottom left pixel of the image. z-coordinate can be given but is ignored.
max_point (tuple of length 2 or 3) – x and y world coordinates to be mapped to the center of the top right pixel of the image. z-coordinate can be given but is ignored.