mt.geo2d.rrect

A 2D rotated rectangle.

Functions

  • cast_RRect_to_Moments2d(): Undocumented.

  • approx_Moments2d_to_RRect(): Approximates a Moments2d instance with a RRect such that the mean aligns with the RRect’s center, and the covariance matrix of the instance is closest to the moment convariance matrix of the RRect.

mt.geo2d.rrect.cast_RRect_to_Moments2d(obj)
mt.geo2d.rrect.approx_Moments2d_to_RRect(obj)

Approximates a Moments2d instance with a RRect such that the mean aligns with the RRect’s center, and the covariance matrix of the instance is closest to the moment convariance matrix of the RRect.

Classes

  • RRect: A 2D rotated rectangle.

class mt.geo2d.rrect.RRect(signed_width: float, height: float, cx: float = 0.0, cy: float = 0.0, angle: float = 0.0)

A 2D rotated rectangle.

An RRect represents a 2D axis-aligned rectangle rotated by an angle. It is parametrised by center point, signed width, height and angle. Internally, an affine transformation is computed that transforms the unit square ‘[0,0,1,1]’ to the rotated rectangle. Signed width cannot be zero and height must be positive. Angle is in radian. Note that we do not care if the rectangle is open or partially closed or closed.

Parameters:
  • signed_width (float) – the signed width, meaning normal width if positive or width with left-right flipping if negative

  • height (float) – the height

  • cx (float) – the x-coordinate of the rectangle’s centroid

  • cy (float) – the y-coordinate of the rectangle’s centroid

  • angle (float) – the angle (in radian) at which the rectangle is rotated, the rotation direction is in the standard convention, from x-axis to y-axis

width

the actual (positive) width

Type:

float

center_pt

the rectangle’s centroid

Type:

point

tl

the transform of point (0,0)

Type:

point

br

the transform of point (1,1)

Type:

point

tr

the transform of point (0,1)

Type:

point

bl

the transform of point (1,0)

Type:

point

tfm

the 2D affine transformation turning unit square [0,0,1,1] into the given rectangle

Type:

mt.geo2d.Aff2d

corners

the four corners [tl,tr,bl,br] above

Type:

numpy.ndarray

area

the area

Type:

float

circumference

the circumference

Type:

float

sign

the sign of the rectangle

Type:

{-1,0,1,nan}

signed_area

the signed area

Type:

float

Notes

For more details, see this page. But note that we primarily use CV convention for images, top left is (0,0).

Inheritance

digraph inheritanced8961431b9 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "GeometricObject" [URL="../mt.geo/mt.geo.object.html#mt.geo.object.GeometricObject",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A geometric object which lives in a d-dimensional Euclidean space."]; "HasShapely" [URL="mt.geo2d.shapely.html#mt.geo2d.shapely.HasShapely",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Mixin to assert that the geometric object has the 'shapely' property."]; "RRect" [URL="#mt.geo2d.rrect.RRect",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A 2D rotated rectangle."]; "HasShapely" -> "RRect" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TwoD" -> "RRect" [arrowsize=0.5,style="setlinewidth(0.5)"]; "GeometricObject" -> "RRect" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TwoD" [URL="../mt.geo/mt.geo.object.html#mt.geo.object.TwoD",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Mixin to assert that the geometric object lives in 2D Euclidean space."]; }
__init__(signed_width: float, height: float, cx: float = 0.0, cy: float = 0.0, angle: float = 0.0)
__repr__()

Return repr(self).

property area

Absolute area.

property bl

The transform of point (0,1).

property br

The transform of point (1,1).

property circumference

Circumference.

static from_json(json_obj)

Creates a RRect from a JSON-like object.

Parameters:

json_obj (list) – list [signed_width, height, cx, cy, angle]

Returns:

output rotated rectangle

Return type:

RRect

left_square()

The interior square attaching to the left edge.

property moment1

First-order moment.

property moment2

Second-order moment.

property moment_x

Returns the integral of x over the rectangle’s interior.

property moment_xx

Returns the integral of x*x over the rectangle’s interior.

property moment_xy

Returns the integral of x*y over the rectangle’s interior.

property moment_y

Returns the integral of y over the rectangle’s interior.

property moment_yy

Returns the integral of y*y over the rectangle’s interior.

right_square()

The interior square attaching to the right edge.

property shapely

Shapely representation for fast intersection operations.

property signed_area

Signed area.

property tl

The transform of point (0,0).

to_json()

Returns a list [signed_width, height, cx, cy, angle].

to_tensor()

Returns a tensor [signed_width, height, cx, cy, angle] representing the RRect .

property tr

The transform of point (1,0).

property width

The actual (positive) width.