Segment
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[ |