Axis Aligned Rectangle
Axis Aligned Rectangle class
AxisAlignedRectangle
Bases: Rectangle
Axis Aligned Rectangle class that inherits from Rectangle. It defines a rectangle that is axis-aligned, meaning:
- its sides are parallel to the X and Y axes
- the first point is the top-left point (considering the y-axis pointing downwards)
- the points are ordered clockwise
Source code in otary/geometry/discrete/shape/axis_aligned_rectangle.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
area
property
Get the area of the AxisAlignedRectangle
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
area of the rectangle |
as_pymupdf_rect
property
Get the pymupdf representation of the given Rectangle. Beware a pymupdf can only be straight or axis-aligned.
See: https://pymupdf.readthedocs.io/en/latest/rect.html
Returns:
| Type | Description |
|---|---|
Rect
|
pymupdf.Rect: pymupdf axis-aligned Rect object |
height
property
Get the height of the AxisAlignedRectangle
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
height of the rectangle |
perimeter
property
Get the perimeter of the AxisAlignedRectangle
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
perimeter of the rectangle |
rotated90
property
Get the unique other related AxisAlignedRectangle that is the same one but rotated 90 degrees around its center.
Returns:
| Name | Type | Description |
|---|---|---|
AxisAlignedRectangle |
AxisAlignedRectangle
|
new AxisAlignedRectangle object |
width
property
Get the width of the AxisAlignedRectangle
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
width of the rectangle |
copy()
Create a copy of the AxisAlignedRectangle object.
Returns:
| Name | Type | Description |
|---|---|---|
AxisAlignedRectangle |
AxisAlignedRectangle
|
copy of the object |
Source code in otary/geometry/discrete/shape/axis_aligned_rectangle.py
from_center(center, width, height, is_cast_int=False)
classmethod
Create an AxisAlignedRectangle from a center point
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
NDArray
|
center point of the rectangle |
required |
width
|
float
|
width of the rectangle |
required |
height
|
float
|
height of the rectangle |
required |
is_cast_int
|
bool
|
cast the points coordinates to int |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
AxisAlignedRectangle |
AxisAlignedRectangle
|
new AxisAlignedRectangle object |
Source code in otary/geometry/discrete/shape/axis_aligned_rectangle.py
from_polygon(polygon)
classmethod
Create an AxisAlignedRectangle from any Polygon by computing its Axis Aligned Bounding Box (AABB). The resulting AxisAlignedRectangle will be the smallest axis-aligned rectangle that fully contains the input polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
Polygon | NDArray
|
Polygon object or array of points |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AxisAlignedRectangle |
AxisAlignedRectangle
|
AxisAlignedRectangle object |
Source code in otary/geometry/discrete/shape/axis_aligned_rectangle.py
from_rectangle(rectangle)
classmethod
Create an AxisAlignedRectangle from an ordinary Rectangle. Only works if the input Rectangle forms an AxisAlignedRectangle with its points.
If you want to create an AxisAlignedRectangle from any Rectangle, use the from_polygon method instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rectangle
|
Rectangle
|
Rectangle object |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AxisAlignedRectangle |
AxisAlignedRectangle
|
AxisAlignedRectangle object |
Source code in otary/geometry/discrete/shape/axis_aligned_rectangle.py
rotate(angle, is_degree=False, is_clockwise=True, pivot=None)
The in-place rotate method is not supported for AxisAlignedRectangle. Use the rotate_transform method instead.
Source code in otary/geometry/discrete/shape/axis_aligned_rectangle.py
rotate_transform(angle, is_degree=False, is_clockwise=True, pivot=None)
Rotate the AxisAlignedRectangle and transform it into a Rectangle. The result is a Rectangle object since the result is not guaranteed to be axis-aligned anymore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle
|
float
|
rotation angle |
required |
is_degree
|
bool
|
whether the angle is in degree or radian. Defaults to False which means radians. |
False
|
is_clockwise
|
bool
|
whether the rotation is clockwise or counter-clockwise. Defaults to True. |
True
|
pivot
|
NDArray
|
pivot point. Defaults to None which means that by default the centroid point of the shape is taken as the pivot point. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Rectangle |
Rectangle
|
object resulting from the rotation |
Example
The rotate method does not modify the original AxisAlignedRectangle object:
>>> rect = ot.AxisAlignedRectangle(points=[[0, 0], [4, 0], [4, 3], [0, 3]])
>>> rot_rect = rect.rotate(angle=45, is_degree=True)
>>> rot_rect.asarray
array([[ 1.6464466 , -0.9748737 ],
[ 4.4748735 , 1.8535534 ],
[ 2.3535533 , 3.9748738 ],
[-0.47487372, 1.1464466 ]], dtype=float32)
>>> rect
array([[0, 0],
[4, 0],
[4, 3],
[0, 3]], dtype=int32)