Geometry
The geometry
module provides a comprehensive set of tools for working with geometric shapes and entities. It follows an inheritance-based design, where more complex shapes are derived from simpler ones.
Core Concepts
The geometry
module is organized into two main categories:
- Continuous: Represents shapes that are defined by continuous mathematical functions, such as circles and ellipses.
- Discrete: Represents shapes that are defined by a finite set of points, such as polygons and line segments.
Available Modules
Below is a list of available modules and their functionalities:
Base Geometry
GeometryEntity module which allows to define transformation and property shared by all type of geometry objects
GeometryEntity
Bases: ABC
GeometryEntity class which is the abstract base class for all geometry classes
Source code in otary/geometry/entity.py
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 |
|
area
abstractmethod
property
Compute the area of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
area value |
centroid
abstractmethod
property
Compute the centroid point which can be seen as the center of gravity of the shape
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
centroid point |
perimeter
abstractmethod
property
Compute the perimeter of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
perimeter value |
shapely_edges
abstractmethod
property
Representation of the geometric object in the shapely library as a geometrical object defined only as a curve with no area. Particularly useful to look for points intersections
shapely_surface
abstractmethod
property
Representation of the geometric object in the shapely library as a geometrical object with an area and a border. Particularly useful to check if two geometrical objects are contained within each other or not.
xmax
abstractmethod
property
Get the maximum X coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
xmin
abstractmethod
property
Get the minimum X coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
ymax
abstractmethod
property
Get the maximum Y coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
ymin
abstractmethod
property
Get the minimum Y coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
copy()
abstractmethod
Create a copy of the geometry entity object
Returns:
Name | Type | Description |
---|---|---|
GeometryEntity |
Self
|
copy of the geometry entity object |
enclosing_axis_aligned_bbox()
abstractmethod
Compute the smallest area enclosing Axis-Aligned Bounding Box (AABB) See: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Rectangle
|
Rectangle object |
Source code in otary/geometry/entity.py
enclosing_convex_hull()
abstractmethod
Compute the smallest area enclosing Convex Hull See: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
Polygon object |
enclosing_oriented_bbox()
abstractmethod
Compute the smallest area enclosing Oriented Bounding Box (OBB) See: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Rectangle
|
Rectangle object |
Source code in otary/geometry/entity.py
intersection(other, only_points=True)
Compute the intersections between two geometric objects. If the only_points parameter is True, then we only consider intersection points as valid. We can not have another type of intersection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
GeometryEntity
|
other GeometryEntity object |
required |
only_points
|
bool
|
whether to consider only points. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
list of n points of shape (n, 2) |
Source code in otary/geometry/entity.py
normalize(x, y)
abstractmethod
Normalize the geometry entity by dividing the points by a norm on the x and y coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
x coordinate norm |
required |
y
|
float
|
y coordinate norm |
required |
Returns:
Name | Type | Description |
---|---|---|
GeometryEntity |
Self
|
normalized GeometryEntity |
Source code in otary/geometry/entity.py
rotate(angle, is_degree=False, is_clockwise=True, pivot=None)
abstractmethod
Rotate the geometry entity object. A pivot point can be passed as an argument to rotate the object around the pivot
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 |
---|---|---|
GeometryEntity |
Self
|
rotated geometry entity object. |
Source code in otary/geometry/entity.py
shift(vector)
abstractmethod
Shift the geometry entity by the vector direction
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector
|
NDArray
|
vector that describes the shift as a array with two elements. Example: [2, -8] which describes the vector [[0, 0], [2, -8]]. The vector can also be a vector of shape (2, 2) of the form [[2, 6], [1, 3]]. |
required |
Returns:
Name | Type | Description |
---|---|---|
GeometryEntity |
Self
|
shifted geometrical object |
Source code in otary/geometry/entity.py
Continuous Geometry
ContinuousGeometryEntity module class
ContinuousGeometryEntity
Bases: GeometryEntity
, ABC
ContinuousGeometryEntity class which is the abstract base class for continuous or smooth geometry objects like circles, ellipse, etc...
Source code in otary/geometry/continuous/entity.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 |
|
n_points_polygonal_approx
property
writable
Get the number of points for the polygonal approximation.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The number of points used in the polygonal approximation. |
polyaprox
property
Generate a polygonal approximation of the continuous geometry entity.
Beware: No setter is defined for this property as it is a read-only property.
You can update the polygonal approximation using the method named
update_polyapprox
.
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
polygonal approximation of the continuous geometry entity |
xmax
property
Get the maximum X coordinate of the geometry entity
Returns:
Type | Description |
---|---|
float
|
np.ndarray: 2D point |
xmin
property
Get the minimum X coordinate of the geometry entity
Returns:
Type | Description |
---|---|
float
|
np.ndarray: 2D point |
ymax
property
Get the maximum Y coordinate of the geometry entity
Returns:
Type | Description |
---|---|
float
|
np.ndarray: 2D point |
ymin
property
Get the minimum Y coordinate of the geometry entity
Returns:
Type | Description |
---|---|
float
|
np.ndarray: 2D point |
__init__(n_points_polygonal_approx=DEFAULT_N_POLY_APPROX)
Initialize a ContinuousGeometryEntity object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_points_polygonal_approx
|
int
|
n points to be used in the polygonal approximation. Defaults to DEFAULT_N_POINTS_POLYGONAL_APPROX. |
DEFAULT_N_POLY_APPROX
|
Source code in otary/geometry/continuous/entity.py
curvature(point)
abstractmethod
Curvature at the point defined as parameter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
input point. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
description |
enclosing_axis_aligned_bbox()
Compute the smallest area enclosing Axis-Aligned Bounding Box (AABB) See: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Rectangle
|
Rectangle object |
Source code in otary/geometry/continuous/entity.py
enclosing_convex_hull()
Compute the smallest area enclosing Convex Hull See: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
Polygon object |
Source code in otary/geometry/continuous/entity.py
enclosing_oriented_bbox()
Compute the smallest area enclosing Oriented Bounding Box (OBB) See: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Rectangle
|
Rectangle object |
Source code in otary/geometry/continuous/entity.py
polygonal_approx(n_points, is_cast_int)
abstractmethod
Generate a polygonal approximation of the continuous geometry entity
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_points
|
int
|
number of points that make up the polygonal approximation. The bigger the better to obtain more precise results in intersection or other similar computations. |
required |
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
polygonal approximation of the continuous geometry entity |
Source code in otary/geometry/continuous/entity.py
update_polyapprox()
Update the polygonal approximation of the continuous geometry entity
Source code in otary/geometry/continuous/entity.py
Shape
Circle Geometric Object
Circle
Bases: Ellipse
Circle geometrical object
Source code in otary/geometry/continuous/shape/circle.py
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 253 254 255 256 257 258 259 |
|
centroid
property
Center of the circle
Returns:
Name | Type | Description |
---|---|---|
float |
NDArray
|
center 2D point |
is_circle
property
Check if the circle is a circle
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if circle else False |
perimeter
property
Perimeter of the circle
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
perimeter value |
shapely_edges
property
Returns the Shapely.LinearRing as a curve representation of the Circle. See https://shapely.readthedocs.io/en/stable/reference/shapely.LinearRing.html
Returns:
Name | Type | Description |
---|---|---|
LinearRing |
LinearRing
|
shapely.LinearRing object |
shapely_surface
property
Returns the Shapely.Polygon as an surface representation of the Circle. See https://shapely.readthedocs.io/en/stable/reference/shapely.Polygon.html
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
shapely.Polygon object |
xmax
property
Get the maximum X coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
xmin
property
Get the minimum X coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
ymax
property
Get the maximum Y coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
ymin
property
Get the minimum Y coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
__init__(center, radius, n_points_polygonal_approx=ContinuousGeometryEntity.DEFAULT_N_POLY_APPROX)
Initialize a Circle geometrical object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center
|
NDArray
|
center 2D point |
required |
radius
|
float
|
radius value |
required |
n_points_polygonal_approx
|
int
|
number of points to be used in the polygonal approximation of the circle. Defaults to ContinuousGeometryEntity.DEFAULT_N_POINTS_POLYGONAL_APPROX. |
DEFAULT_N_POLY_APPROX
|
Source code in otary/geometry/continuous/shape/circle.py
copy()
Copy the circle object
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
copied circle object |
Source code in otary/geometry/continuous/shape/circle.py
curvature(point=None)
Curvature of circle is a constant and does not depend on a position of a point
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
curvature value |
normalize(x, y)
Normalize the circle by dividing the points by a norm on the x and y coordinates. This does not change the circle radius.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
x coordinate norm |
required |
y
|
float
|
y coordinate norm |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
normalized circle object |
Source code in otary/geometry/continuous/shape/circle.py
polygonal_approx(n_points, is_cast_int=False)
Generate a Polygon object that is an approximation of the circle as a discrete geometrical object made up of only points and segments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_points
|
int
|
number of points that make up the circle polygonal approximation |
required |
is_cast_int
|
bool
|
whether to cast to int the points coordinates or not. Defaults to False |
False
|
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
Polygon representing the circle as a succession of n points |
Source code in otary/geometry/continuous/shape/circle.py
rotate(angle, is_degree=False, is_clockwise=True, pivot=None)
Rotate the circle around a pivot point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
float
|
angle by which to rotate the circle |
required |
is_degree
|
bool
|
whether the angle is in degrees. Defaults to False. |
False
|
is_clockwise
|
bool
|
whether the rotation is clockwise. Defaults to True. |
True
|
pivot
|
Optional[NDArray]
|
pivot point around which to rotate. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
rotated circle object |
Source code in otary/geometry/continuous/shape/circle.py
shift(vector)
Shift the circle by a given vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector
|
NDArray
|
2D vector by which to shift the circle |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
shifted circle object |
Source code in otary/geometry/continuous/shape/circle.py
Ellipse Geometric Object
Ellipse
Bases: ContinuousGeometryEntity
Ellipse geometrical object
Source code in otary/geometry/continuous/shape/ellipse.py
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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
area
property
Compute the area of the ellipse
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
area value |
centroid
property
Compute the center point of the ellipse
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
2D point defining the center of the ellipse |
eccentricity
property
Eccentricity value of the ellipse
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
eccentricity value |
focal_distance
property
Distance from any focal point to the center
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
focal distance value |
h
property
h is a common ellipse value used in calculation and kind of represents the eccentricity of the ellipse but in another perspective.
Circle would have a h = 0. A really stretch out ellipse would have a h value close o 1
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
h value |
is_circle
property
Check if the ellipse is a circle
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if circle else False |
linear_eccentricity
property
Distance from any focal point to the center
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
linear eccentricity value |
perimeter
property
Compute the perimeter of the ellipse. Beware this is only an approximation due to the computation of both pi and the James Ivory's infinite serie.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
perimeter value |
semi_minor_axis
property
Computed semi minor axis (also called b usually)
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
description |
shapely_edges
property
Returns the Shapely.LinearRing as a curve representation of the Ellipse. See https://shapely.readthedocs.io/en/stable/reference/shapely.LinearRing.html
Returns:
Name | Type | Description |
---|---|---|
LinearRing |
LinearRing
|
shapely.LinearRing object |
shapely_surface
property
Returns the Shapely.Polygon as an surface representation of the Ellipse. See https://shapely.readthedocs.io/en/stable/reference/shapely.Polygon.html
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
shapely.Polygon object |
__assert_ellipse()
Assert the parameters of the ellipse. If the parameters proposed do not make up a ellipse raise an error.
Source code in otary/geometry/continuous/shape/ellipse.py
__init__(foci1, foci2, semi_major_axis, n_points_polygonal_approx=ContinuousGeometryEntity.DEFAULT_N_POLY_APPROX)
Initialize a Ellipse geometrical object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
foci1
|
NDArray | list
|
first focal 2D point |
required |
foci2
|
NDArray | list
|
second focal 2D point |
required |
semi_major_axis
|
float
|
semi major axis value |
required |
n_points_polygonal_approx
|
int
|
number of points to be used in the polygonal approximation. Defaults to ContinuousGeometryEntity.DEFAULT_N_POINTS_POLYGONAL_APPROX. |
DEFAULT_N_POLY_APPROX
|
Source code in otary/geometry/continuous/shape/ellipse.py
angle(degree=False, is_y_axis_down=False)
Angle of the ellipse
Parameters:
Name | Type | Description | Default |
---|---|---|---|
degree
|
bool
|
whether to output angle in degree, Defaults to False meaning radians. |
False
|
is_y_axis_down
|
bool
|
whether the y axis is down. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
angle value |
Source code in otary/geometry/continuous/shape/ellipse.py
copy()
Copy the current ellipse object
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
copied ellipse object |
Source code in otary/geometry/continuous/shape/ellipse.py
curvature(point)
Computes the curvature of a point on the ellipse.
Equation is based on the following where a is semi major and b is minor axis.
\kappa = \frac{1}{a^2 b^2} \left( \frac{x^2}{a^4} + \frac{y^2}{b^4} \right)^{-\frac{3}{2}}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
point on the ellipse |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
curvature of the point |
Source code in otary/geometry/continuous/shape/ellipse.py
enclosing_oriented_bbox()
Enclosing oriented bounding box. Manage the case where the ellipse is a circle and return the enclosing axis-aligned bounding box in that case.
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Enclosing oriented bounding box |
Source code in otary/geometry/continuous/shape/ellipse.py
normalize(x, y)
Normalize the ellipse to a given bounding box.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
width of the bounding box |
required |
y
|
float
|
height of the bounding box |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
normalized ellipse object |
Source code in otary/geometry/continuous/shape/ellipse.py
perimeter_approx(n_terms=5, is_ramanujan=False)
Perimeter approximation of the ellipse using the James Ivory infinite serie. In the case of the circle this always converges to the exact value of the circumference no matter the number of terms.
See: https://en.wikipedia.org/wiki/Ellipse#Circumference
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_terms
|
int
|
number of n first terms to calculate and add up from the infinite series. Defaults to 5. |
5
|
is_ramanujan
|
bool
|
whether to use the Ramanujan's best approximation. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
circumference approximation of the ellipse |
Source code in otary/geometry/continuous/shape/ellipse.py
polygonal_approx(n_points, is_cast_int=False)
Generate apolygonal approximation of the ellipse.
The way is done is the following: 1. suppose the ellipse centered at the origin 2. suppose the ellipse semi major axis to be parallel with the x-axis 3. compute pairs of (x, y) points that belong to the ellipse using the parametric equation of the ellipse. 4. shift all points by the same shift as the center to origin 5. rotate using the ellipse center pivot point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_points
|
int
|
number of points that make up the ellipse polygonal approximation |
required |
is_cast_int
|
bool
|
whether to cast to int the points coordinates or not. Defaults to False |
False
|
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
Polygon representing the ellipse as a succession of n points |
Source code in otary/geometry/continuous/shape/ellipse.py
rotate(angle, is_degree=False, is_clockwise=True, pivot=None)
Rotate the ellipse around a pivot point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
float
|
angle to rotate the ellipse |
required |
is_degree
|
bool
|
whether the angle is in degrees. Defaults to False. |
False
|
is_clockwise
|
bool
|
whether the rotation is clockwise. Defaults to True. |
True
|
pivot
|
Optional[NDArray]
|
pivot point to rotate around. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
rotated ellipse object |
Source code in otary/geometry/continuous/shape/ellipse.py
shift(vector)
Shift the ellipse by a given vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector
|
NDArray
|
vector to shift the ellipse |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
shifted ellipse object |
Source code in otary/geometry/continuous/shape/ellipse.py
Discrete Geometry
DiscreteGeometryEntity module class
DiscreteGeometryEntity
Bases: GeometryEntity
, ABC
GeometryEntity class which is the abstract base class for all geometry classes
Source code in otary/geometry/discrete/entity.py
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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
asarray
property
writable
Array representation of the geometry object
center_mean
property
Compute the center as the mean of all the points. This can be really different than the centroid.
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
center mean as a 2D point |
centroid
abstractmethod
property
Compute the centroid point which can be seen as the center of gravity or center of mass of the shape
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
centroid point |
crop_coordinates
property
Compute the coordinates of the geometry entity in the context of itself being in a crop image that make it fit pefectly
Returns:
Name | Type | Description |
---|---|---|
Self |
NDArray
|
description |
edges
abstractmethod
property
Get the edges of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
edges of the geometry entity |
lengths
property
Returns the length of all the segments that make up the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
array of shape (n_points) |
n_points
property
Returns the number of points this geometric object is made of
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
number of points that composes the geomtric object |
segments
property
Get the segments of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
list[Segment]
|
segments of the geometry entity |
shapely_edges
abstractmethod
property
Representation of the geometric object in the shapely library as a geometrical object defined only as a curve with no area. Particularly useful to look for points intersections
shapely_surface
abstractmethod
property
Representation of the geometric object in the shapely library as a geometrical object with an area and a border. Particularly useful to check if two geometrical objects are contained within each other or not.
xmax
property
Get the maximum X coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
xmin
property
Get the minimum X coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
ymax
property
Get the maximum Y coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
ymin
property
Get the minimum Y coordinate of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
NDArray |
float
|
2D point |
clamp(xmin=-np.inf, xmax=np.inf, ymin=-np.inf, ymax=np.inf)
Clamp the Geometry entity so that the x and y coordinates fit in the min and max values in parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xmin
|
float
|
x coordinate minimum |
-inf
|
xmax
|
float
|
x coordinate maximum |
inf
|
ymin
|
float
|
y coordinate minimum |
-inf
|
ymax
|
float
|
y coordinate maximum |
inf
|
Returns:
Name | Type | Description |
---|---|---|
GeometryEntity |
Self
|
clamped GeometryEntity |
Source code in otary/geometry/discrete/entity.py
copy()
Create a copy of the geometry entity object
Returns:
Name | Type | Description |
---|---|---|
GeometryEntity |
Self
|
copy of the geometry entity object |
distances_vertices_to_point(point)
Get the distance from all vertices in the geometry entity to the input point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
2D point |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
array of the same len as the number of vertices in the geometry entity. |
Source code in otary/geometry/discrete/entity.py
enclosing_axis_aligned_bbox()
Compute the smallest area enclosing Axis-Aligned Bounding Box (AABB) See: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html
Return the points in the following order: 1. top left 2. top right 3. bottom right 4. bottom left
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Rectangle
|
Rectangle object |
Source code in otary/geometry/discrete/entity.py
enclosing_convex_hull()
Compute the smallest area enclosing Convex Hull See: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
Polygon object |
Source code in otary/geometry/discrete/entity.py
enclosing_oriented_bbox()
Compute the smallest area enclosing Oriented Bounding Box (OBB) See: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Rectangle
|
Rectangle object |
Source code in otary/geometry/discrete/entity.py
find_shared_approx_vertices(other, margin_dist_error=5)
Get the shared vertices between two geometric objects.
A vertice is considered shared if it is close enough to another vertice in the other geometric structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
DiscreteGeometryEntity
|
a DiscreteGeometryEntity object |
required |
margin_dist_error
|
float
|
the threshold to define a vertice as shared or not. Defaults to 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
list of vertices identified as shared between the two geometric objects |
Source code in otary/geometry/discrete/entity.py
find_shared_approx_vertices_ix(other, margin_dist_error=5)
Compute the vertices indices from this entity that correspond to shared vertices with the other geometric entity.
A vertice is considered shared if it is close enough to another vertice in the other geometric structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
DiscreteGeometryEntity
|
other Discrete Geometry entity |
required |
margin_dist_error
|
float
|
minimum distance to have two vertices considered as close enough to be shared. Defaults to 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
list of indices |
Source code in otary/geometry/discrete/entity.py
find_vertice_ix_closest_from(point)
Get the index of the closest vertice from a given point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
2D point |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
the index of the closest point in the entity from the input point |
Source code in otary/geometry/discrete/entity.py
find_vertice_ix_farthest_from(point)
Get the index of the farthest vertice from a given point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
2D point |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
the index of the farthest vertice in the entity from the input point |
Source code in otary/geometry/discrete/entity.py
find_vertices_far_from(points, min_distance=5)
Get vertices that belongs to the geometric structure far from the points in parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
NDArray
|
input list of points |
required |
min_distance
|
float
|
the threshold to define a point as far enough or not from a vertice. Defaults to 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
vertices that belongs to the geometric structure and that are far from the input points. |
Source code in otary/geometry/discrete/entity.py
longest_dist_vertices_to_point(point)
Compute the longest distance from the geometry entity vertices to the point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
2D point |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
longest distance from the geometry entity vertices to the point |
Source code in otary/geometry/discrete/entity.py
normalize(x, y)
Normalize the geometry entity by dividing the points by a norm on the x and y coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
x coordinate norm |
required |
y
|
float
|
y coordinate norm |
required |
Returns:
Name | Type | Description |
---|---|---|
GeometryEntity |
Self
|
normalized GeometryEntity |
Source code in otary/geometry/discrete/entity.py
rotate(angle, is_degree=False, is_clockwise=True, pivot=None)
Rotate the geometry entity object. A pivot point can be passed as an argument to rotate the object around the pivot
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 |
---|---|---|
GeometryEntity |
Self
|
rotated geometry entity object. |
Source code in otary/geometry/discrete/entity.py
rotate_around_image_center(img, angle, degree=False)
Given an geometric object and an image, rotate the object around the image center point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
NDArray
|
image as a shape (x, y) sized array |
required |
angle
|
float
|
rotation angle |
required |
degree
|
bool
|
whether the angle is in degree or radian. Defaults to False which means radians. |
False
|
Returns:
Name | Type | Description |
---|---|---|
GeometryEntity |
Self
|
rotated geometry entity object. |
Source code in otary/geometry/discrete/entity.py
shift(vector)
Shift the geometry entity by the vector direction
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector
|
NDArray
|
vector that describes the shift as a array with two elements. Example: [2, -8] which describes the vector [[0, 0], [2, -8]]. The vector can also be a vector of shape (2, 2) of the form [[2, 6], [1, 3]]. |
required |
Returns:
Name | Type | Description |
---|---|---|
GeometryEntity |
Self
|
shifted geometrical object |
Source code in otary/geometry/discrete/entity.py
shortest_dist_vertices_to_point(point)
Compute the shortest distance from the geometry entity vertices to the point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
2D point |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
shortest distance from the geometry entity vertices to the point |
Source code in otary/geometry/discrete/entity.py
Point class useful to describe any kind of points
Point
Bases: DiscreteGeometryEntity
Point class
Source code in otary/geometry/discrete/point.py
12 13 14 15 16 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 |
|
area
property
Compute the area of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
area value |
centroid
property
Return the point as the centroid of a point is simply the point
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
centroid of the point |
edges
property
Get the edges of the point which returns empty array since a point has no edges
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
empty array of shape (0, 2, 2) |
perimeter
property
Compute the perimeter of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
perimeter value |
shapely_edges
property
Returns the Shapely.Point representation of the point. See https://shapely.readthedocs.io/en/stable/reference/shapely.Point.html
Returns:
Name | Type | Description |
---|---|---|
Point |
Point
|
shapely.Point object |
shapely_surface
property
Returns None since a point has no surface
Returns:
Name | Type | Description |
---|---|---|
None |
Point
|
None value |
distances_vertices_to_point(point)
Compute the distances to a given point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
point to which we want to compute the distances |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
distance to the given point |
Source code in otary/geometry/discrete/point.py
order_idxs_points_by_dist(points, desc=False)
staticmethod
Beware the method expects points to be collinear.
Given four points [p0, p1, p2, p3], we wish to have the order in which each point is separated. The one closest to the origin is placed at the origin and relative to this point we are able to know at which position are the other points.
If p0 is closest to the origin and the closest points from p0 are in order p2, p1 and p3. Thus the array returned by the function is [0, 2, 1, 3].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
NDArray
|
numpy array of shape (n, 2) |
required |
desc
|
bool
|
if True returns the indices based on distances descending order. Otherwise ascending order which is the default. |
False
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
indices of the points |
Source code in otary/geometry/discrete/point.py
Shape
Polygon class to handle complexity with polygon calculation
Polygon
Bases: DiscreteGeometryEntity
Polygon class which defines a polygon object which means any closed-shape
Source code in otary/geometry/discrete/shape/polygon.py
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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 |
|
area
property
Compute the area of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
area value |
centroid
property
Compute the centroid point which can be seen as the center of gravity or center of mass of the shape.
Beware: if the shape is degenerate, the centroid will be undefined. In that case, the mean of the points is returned.
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
centroid point |
edges
property
Get the lines that compose the geometry entity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
NDArray
|
array of points of shape (n, 2) |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
array of lines of shape (n, 2, 2) |
is_convex
property
Whether the Polygon describes a convex shape of not.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if convex else False |
is_self_intersected
property
Whether any of the segments intersect another segment in the same set
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if at least two lines intersect, False otherwise |
perimeter
property
Compute the perimeter of the geometry entity
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
perimeter value |
shapely_edges
property
Returns the Shapely.LinearRing as a curve representation of the Polygon. See https://shapely.readthedocs.io/en/stable/reference/shapely.LinearRing.html
Returns:
Name | Type | Description |
---|---|---|
LinearRing |
LinearRing
|
shapely.LinearRing object |
shapely_surface
property
Returns the Shapely.Polygon as an surface representation of the Polygon. See https://shapely.readthedocs.io/en/stable/reference/shapely.Polygon.html
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
shapely.Polygon object |
__rescale(scale)
Create a new polygon that is scaled up or down.
The rescale method compute the vector that is directed from the polygon center to each point. Then it rescales each vector and use the head point of each vector to compose the new scaled polygon.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
float
|
float value to scale the polygon |
required |
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
scaled polygon |
Source code in otary/geometry/discrete/shape/polygon.py
add_vertice(point, index)
Add a point at a given index in the Polygon object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
point to be added |
required |
index
|
int
|
index where the point will be added |
required |
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Self
|
Polygon object with an added point |
Source code in otary/geometry/discrete/shape/polygon.py
as_linear_spline(index=0)
Get the polygon as a LinearSpline object. This simply means a LinearSpline object with the same points as the Polygon but with an extra point: the one at the index.
Returns:
Name | Type | Description |
---|---|---|
LinearSpline |
LinearSpline
|
linear spline from polygon |
Source code in otary/geometry/discrete/shape/polygon.py
contains(other, dilate_scale=1)
Whether the geometry contains the other or not
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
GeometryEntity
|
a GeometryEntity object |
required |
dilate_scale
|
float
|
if greater than 1, the object will be scaled up before checking if it contains the other Geometry Entity. Can not be a value less than 1. |
1
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the entity contains the other |
Source code in otary/geometry/discrete/shape/polygon.py
expand(scale)
Stretch, dilate or expand a polygon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
float
|
scale expanding factor. Must be greater than 1. |
required |
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
new bigger polygon |
Source code in otary/geometry/discrete/shape/polygon.py
find_interpolated_point(start_index, end_index, pct_dist)
Return a point along the contour path from start_idx to end_idx (inclusive), at a relative distance pct_dist ∈ [0, 1] along that path.
By convention, if start_index == end_index, then use the whole contour start at this index position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_idx
|
int
|
Index of the start point in the contour |
required |
end_idx
|
int
|
Index of the end point in the contour |
required |
pct_dist
|
float
|
Value in [0, 1], 0 returns start, 1 returns end. Any value in [0, 1] returns a point between start and end that is pct_dist along the path. |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
Interpolated point [x, y] |
Source code in otary/geometry/discrete/shape/polygon.py
find_interpolated_point_and_prev_ix(start_index, end_index, pct_dist)
Return a point along the contour path from start_idx to end_idx (inclusive), at a relative distance pct_dist ∈ [0, 1] along that path.
By convention, if start_index == end_index, then use the whole contour start at this index position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_idx
|
int
|
Index of the start point in the contour |
required |
end_idx
|
int
|
Index of the end point in the contour |
required |
pct_dist
|
float
|
Value in [0, 1], 0 returns start, 1 returns end. Any value in [0, 1] returns a point between start and end that is pct_dist along the path. |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
tuple[NDArray, int]
|
Interpolated point [x, y] |
Source code in otary/geometry/discrete/shape/polygon.py
find_vertices_between(start_index, end_index)
Get the vertices between two indices.
Returns always the vertices between start_index and end_index using the natural order of the vertices in the contour.
By convention, if start_index == end_index, then it returns the whole contour plus the vertice at start_index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_index
|
int
|
index of the first vertex |
required |
end_index
|
int
|
index of the last vertex |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
array of vertices |
Source code in otary/geometry/discrete/shape/polygon.py
from_linear_entities(linear_entities)
classmethod
Convert a list of linear entities to polygon.
Beware: the method assumes entities are sorted and connected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
linear_entities
|
Sequence[LinearEntity]
|
List of linear entities. |
required |
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
polygon representation of the linear entity |
Source code in otary/geometry/discrete/shape/polygon.py
from_linear_entities_returns_vertices_ix(linear_entities)
classmethod
Convert a list of linear entities to polygon.
Beware: this method assumes entities are sorted and connected. Conneted means that the last point of each entity is the first point of the next entity. This implies that the polygon is necessarily closed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
linear_entities
|
Sequence[LinearEntity]
|
List of linear entities. |
required |
Returns:
Type | Description |
---|---|
(Polygon, list[int])
|
polygon and indices of first vertex of each entity |
Source code in otary/geometry/discrete/shape/polygon.py
from_lines(lines)
classmethod
The lines should describe a perfect closed shape polygon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lines
|
NDArray
|
array of lines of shape (n, 2, 2) |
required |
Returns:
Type | Description |
---|---|
Polygon
|
a Polygon object |
Source code in otary/geometry/discrete/shape/polygon.py
from_unordered_lines_approx(lines, max_dist_thresh=50, max_iterations=50, start_line_index=0, img=None, is_debug_enabled=False)
classmethod
Create a Polygon object from an unordered list of lines that approximate a closed-shape. They approximate in the sense that they do not necessarily share common points. This method computes the intersection points between lines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
_type_
|
array of shape (lx, ly) |
None
|
lines
|
NDArray
|
array of lines of shape (n, 2, 2) |
required |
max_dist_thresh
|
float
|
For any given point, the maximum distance to consider two points as close. Defaults to 50. |
50
|
max_iterations
|
float
|
Maximum number of iterations before finding a polygon. It defines also the maximum number of lines in the polygon to be found. |
50
|
start_line_index
|
int
|
The starting line to find searching for the polygon. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
Polygon
|
a Polygon object |
Source code in otary/geometry/discrete/shape/polygon.py
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 |
|
inter_area(other)
Inter area with another Polygon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Polygon
|
other Polygon |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
inter area value |
Source code in otary/geometry/discrete/shape/polygon.py
iou(other)
Intersection over union with another Polygon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Polygon
|
other Polygon |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
intersection over union value |
Source code in otary/geometry/discrete/shape/polygon.py
is_clockwise(is_y_axis_down=False)
Determine if a polygon points go clockwise using the Shoelace formula.
True if polygon vertices order is clockwise in the "y-axis points up" referential.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_y_axis_down
|
bool
|
If is_y_axis_down is True, then the image referential is used where y axis points down. |
False
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if clockwise, False if counter-clockwise |
Source code in otary/geometry/discrete/shape/polygon.py
is_equal(polygon, dist_margin_error=5)
Check whether two polygons objects are equal by considering a margin of error based on a distance between points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygon
|
Polygon
|
Polygon object |
required |
dist_margin_error
|
float
|
distance margin of error. Defaults to 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the polygon are equal, False otherwise |
Source code in otary/geometry/discrete/shape/polygon.py
is_regular(margin_dist_error_pct=0.01)
Identifies whether the polygon is regular, this means is rectangular or is a square.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
margin_area_error
|
float
|
area error. Defaults to 25. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the polygon describes a rectangle or square. |
Source code in otary/geometry/discrete/shape/polygon.py
normal_point(start_index, end_index, dist_along_edge_pct, dist_from_edge, is_outward=True)
Compute the outward normal point. This is a point that points toward the outside of the polygon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_index
|
int
|
start index for the edge selection |
required |
end_index
|
int
|
end index for the edge selection |
required |
dist_along_edge_pct
|
float
|
distance along the edge to place the point |
required |
dist_from_edge
|
float
|
distance outward from the edge |
required |
is_outward
|
bool
|
True if the normal points to the outside of the polygon. False if the normal points to the inside of the polygon. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
2D point as array |
Source code in otary/geometry/discrete/shape/polygon.py
rearrange_first_vertice_at_index(index)
Rearrange the list of points that defines the Polygon so that the first point in the list of points is the one at index given by the argument of this function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
int
|
index value |
required |
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Self
|
Polygon which is the exact same one but with a rearranged list of points. |
Source code in otary/geometry/discrete/shape/polygon.py
rearrange_first_vertice_closest_to_point(point=np.zeros(shape=(2,)))
Rearrange the list of vertices that defines the Polygon so that the first point in the list of vertices is the one that is the closest by distance to the reference point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference_point
|
NDArray
|
point that is taken as a reference in the space to find the one in the Polygon list of points that is the closest to this reference point. Default to origin point [0, 0]. |
required |
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
Polygon which is the exact same one but with a rearranged list of points. |
Source code in otary/geometry/discrete/shape/polygon.py
reorder_clockwise(is_y_axis_down=False)
Reorder the vertices of the polygon in clockwise order where the first point stays the same.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_y_axis_down
|
bool
|
True if cv2 is used. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
reordered polygon |
Source code in otary/geometry/discrete/shape/polygon.py
score_vertices_in_points(points, max_distance)
Returns a score of 0 or 1 for each point in the polygon if it is close enough to any point in the input points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
NDArray
|
list of 2D points |
required |
margin_dist_error
|
float
|
mininum distance to consider two points as close enough to be considered as the same points |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
a list of score for each point in the contour |
Source code in otary/geometry/discrete/shape/polygon.py
shrink(scale)
Contract or shrink a polygon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
float
|
scale shrinking factor. Must be greater than 1. |
required |
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
new bigger polygon |
Source code in otary/geometry/discrete/shape/polygon.py
to_image_crop_referential(other, crop, image_crop_shape=None)
This function can be useful for a very specific need: In a single image you have two same polygons and their coordinates are defined in this image referential.
You want to obtain the original polygon and all its vertices information in the image crop referential to match the other polygon within it.
This method manipulates three referentials: 1. image referential (main referential) 2. crop referential 3. image crop referential. It is different from the crop referential because the width and height of the crop referential may not be the same.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Polygon
|
other Polygon in the image referential |
required |
crop_rect
|
Rectangle
|
crop rectangle in the image referential |
required |
image_crop_shape
|
(tuple[int, int], optionla)
|
[width, height] of the crop image. If None, the shape is assumed to be directly the crop shape. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Polygon |
Polygon
|
original polygon in the image crop referential |
Source code in otary/geometry/discrete/shape/polygon.py
union_area(other)
Union area with another Polygon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Polygon
|
other Polygon |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
union area value |
Source code in otary/geometry/discrete/shape/polygon.py
Rectangle class. It will be particularly useful for the AITT project for describing bounding boxes.
Rectangle
Bases: Polygon
Rectangle class to manipulate rectangle object
Source code in otary/geometry/discrete/shape/rectangle.py
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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
|
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 |
is_axis_aligned
property
Check if the rectangle is axis-aligned
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the rectangle is axis-aligned, False otherwise |
longside_length
property
Compute the biggest side of the rectangle
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the biggest side length |
shortside_length
property
Compute the smallest side of the rectangle
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the smallest side length |
__init__(points, is_cast_int=False, desintersect=False)
Create a Rectangle object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
NDArray | list
|
2D points that define the rectangle |
required |
is_cast_int
|
bool
|
cast points to int. Defaults to False. |
False
|
desintersect
|
bool
|
whether to desintersect the rectangle or not. Can be useful if the input points are in a random order and self-intersection is possible. Defaults to False. |
False
|
Source code in otary/geometry/discrete/shape/rectangle.py
desintersect()
Desintersect the rectangle if it is self-intersected. If the rectangle is not self-intersected, returns the same rectangle.
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Self
|
the desintersected Rectangle object |
Source code in otary/geometry/discrete/shape/rectangle.py
from_center(center, width, height, angle=0.0, is_cast_int=False)
classmethod
Create a Rectangle object using the center point, width, height and angle.
Convention to create the rectangle is
index 0: top left point index 1: top right point index 2: bottom right point index 3: bottom left 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 |
angle
|
float
|
radian rotation angle for the rectangle. Defaults to 0. |
0.0
|
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Rectangle
|
Rectangle object |
Source code in otary/geometry/discrete/shape/rectangle.py
from_topleft(topleft, width, height, is_cast_int=False)
classmethod
Create a Rectangle object using the top left point, width, height and angle.
Convention to create the rectangle is
index 0: top left point index 1: top right point index 2: bottom right point index 3: bottom left point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topleft
|
NDArray
|
top left point of the rectangle |
required |
width
|
float
|
width of the rectangle |
required |
height
|
float
|
height of the rectangle |
required |
is_cast_int
|
bool
|
whether to cast int or not. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Rectangle
|
Rectangle object |
Source code in otary/geometry/discrete/shape/rectangle.py
from_topleft_bottomright(topleft, bottomright, is_cast_int=False)
classmethod
Create a Rectangle object using the top left and bottom right points.
Convention to create the rectangle is
index 0: top left point index 1: top right point index 2: bottom right point index 3: bottom left point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topleft
|
NDArray
|
top left point of the rectangle |
required |
bottomright
|
NDArray
|
bottom right point of the rectangle |
required |
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Rectangle
|
new Rectangle object |
Source code in otary/geometry/discrete/shape/rectangle.py
get_height_from_topleft(topleft_index)
Get the heigth from the topleft vertice
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topleft_index
|
int
|
top-left vertice index |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
height value |
Source code in otary/geometry/discrete/shape/rectangle.py
get_vector_left_from_topleft(topleft_index)
Get the vector that goes from the topleft vertice to the topright vertice
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topleft_index
|
int
|
top-left vertice index |
required |
Returns:
Name | Type | Description |
---|---|---|
Vector |
Vector
|
Vector object descripting the vector |
Source code in otary/geometry/discrete/shape/rectangle.py
get_vector_up_from_topleft(topleft_index)
Get the vector that goes from the bottomleft vertice to the topleft vertice
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topleft_index
|
int
|
top-left vertice index |
required |
Returns:
Name | Type | Description |
---|---|---|
Vector |
Vector
|
Vector object descripting the vector |
Source code in otary/geometry/discrete/shape/rectangle.py
get_vertice_from_topleft(topleft_index, vertice='topright')
Get vertice from the topleft vertice. You can use this method to obtain the topright, bottomleft, bottomright vertice from the topleft vertice.
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
topright vertice |
Source code in otary/geometry/discrete/shape/rectangle.py
get_width_from_topleft(topleft_index)
Get the width from the topleft vertice
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topleft_index
|
int
|
top-left vertice index |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
width value |
Source code in otary/geometry/discrete/shape/rectangle.py
join(rect, margin_dist_error=1e-05)
Join two rectangles into a single one. If they share no point in common or only a single point returns None. If they share two points, returns a new Rectangle that is the concatenation of the two rectangles and that is not self-intersected. If they share 3 or more points they represent the same rectangle, thus returns this object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rect
|
Rectangle
|
the other Rectangle object |
required |
margin_dist_error
|
float
|
the threshold to consider whether the rectangle share a common point. Defaults to 1e-5. |
1e-05
|
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Optional[Rectangle]
|
the join new Rectangle object |
Source code in otary/geometry/discrete/shape/rectangle.py
longside_slope_angle(degree=False, is_y_axis_down=False)
Compute the biggest slope of the rectangle
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the biggest slope |
Source code in otary/geometry/discrete/shape/rectangle.py
shortside_slope_angle(degree=False, is_y_axis_down=False)
Compute the smallest slope of the rectangle
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the smallest slope |
Source code in otary/geometry/discrete/shape/rectangle.py
unit()
classmethod
Create a unit Rectangle object
Returns:
Name | Type | Description |
---|---|---|
Rectangle |
Rectangle
|
new Rectangle object |
Triangle class module
Triangle
Bases: Polygon
Triangle class
Source code in otary/geometry/discrete/shape/triangle.py
Linear
Segment class to describe defined lines and segments
Segment
Bases: LinearEntity
Segment Class to manipulate easily segments objects
Source code in otary/geometry/discrete/linear/segment.py
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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
centroid
property
Returns the center point of the segment
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
point of shape (1, 2) |
midpoint
property
In the Segment, this is equivalent to the centroid
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
point of shape (1, 2) |
slope
property
Returns the segment slope in the classical XY coordinates referential
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
segment slope value |
slope_cv2
property
Compute the slope seen as in the cv2 coordinates with y-axis inverted
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
segment slope value |
assert_list_of_lines(lines)
staticmethod
Check that the lines argument is really a list of lines
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lines
|
NDArray
|
a expected list of lines |
required |
Source code in otary/geometry/discrete/linear/segment.py
intersection_line(other)
Compute the intersection point that would exist between two segments if we consider them as lines - which means as lines with infinite length.
Lines would thus define infinite extension in both extremities directions of the input segments objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Segment
|
other Segment object |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
intersection point between the two lines |
Source code in otary/geometry/discrete/linear/segment.py
is_collinear(segment, margin_error_angle=DEFAULT_MARGIN_ANGLE_ERROR)
Verify whether two segments on the plane are collinear or not. This means that they are parallel and have at least three points in common. We needed to make all the combination verification in order to proove cause we could end up with two points very very close by and it would end up not providing the expected result. Consider the following example:
segment1 = Segment([[339, 615], [564, 650]]) segment2 = Segment([[340, 614], [611, 657]]) segment1.is_collinear(segment2) Angle difference: 0.9397169393235674 Margin: 0.06283185307179587 False
Only because [339, 615] and [340, 614] are really close and do not provide the appropriate slope does not means that overall the two segments are not collinear.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segment
|
array
|
segment of shape (2, 2) |
required |
margin_error_angle
|
float
|
Threshold value for validating collinearity. |
DEFAULT_MARGIN_ANGLE_ERROR
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
1 if colinear, 0 otherwise |
Source code in otary/geometry/discrete/linear/segment.py
is_parallel(segment, margin_error_angle=DEFAULT_MARGIN_ANGLE_ERROR)
Check if two lines are parallel by calculating the slope of the two lines
Angle Difference = |theta_0 - theta_1| mod pi Because always returns positive results due to the modulo we took into account the special case where angle difference = np.pi - epsilon ~ 3.139, this implies also two parralel lines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segment
|
array
|
segment of shape (2, 2) |
required |
margin_error_angle
|
float
|
Threshold value for validating if the lines are parallel. Defaults to DEFAULT_MARGIN_ANGLE_ERROR. |
DEFAULT_MARGIN_ANGLE_ERROR
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether we qualify the lines as parallel or not |
Source code in otary/geometry/discrete/linear/segment.py
is_point_collinear(point, margin_error_angle=DEFAULT_MARGIN_ANGLE_ERROR)
Check whether a point is collinear with the segment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
point of shape (2,) |
required |
margin_error_angle
|
float
|
Threshold value for validating collinearity. Defaults to DEFAULT_MARGIN_ANGLE_ERROR. |
DEFAULT_MARGIN_ANGLE_ERROR
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the point is collinear with the segment |
Source code in otary/geometry/discrete/linear/segment.py
is_points_collinear(p1, p2, p3, margin_error_angle=DEFAULT_MARGIN_ANGLE_ERROR)
staticmethod
Verify whether three points on the plane are collinear or not. Method by angle or slope: For three points, slope of any pair of points must be same as other pair.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p1
|
array
|
point of shape (2,) |
required |
p2
|
array
|
point of shape (2,) |
required |
p3
|
array
|
point of shape (2,) |
required |
margin_error_angle
|
float
|
Threshold value for validating collinearity. Defaults to DEFAULT_MARGIN_ANGLE_ERROR. |
DEFAULT_MARGIN_ANGLE_ERROR
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
1 if colinear, 0 otherwise |
Source code in otary/geometry/discrete/linear/segment.py
normal()
Returns the normal segment of the segment. The normal segment is a segment that is orthogonal to the input segment.
Please note that the normal segment have the same length as the input segment. Moreover the normal segment is rotated by 90 degrees clockwise.
Returns:
Name | Type | Description |
---|---|---|
Segment |
Self
|
normal segment centered at the original segment centroid |
Source code in otary/geometry/discrete/linear/segment.py
slope_angle(degree=False, is_y_axis_down=False)
Calculate the slope angle of a single line in the cartesian space
Parameters:
Name | Type | Description | Default |
---|---|---|---|
degree
|
bool
|
whether to output the result in degree. By default in radian. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
slope angle in ]-pi/2, pi/2[ |
Source code in otary/geometry/discrete/linear/segment.py
Curve class useful to describe any kind of curves
LinearSpline
Bases: LinearEntity
Curve class
Source code in otary/geometry/discrete/linear/linear_spline.py
13 14 15 16 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 |
|
centroid
property
Returns the center point that is within the linear spline. This means that this points necessarily belongs to the linear spline.
This can be useful when the centroid is not a good representation of what is needed as 'center'.
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
point of shape (1, 2) |
curvature
property
Get the curvature of the linear spline as-if it had a well-defined curvature, meaning as-if it were a continuous curve.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
curvature value |
midpoint
property
Returns the center point that is within the linear spline. This means that this points necessarily belongs to the linear spline.
This can be useful when the centroid is not a good representation of what is needed as 'center'.
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
point of shape (1, 2) |
find_interpolated_point(pct_dist)
Return a point along the curve at a relative distance pct_dist ∈ [0, 1]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pct_dist
|
float
|
Value in [0, 1], 0 returns start, 1 returns end. Any value in [0, 1] returns a point between start and end that is pct_dist along the path. |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
Interpolated point [x, y] |
Source code in otary/geometry/discrete/linear/linear_spline.py
find_interpolated_point_and_prev_ix(pct_dist)
Return a point along the curve at a relative distance pct_dist ∈ [0, 1]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pct_dist
|
float
|
Value in [0, 1], 0 returns start, 1 returns end. Any value in [0, 1] returns a point between start and end that is pct_dist along the path. |
required |
Returns:
Type | Description |
---|---|
tuple[NDArray, int]
|
tuple[NDArray, int]: Interpolated point [x, y] and previous index in path. |
Source code in otary/geometry/discrete/linear/linear_spline.py
Vectors class they are like segments, but with a given direction
Vector
Bases: Segment
, DirectedLinearEntity
Vector class to manipulate vector which can be seen as Segment with direction
Source code in otary/geometry/discrete/linear/directed/vector.py
cardinal_degree
property
Returns the cardinal degree of the vector in the cv2 space. We consider the top of the image to point toward the north as default and thus represent the cardinal degree value 0 mod 360.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
cardinal degree |
coordinates_shift
property
Return the vector as a single point (x1-x0, y1-y0)
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
coordinates shift |
normalized
property
Nornalized vector
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
normalized vector |
from_single_point(point)
classmethod
Get vector that goes from [0, 0] to point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
point of shape 2 |
required |
Returns:
Name | Type | Description |
---|---|---|
Vector |
Vector
|
new vector object |
Source code in otary/geometry/discrete/linear/directed/vector.py
rescale_head(scale)
Rescale the head part of the vector without moving the first point. This method only updates the second point that composes the vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
float
|
scale factor |
required |
Returns:
Name | Type | Description |
---|---|---|
Vector |
Vector
|
scaled vector |
Source code in otary/geometry/discrete/linear/directed/vector.py
Vectorized Curve class useful to describe any kind of vectorized curves
VectorizedLinearSpline
Bases: LinearSpline
, DirectedLinearEntity
VectorizedLinearSpline class:
- it IS a linear spline
- it HAS a vector since a vector IS a segment and however the curve CANNOT be a segment. The vector is thus an attribute in this class. The vector does inherit from Vector class.
Source code in otary/geometry/discrete/linear/directed/vectorized_linear_spline.py
cardinal_degree
property
Returns the cardinal degree of the VectorizedLinearSpline in the cv2 space. It is calculated using the two extremities points that compose the object.
We consider the top of the image to point toward the north as default and thus represent the cardinal degree value 0 mod 360.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
cardinal degree |
is_simple_vector
property
Whether the VectorizedLinearSpline is just a two points vector or not
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True or false |