curvey.polygon¤
polygon
¤
A polygon bounded by curves
Polygon
¤
A polygon defined by its boundary curves
It's assumed that the interior curves have opposite orientation to the exterior, but this is not enforced.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exterior |
Curve
|
The exterior boundary |
required |
interiors |
Iterable[Curve] | None
|
A (possibly) empty sequence of |
None
|
Source code in src\curvey\polygon.py
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 |
|
area: float
cached
property
¤
Absolute area
boundary: Edges
cached
property
¤
Boundary edges as an edge soup
hole_points: ndarray
cached
property
¤
A (len(self.interiors), 2)
array of points inside interior holes
This is probably only useful for triangulation.
signed_area: float
cached
property
¤
Area enclosed by the polygon
This is simply equal to the sum of the signed areas enclosed by the polygon boundaries. Signed area is positive if the polygon is positively (counter-clockwise) oriented.
apply(fn: CurveFn, *args, **kwargs) -> Self
¤
Apply a curve function to boundary curves
from curvey import Curve, Polygon
poly = Polygon.from_text("e", family='arial')[0]
poly = poly.apply(Curve.split_long_edges, thresh=1)
poly.plot()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
CurveFn
|
A function |
required |
*args |
|
()
|
|
**kwargs |
Additional arguments passed to the function |
{}
|
Source code in src\curvey\polygon.py
approximate_medial_axis(dist_thresh: float, abs_err: float, angle_thresh: float = pi / 3, min_edge_length: float | None = None, pt0: ndarray | None = None, close_loops: bool = True, **kwargs) -> Edges
¤
Construct the approximate medial axis of the polygon
Implementation of Efficient and Robust Computation of an Approximated Medial Axis. Yuandong Yang, Oliver Brock, and Robert N. Moll. 2004.
The algorithm operates as follows:
- Locate an initial point on the medial axis.
- Construct a maximally inscribed disk at that point
- Uniformly sample points on the boundary of that disk
- For each of the sampled points, construct direction vectors pointing at their corresponding closest points on the polygon boundary.
- Compare the angles between the direction vectors of adjacent points sampled on the
disk boundary. If the vectors diverge, i.e. the difference in angle exceeds a threshold
angle_thresh
, the disk is assumed to intersect the medial axis at midpoint between those two adjacent points. - Points found in the previous step are added to the medial axis, and also added to a queue to repeated sample maximally inscribed disks as per steps 2-5.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dist_thresh |
float
|
Distance from the boundary to stop propagating the medial axis. |
required |
abs_err |
float
|
The error allowed in the MA vertex positions. Smaller numbers sample inscribed disks more finely. |
required |
angle_thresh |
float
|
Angle discreprancy (in radians) to count as a medial axis intersection. Default is \(pi / 3\). |
pi / 3
|
min_edge_length |
float | None
|
Prevent adding new vertices if they're within this distance of other vertices |
None
|
pt0 |
ndarray | None
|
A arbitrary starting point interior to the polygon to begin searching for the medial axis. If not supplied, this is chosen automatically by choosing the centroid of the largest triangle of the triangulated polygon. |
None
|
close_loops |
bool
|
The standard AMA algorithm produces medial axes in the form of a tree graph. As a final post-processing step, look for pairs of leaf vertices within eachother's disks and add edges connecting them. |
True
|
Returns:
Name | Type | Description |
---|---|---|
ama |
Edges
|
The approximate medial axis as an |
Source code in src\curvey\polygon.py
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 |
|
boundaries() -> Iterator[Curve]
¤
from_shapely(poly: shapely.Polygon) -> Self
classmethod
¤
Convert a shapely.Polygon
to a curvey.Polygon
Source code in src\curvey\polygon.py
from_text(text: str, **kwargs) -> list[Self]
classmethod
¤
Construct a set of polygons from matplotlib's text rendering engine
from curvey import Polygon
polys = Polygon.from_text("curvey", family="arial", size="18")
for p in polys:
p.plot()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The string to render |
required |
**kwargs |
Remaining kwargs passed to |
{}
|
Source code in src\curvey\polygon.py
plot(**kwargs)
¤
plot_edges(**kwargs)
¤
Plot polygon boundary edges
All kwargs are passed to Curve.plot_edges.
plot_polygon(ax: Axes | None = None) -> PathPatch
¤
Plot a filled polygon
Source code in src\curvey\polygon.py
to_ccw() -> Self
¤
to_cw() -> Self
¤
to_edges() -> Edges
¤
to_matplotlib() -> Path
¤
Convert a Polygon
to a matplotlib.path.Path
Source code in src\curvey\polygon.py
to_orientation(orientation: int = 1) -> Self
¤
A polygon with the specified orientation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
orientation |
int
|
Must be 1 or -1. |
1
|
Source code in src\curvey\polygon.py
to_shapely() -> shapely.Polygon
¤
Convert a curvey.Polygon
to a shapely.Polygon
triangulate(max_tri_area: float | None = None, min_angle: float | None = None, extra_params: str | None = None, **kwargs) -> Triangulation
¤
Triangulate the polygon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_tri_area |
float | None
|
A global maximum triangle area constraint. |
None
|
min_angle |
float | None
|
Minimum angle constraint, in degrees. |
None
|
extra_params |
str | None
|
See the API documentation. E.g. `extra_params='S10X' specifies a maximum number of 10 Steiner points and suppresses exact arithmetic. |
None
|
**kwargs |
Remaining kwargs passed to |
{}
|