Skip to content

major_axis_angle

cellseg_gsontools.geometry.major_axis_angle(polygon)

Compute the major axis angle of a polygon.

Note

The major axis is the (x,y) endpoints of the longest line that can be drawn through the object. Major axis angle is the angle of the major axis with respect to the x-axis. - Wirth

Parameters:

Name Type Description Default
polygon Polygon

Input shapely polygon object.

required

Returns:

Name Type Description
float float

The angle of the major axis in degrees.

Source code in cellseg_gsontools/geometry/shape_metrics.py
def major_axis_angle(polygon: Polygon) -> float:
    """Compute the major axis angle of a polygon.

    Note:
        The major axis is the (x,y) endpoints of the longest line that
        can be drawn through the object. Major axis angle is the angle of
        the major axis with respect to the x-axis.
        - [Wirth](http://www.cyto.purdue.edu/cdroms/micro2/content/education/wirth10.pdf)

    Parameters:
        polygon (Polygon):
            Input shapely polygon object.

    Returns:
        float:
            The angle of the major axis in degrees.
    """
    mrr = polygon.minimum_rotated_rectangle.exterior.coords
    return axis_angle(mrr, "major")