mahautils.shapes.Shape2D#
- class mahautils.shapes.Shape2D(is_closed: bool, default_num_coordinates: int | None = None, construction: bool = False, units: str | None = None)#
Bases:
GeometryRepresents an arbitrary, two-dimensional shape
This class is intended to represent an arbitrary 2D shape. Note that the intended application for this class is to be used in a drawing utility, which is why attributes such as “construction” shapes are defined (these are a common feature of computer-aided design tools).
Attributes
Whether the shape is a "construction shape" meant for visual display but not functional geometry
The number of coordinates to use when representing a discretized form of the shape
Whether the shape is bounded by a closed perimeter
Methods
__init__(is_closed[, ...])Creates an object representing a 2D geometric shape
points()Returns a list containing discretized points around the perimeter of the shape
reflect(pntA, pntB)Reflects the shape across a line defined by two points
Reflects the shape over the \(x\)-axis
Reflects the shape over the \(y\)-axis
rotate(center, angle[, angle_units])Rotates the shape in the \(xy\)-plane
translate([x, y])Translates the shape in the \(xy\)-plane
Generates Cartesian coordinates of the shape
Inherited Attributes
The units in which the geometry is defined
- __init__(is_closed: bool, default_num_coordinates: int | None = None, construction: bool = False, units: str | None = None) None#
Creates an object representing a 2D geometric shape
Defines an object which represents a general shape and can return shape properties and the Cartesian coordinates of the (discretized) shape.
- Parameters:
is_closed (bool) – Whether the shape is bounded by a closed perimeter
default_num_coordinates (int, optional) – The default number of coordinates to use when representing the shape (default is
None)construction (bool, optional) – Whether the shape is a “construction shape” meant for visual display but not functional geometry (default is
False)units (str, optional) – The units in which the geometry is defined, or
Noneto indicate dimensionless geometry or that units are to be ignored (default isNone)
- property construction#
Whether the shape is a “construction shape” meant for visual display but not functional geometry
- property is_closed#
Whether the shape is bounded by a closed perimeter
- property default_num_coordinates#
The number of coordinates to use when representing a discretized form of the shape
- points() Tuple[ndarray, ...]#
Returns a list containing discretized points around the perimeter of the shape
This method returns a tuple, of which each element is a point along the perimeter of the shape.
See also
xy_coordinatesReturns the same coordinates as
xy_coordinates()except that points are returned as a list, where each entry is a point on the perimeter of the shape (essentially the transpose ofxy_coordinates())
- reflect(pntA: List[float] | Tuple[float, float] | ndarray | CartesianPoint2D, pntB: List[float] | Tuple[float, float] | ndarray | CartesianPoint2D) None#
Reflects the shape across a line defined by two points
- Parameters:
pntA (list or tuple or CartesianPoint2D) – One point on the line across which the shape is to be reflected
pntB (list or tuple or CartesianPoint2D) – Another point on the line across which the shape is to be reflected
- reflect_x()#
Reflects the shape over the \(x\)-axis
- reflect_y()#
Reflects the shape over the \(y\)-axis
- property units: str | None#
The units in which the geometry is defined
- rotate(center: List[float] | Tuple[float, float] | ndarray | CartesianPoint2D, angle: float, angle_units: str = 'rad') None#
Rotates the shape in the \(xy\)-plane
Rotates the shape the shape a given angle in the \(xy\)-plane about a user-specified point.
- Parameters:
center (list or tuple or CartesianPoint2D) – The center of rotation about which to rotate the shape
angle (float) – The angle by which to rotate the shape about
centerangle_units (str, optional) – The units (radians or degrees) of the
angleargument. Must be either'rad'or'deg'(default is'rad')
- translate(x: float = 0, y: float = 0) None#
Translates the shape in the \(xy\)-plane
Translates the shape a user-specified distance in the \(x\)- and/or \(y\)-directions.
- Parameters:
x (float, optional) – The distance to translate the shape in the \(x\)-direction (default is
0)y (float, optional) – The distance to translate the shape in the \(y\)-direction (default is
0)
- xy_coordinates() Tuple[ndarray, ndarray]#
Generates Cartesian coordinates of the shape
This method generates a set of discretized points around the perimeter of the shape. Points are returned as a tuple of two NumPy arrays: the first NumPy array contains the x-coordinates of the points, and the second NumPy array contains the y-coordinates. This format makes it relatively easy to plot the shape using packages like Matplotlib.
See also
pointsReturns the same coordinates as
xy_coordinates()except that points are returned with the x- and y-coordinates grouped for each point (essentially the transpose ofxy_coordinates())