mahautils.shapes.ClosedShape2D¶
- class mahautils.shapes.ClosedShape2D(default_num_coordinates: int | None = None, construction: bool = False, polygon_file_enclosed_conv: int = 1, units: str | None = None)¶
Bases:
Shape2DA class that represents a closed, two-dimensional shape
This class is intended to represent closed shapes (i.e., shapes for which any given point in space is either inside or outside the shape, or on the perimeter).
Attributes
Returns the area enclosed by the shape
Convention for considering enclosed area when generating a polygon file from
ClosedShape2DobjectsMethods
__init__([default_num_coordinates, ...])Creates an object representing a closed, 2D geometric shape
is_inside(point[, perimeter_is_inside])Returns whether a point is inside the shape
points([repeat_end])Returns a list containing discretized points around the perimeter of the shape
xy_coordinates([repeat_end])Generates Cartesian coordinates of the shape
Inherited 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
The units in which the geometry is defined
Inherited Methods
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
- __init__(default_num_coordinates: int | None = None, construction: bool = False, polygon_file_enclosed_conv: int = 1, units: str | None = None) None¶
Creates an object representing a closed, 2D geometric shape
Defines an object which represents a closed shape in the 2D Cartesian coordinate system.
- Parameters:
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)polygon_file_enclosed_conv (int, optional) – Convention for considering enclosed area when generating a polygon file from
ClosedShape2Dobjects (default is1)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 area: float¶
Returns the area enclosed by the shape
- property polygon_file_enclosed_conv: int¶
Convention for considering enclosed area when generating a polygon file from
ClosedShape2DobjectsThis property is exclusively intended for use when generating Maha Multics polygon files. As discussed on the Polygon File Format page, when generating Maha Multics polygon files, the
ENCLOSED_CONVoption can be set for any given closed shape to indicate whether the area inside the shape (as determined by the winding number algorithm) is considered by the polygon file to to be “enclosed” area. This property is designed to store the value of thisENCLOSED_CONVoption for anyClosedShape2Dobjects that are to be incorporated into a polygon file.Note
For more information about the interpretation of this option, refer to the Polygon File Format page.
- is_inside(point: List[float] | Tuple[float, float] | ndarray | CartesianPoint2D, perimeter_is_inside: bool = True) bool¶
Returns whether a point is inside the shape
- Parameters:
point (list or tuple or CartesianPoint2D) – The point whose location is to be checked. Must be either a
CartesianPoint2Dinstance, or a list or tuple containing two elements of typefloatperimeter_is_inside (bool, optional) – Whether to consider points on the perimeter of the shape to be inside the shape (default is
True)
- Returns:
If
perimeter_is_insideisTrue, returnsTrueifpointis inside the shape or on the perimeter, andFalseotherwise. Ifperimeter_is_insideisFalse, returnsTrueifpointis inside the shape but NOT on the perimeter, andFalseotherwise- Return type:
bool
- points(repeat_end: bool = False) 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.
- Parameters:
repeat_end (bool, optional) – Whether the first and last coordinate returned should be the same point (default is
False). This is useful, for instance, when plotting the shape with Matplotlib: ifrepeat_endis set toFalse, there may be a slight gap visible between the end points 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())
- xy_coordinates(repeat_end: bool = False) 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.
- Parameters:
repeat_end (bool, optional) – Whether the first and last coordinate returned should be the same point (default is
False). This is useful, for instance, when plotting the shape with Matplotlib: ifrepeat_endis set toFalse, there may be a slight gap visible between the end points of the shape
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())
- property construction¶
Whether the shape is a “construction shape” meant for visual display but not functional geometry
- property default_num_coordinates¶
The number of coordinates to use when representing a discretized form of the shape
- property is_closed¶
Whether the shape is bounded by a closed perimeter
- 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
- 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)
- property units: str | None¶
The units in which the geometry is defined