magnet.cell.Polygon#
- class magnet.cell.Polygon(nodes=None, mesh_vertices=None, faces=None)#
Bases:
Cell
Generic 2D polygonal cell.
Constructor
- __init__(nodes=None, mesh_vertices=None, faces=None) None #
Methods
area
()Compute the area of the polygon.
centroid
()Compute centroid coordinates of the polygon.
inscribed_diameter
([center])Compute the diameter of the inscribed circle of the cell.
Check if polygon vertices are ordered counterclockwise.
is_inside
(p)Check if a point is inside the polygon.
Compute the perimeter of the polygon.
Sort nodes of a polygon on the perimeter.
Compute the area and centroid of the polygon.
- area()#
Compute the area of the polygon.
- Parameters:
None
- Returns:
Area value.
- Return type:
float
- centroid() ndarray #
Compute centroid coordinates of the polygon.
- Parameters:
None
- Returns:
Array of shape (2,) corresponding to the centroid coordiantes.
- Return type:
np.ndarray of float
- inscribed_diameter(center: ndarray | None = None) float #
Compute the diameter of the inscribed circle of the cell.
Computes (approximately) the diameter of the biggest circle contained in the polygon.
- Parameters:
center (np.ndarray of flot, optional) – Center point of the circle for diameter computation. By default, uses the centroid of the polygon.
- Returns:
The diameter of the inscribed cirlce.
- Return type:
float
- is_counterclockwise()#
Check if polygon vertices are ordered counterclockwise.
- Parameters:
None
- Returns:
True if the vertices are ordered counterclockwise, False if clockwise.
- Return type:
bool
- is_inside(p: ndarray) bool #
Check if a point is inside the polygon.
- Parameters:
p (np.ndarray of float) – Point in question.
- Returns:
True if the point is inside the polygon, False otherwise.
- Return type:
bool
Notes
Uses ray casting method; the ray is cast in a random direction.
- perimeter() float #
Compute the perimeter of the polygon.
- Parameters:
None
- Returns:
Perimeter value.
- Return type:
float
- sort_nodes()#
Sort nodes of a polygon on the perimeter.
Reconstructs the order of nodes on the perimeter starting from the list of edges with arbitrary order. The resulting order can be either clockwise or counterclockwise. Updates Nodes attribute at the end.
- Parameters:
None
- Return type:
None
- volume_center()#
Compute the area and centroid of the polygon.
- Parameters:
None
- Returns:
volume (float) – The area of the polygon.
centroid (np.ndarray of float) – Centroid of the polygon.
Inherited Methods
__init__
([nodes, mesh_vertices, faces])