aerosandbox.geometry.polygon
Attributes
Classes
Polygon | Helper class that provides a standard way to create an ABC using |
Module Contents
class aerosandbox.geometry.polygon.Polygon(coordinates)
: Bases: aerosandbox.common.AeroSandboxObject
code
Helper class that provides a standard way to create an ABC using
inheritance.
Parameters:
: **coordinates** (*aerosandbox.numpy.ndarray*) –
coordinates
\_\_repr\_\_()
x()
: Returns the x coordinates of the polygon. Equivalent to Polygon.coordinates[:,0].
Returns:
: X coordinates as a vector
Return type:
: aerosandbox.numpy.ndarray
y()
: Returns the y coordinates of the polygon. Equivalent to Polygon.coordinates[:,1].
Returns:
: Y coordinates as a vector
Return type:
: aerosandbox.numpy.ndarray
n\_points()
: Returns the number of points/vertices/coordinates of the polygon.
Return type:
: int
scale(*scale\_x=1.0*, *scale\_y=1.0*)
: Scales a Polygon about the origin.
:param scale\_x: Amount to scale in the x-direction.
:param scale\_y: Amount to scale in the y-direction.
Returns: The scaled Polygon.
Parameters:
: - **scale\_x** (*float*) –
- **scale\_y** (*float*) –
Return type:
: [Polygon](#aerosandbox.geometry.polygon.Polygon)
translate(*translate\_x=0.0*, *translate\_y=0.0*)
: Translates a Polygon by a given amount.
:param translate\_x: Amount to translate in the x-direction
:param translate\_y: Amount to translate in the y-direction
Returns: The translated Polygon.
Parameters:
: - **translate\_x** (*float*) –
- **translate\_y** (*float*) –
Return type:
: [Polygon](#aerosandbox.geometry.polygon.Polygon)
rotate(*angle*, *x\_center=0.0*, *y\_center=0.0*)
: Rotates a Polygon clockwise by the specified amount, in radians.
Rotates about the point (x\_center, y\_center), which is (0, 0) by default.
Parameters:
: - **angle** (*float*) – Angle to rotate, counterclockwise, in radians.
- **x\_center** (*float*) – The x-coordinate of the center of rotation.
- **y\_center** (*float*) – The y-coordinate of the center of rotation.
Return type:
: [Polygon](#aerosandbox.geometry.polygon.Polygon)
Returns: The rotated Polygon.
area()
: Returns the area of the polygon.
Return type:
: float
perimeter()
: Returns the perimeter of the polygon.
Return type:
: float
centroid()
: Returns the centroid of the polygon as a 1D np.ndarray of length 2.
Return type:
: aerosandbox.numpy.ndarray
Ixx()
: Returns the nondimensionalized Ixx moment of inertia, taken about the centroid.
Iyy()
: Returns the nondimensionalized Iyy moment of inertia, taken about the centroid.
Ixy()
: Returns the nondimensionalized product of inertia, taken about the centroid.
J()
: Returns the nondimensionalized polar moment of inertia, taken about the centroid.
write\_sldcrv(*filepath=None*)
: Writes a .sldcrv (SolidWorks curve) file corresponding to this Polygon to a filepath.
Parameters:
: **filepath** (*str*) – A filepath (including the filename and .sldcrv extension) [string]
if None, this function returns the .sldcrv file as a string.
Returns: None
contains\_points(*x*, *y*)
: Returns a boolean array of whether some (x, y) point(s) are contained within the Polygon.
Note: This function is unfortunately not automatic-differentiable.
Parameters:
: - **x** (*Union**[**float**,* *aerosandbox.numpy.ndarray**]*) – x-coordinate(s) of the query points.
- **y** (*Union**[**float**,* *aerosandbox.numpy.ndarray**]*) – y-coordinate(s) of the query points.
Returns:
: A boolean array of the same size as x and y, with values corresponding to whether the points are
inside the Polygon.
Return type:
: Union[float, aerosandbox.numpy.ndarray]
as\_shapely\_polygon()
: Returns a Shapely Polygon object representing this polygon.
Shapely is a Python library for 2D geometry operations. While it is more powerful than this class (e.g.,
: allows for union/intersection calculation between Polygons), it is not automatic-differentiable.
jaccard\_similarity(*other*)
: Calculates the Jaccard similarity between this polygon and another polygon.
Note: This function is unfortunately not automatic-differentiable.
Parameters:
: **other** ([*Polygon*](#aerosandbox.geometry.polygon.Polygon)) – The other polygon to compare to.
Returns:
: The Jaccard similarity between this polygon and the other polygon.
: - 0 if the polygons are completely disjoint
- 1 if the polygons are identical
draw(*set\_equal=True*, *color=None*, *\*\*kwargs*)
: Draws the Polygon on the current matplotlib axis.
Parameters:
: - **set\_equal** – Whether to set the aspect ratio of the plot to be equal.
- **\*\*kwargs** – Keyword arguments to pass to the matplotlib.pyplot.fill function.
See: <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.fill.html>
Returns: None (draws on the current matplotlib axis)