aerosandbox.geometry.polygon#

Module Contents#

Classes#

Polygon

Helper class that provides a standard way to create an ABC using

Attributes#

class aerosandbox.geometry.polygon.Polygon(coordinates)[source]#

Bases: aerosandbox.common.AeroSandboxObject

Helper class that provides a standard way to create an ABC using inheritance.

Parameters:

coordinates (aerosandbox.numpy.ndarray) –

__repr__()[source]#

Return repr(self).

x()[source]#

Returns the x coordinates of the polygon. Equivalent to Polygon.coordinates[:,0].

Returns:

X coordinates as a vector

Return type:

aerosandbox.numpy.ndarray

y()[source]#

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()[source]#

Returns the number of points/vertices/coordinates of the polygon.

Return type:

int

scale(scale_x=1.0, scale_y=1.0)[source]#

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

translate(translate_x=0.0, translate_y=0.0)[source]#

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

rotate(angle, x_center=0.0, y_center=0.0)[source]#

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

Returns: The rotated Polygon.

area()[source]#

Returns the area of the polygon.

Return type:

float

perimeter()[source]#

Returns the perimeter of the polygon.

Return type:

float

centroid()[source]#

Returns the centroid of the polygon as a 1D np.ndarray of length 2.

Return type:

aerosandbox.numpy.ndarray

Ixx()[source]#

Returns the nondimensionalized Ixx moment of inertia, taken about the centroid.

Iyy()[source]#

Returns the nondimensionalized Iyy moment of inertia, taken about the centroid.

Ixy()[source]#

Returns the nondimensionalized product of inertia, taken about the centroid.

J()[source]#

Returns the nondimensionalized polar moment of inertia, taken about the centroid.

write_sldcrv(filepath=None)[source]#

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)[source]#

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()[source]#

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)[source]#

Calculates the Jaccard similarity between this polygon and another polygon.

Note: This function is unfortunately not automatic-differentiable.

Parameters:

other (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)[source]#

Draws the Polygon on the current matplotlib axis.

Parameters:

Returns: None (draws on the current matplotlib axis)

aerosandbox.geometry.polygon.theta[source]#