mahautils.shapes.CartesianPoint2D#
- class mahautils.shapes.CartesianPoint2D(*args: List[float] | Tuple[float, float] | ndarray | CartesianPoint2D | float, units: str | None = None, **kwargs)#
-
Class representing a point in 2D Cartesian coordinates
This class can be used to represent a point in the 2D Cartesian coordinate system. Note that although the axes for such a coordinate system can be arbitrary (\(xy\)-coordinates, \(xz\)-coordinates, etc.) in this class the axes are always referred to as \(x\) and \(y\) for simplicity and clarity.
Notes
The equality operator (
==) is defined for points. Points are considered equal if they are of the same type (Point,CartesianPoint2D, etc.), havecoordinatesattributes of the same shape and values, and have the same value ofunits.Examples
Create a
CartesianPoint2Dwith no location initialized:>>> print(mahautils.shapes.CartesianPoint2D()) ()
Create a
CartesianPoint2Dwith location specified by positional arguments:>>> print(mahautils.shapes.CartesianPoint2D(1, 2.3)) (1.0, 2.3) >>> print(mahautils.shapes.CartesianPoint2D([4, 5])) (4.0, 5.0) >>> pnt = mahautils.shapes.CartesianPoint2D([6, 7]) >>> print(mahautils.shapes.CartesianPoint2D(pnt)) (6.0, 7.0)
Create a
CartesianPoint2Dwith location specified by keyword arguments:>>> print(mahautils.shapes.CartesianPoint2D(x=1, y=2)) (1.0, 2.0)
Attributes
The coordinates of the point, represented as a tuple
(x, y)The x-coordinate of the point
The y-coordinate of the point
Methods
__init__(*args[, units])Defines a point in the 2D Cartesian coordinate system
distance_to(point)Computes the distance to another point
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
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
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
Reflects the shape over the \(x\)-axis
Reflects the shape over the \(y\)-axis
- __init__(*args: List[float] | Tuple[float, float] | ndarray | CartesianPoint2D | float, units: str | None = None, **kwargs)#
Defines a point in the 2D Cartesian coordinate system
Creates a
CartesianPoint2Dinstance and optionally allows the user to define the location of the point.- Parameters:
args (list or tuple or CartesianPoint2D or float, optional) – Positional arguments provided when creating the point object. See the “Notes” section for information on how to use positional arguments to specify the point location
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)kwargs (Any, optional) – Keyword arguments provided when creating the point object. See the “Notes” section for information on how to use keyword arguments to specify the point location
Notes
When creating a
CartesianPoint2Dinstance, it is possible to provide the point location using the constructor arguments. This location can be provided using either positional or keyword arguments, but not both.If providing the location using positional arguments, then any of the following may be specified: (1) two floating-point numbers; (2) a list, tuple, NumPy array, or any other array-like object containing two floating-point numbers; or (3) another
CartesianPoint2Dinstance.If providing the location using keyword arguments, then two keyword arguments must be specified:
xandy. Both arguments must be numeric types (integer or floating-point values).
- property coordinates#
The coordinates of the point, represented as a tuple
(x, y)
- property x#
The x-coordinate of the point
- property y#
The y-coordinate of the point
- 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
- distance_to(point: List[float] | Tuple[float, float] | ndarray | CartesianPoint2D)#
Computes the distance to another point
Calculates and returns the distance to another point in the same 2D Cartesian coordinate system.
- Parameters:
point (list or tuple or CartesianPoint2D) – The point to which to calculate distance
- Returns:
The distance to another location
pointin the 2D Cartesian plane- Return type:
float
- property is_closed#
Whether the shape is bounded by a closed perimeter
- 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
- 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
- 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())