Skip to contents

The function computes the polygonal convex hull of the points in x and then returns the number of points that lie below a specified set of heights along the vertical axis of the convex hull.

Usage

poly_width_at(
  x,
  at = c(0.05, 0.25, 0.5, 0.75, 0.95),
  unify = FALSE,
  plot = FALSE
)

Arguments

x

A vector containing two-dimensional data points (often produced with object_contour).

at

A vector of heights along the vertical axis of the convex hull at which to count the number of points below. The default value is c(0.05, 0.25, 0.5, 0.75, 0.95), which means the function will return the number of points below the 5th, 25th, 50th, 75th, and 95th percentiles of the convex hull. If at = "heights" is used, the function returns the width for each point of the object length.

unify

A logical value indicating whether to use the unified convex hull calculation method. If unify = TRUE, coordinates in x will be first bound before computing the convex hull.

plot

A logical value that specifies whether the widths should be plotted.

Value

A vector with the widths of the convex hull at the specified heights or a list of vectors with the widths of each component.

Details

The convex hull computed from x is aligned along the major axis and then converted to a binary image. For each height in the at vector, the function computes the corresponding row number in the binary image (i.e., the row number that corresponds to the specified height along the vertical axis of the convex hull) and sums the values in that row to obtain the number of points that lie below the specified height. If the convex hull contains multiple polygons and unify = FALSE, the function loops over each polygon and returns a list of the number of points below the specified heights for each polygon. If the convex hull contains only one polygon or multiple polygons and unify = TRUE, the function returns a vector of the number of points below the specified heights for that single polygon.

Examples

cont <- contours[[2]]
plot_polygon(cont |> conv_hull() |> poly_align())

#  width below 5th, 25th, 50th, 75th, and 95th percentiles of the length
wd <- poly_width_at(cont)
wd
#> [1]  87 356 386 268  93

# width along the height
poly_width_at(cont, at = "height", plot = TRUE)

#>    [1]   2   7  10  11  12  13  15  17  17  19  20  21  23  24  25  26  28  28
#>   [19]  30  32  32  34  35  36  37  39  41  41  43  44  45  46  48  49  50  52
#>   [37]  52  54  55  56  58  59  60  61  63  64  65  67  68  69  70  72  72  74
#>   [55]  76  76  78  79  80  82  83  84  85  87  88  89  91  92  93  94  96  96
#>   [73]  98 100 100 102 103 104 105 107 108 109 111 112 113 114 116 117 118 120
#>   [91] 120 122 123 124 126 127 128 129 131 131 133 135 135 137 138 140 141 142
#>  [109] 144 144 146 147 148 150 151 152 153 155 155 157 159 159 161 162 164 164
#>  [127] 166 168 168 170 171 172 173 175 176 177 179 179 181 182 183 185 186 188
#>  [145] 188 190 191 192 194 195 196 197 199 199 201 203 203 205 206 207 209 210
#>  [163] 212 212 214 215 216 218 219 220 221 223 223 225 227 227 229 230 231 232
#>  [181] 234 236 236 238 239 240 241 243 244 245 247 247 249 250 251 253 254 255
#>  [199] 256 258 259 260 262 262 264 265 266 267 268 269 271 271 273 273 275 275
#>  [217] 277 277 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
#>  [235] 294 296 296 297 298 299 300 300 301 302 303 304 304 306 306 307 308 308
#>  [253] 310 310 311 312 312 313 314 315 316 316 317 318 319 319 321 321 321 323
#>  [271] 323 324 325 325 327 327 328 329 329 330 331 332 332 333 334 334 334 336
#>  [289] 336 337 338 338 339 339 341 341 341 342 343 344 344 344 345 346 347 347
#>  [307] 347 349 349 349 350 351 351 352 352 353 354 354 355 355 356 356 357 357
#>  [325] 357 358 359 359 359 360 361 361 361 361 362 363 363 363 364 364 364 365
#>  [343] 365 366 366 366 366 367 368 368 368 368 368 369 369 369 370 370 370 371
#>  [361] 371 371 371 371 371 373 373 373 373 373 373 373 374 374 375 375 375 375
#>  [379] 375 375 376 376 376 376 376 377 377 378 378 378 378 378 378 378 378 378
#>  [397] 380 380 380 380 380 380 380 380 380 380 381 382 382 382 382 382 382 382
#>  [415] 382 382 382 383 384 384 384 384 384 384 384 384 384 385 385 385 385 385
#>  [433] 385 386 386 386 386 386 387 387 387 387 387 387 387 387 387 387 387 388
#>  [451] 388 388 388 389 389 389 389 389 389 390 390 390 390 390 390 390 390 390
#>  [469] 390 390 391 391 391 391 391 391 391 392 392 392 392 393 393 393 393 393
#>  [487] 393 393 393 393 393 394 394 394 393 393 393 393 393 393 393 393 394 394
#>  [505] 394 394 394 394 394 394 394 394 395 395 395 395 395 395 395 395 395 395
#>  [523] 395 395 395 396 396 395 395 395 395 395 395 395 395 395 395 395 395 395
#>  [541] 395 395 395 395 395 395 395 395 395 396 396 396 396 396 396 396 396 396
#>  [559] 396 395 395 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394
#>  [577] 394 394 394 394 394 394 394 394 394 392 392 392 392 392 392 392 392 392
#>  [595] 392 392 392 392 392 392 391 391 391 391 391 391 391 391 391 390 390 390
#>  [613] 389 389 389 389 389 389 389 389 389 389 389 388 388 388 388 388 388 388
#>  [631] 388 388 388 388 387 386 386 386 386 386 386 386 386 386 386 386 386 385
#>  [649] 385 385 385 385 385 384 384 384 384 384 383 383 383 383 383 383 383 383
#>  [667] 383 383 383 382 382 382 381 381 381 381 381 381 381 381 380 380 380 380
#>  [685] 380 380 378 378 378 378 378 378 378 377 377 377 376 376 376 376 375 375
#>  [703] 375 375 375 374 374 373 373 373 373 373 373 373 371 371 371 371 371 371
#>  [721] 370 370 369 369 369 368 368 368 368 367 367 366 366 366 366 365 365 364
#>  [739] 364 364 364 364 363 362 362 362 362 362 361 360 360 360 360 359 359 358
#>  [757] 358 358 357 357 357 356 355 355 355 355 354 354 353 353 352 352 352 352
#>  [775] 351 350 350 350 350 349 349 348 348 347 347 347 347 345 345 345 345 345
#>  [793] 344 343 343 343 342 342 342 341 340 340 340 340 339 338 338 338 337 337
#>  [811] 336 336 336 335 335 335 334 333 333 333 333 332 331 331 331 330 330 329
#>  [829] 329 329 328 328 328 327 326 326 326 326 325 324 324 324 323 323 322 322
#>  [847] 321 321 321 321 320 319 319 319 319 317 317 317 317 316 316 315 315 314
#>  [865] 314 314 314 313 312 312 312 312 310 310 310 310 309 309 308 307 307 307
#>  [883] 307 306 305 305 305 304 304 303 303 302 302 302 302 300 300 300 300 299
#>  [901] 299 298 297 297 297 297 295 295 295 295 294 294 293 293 292 292 292 292
#>  [919] 290 290 290 290 289 288 288 287 287 287 287 285 285 285 285 284 283 283
#>  [937] 283 282 282 281 280 280 280 280 279 278 278 277 277 277 275 275 275 275
#>  [955] 274 273 273 272 272 272 271 270 270 270 269 268 268 267 267 267 267 265
#>  [973] 265 265 264 264 263 262 262 262 262 260 260 260 259 259 258 258 257 257
#>  [991] 257 255 255 255 254 253 253 253 252 252 251 250 250 250 248 248 248 248
#> [1009] 247 246 246 245 245 244 244 243 243 242 241 241 241 239 239 239 239 237
#> [1027] 237 237 235 235 235 234 233 233 233 231 231 231 230 229 229 228 227 227
#> [1045] 227 226 225 225 224 224 223 222 222 221 220 220 219 218 218 218 216 216
#> [1063] 215 214 214 213 213 212 211 211 209 209 209 208 207 206 206 205 204 204
#> [1081] 203 202 202 201 200 199 199 199 197 197 196 195 195 194 194 192 192 192
#> [1099] 190 190 189 189 188 187 187 185 185 185 184 183 182 182 181 180 180 179
#> [1117] 178 178 177 176 175 175 175 173 173 172 171 170 170 169 168 168 166 166
#> [1135] 166 164 164 162 162 162 160 160 159 158 158 157 156 155 155 154 153 152
#> [1153] 151 151 150 149 149 147 147 146 145 145 144 143 142 141 140 140 139 138
#> [1171] 138 136 136 135 134 133 133 132 131 130 129 129 127 127 126 125 125 124
#> [1189] 123 122 122 120 120 118 118 118 116 116 115 114 113 113 112 111 111 109
#> [1207] 109 107 107 106 105 104 104 103 102 102 100 100  99  98  97  96  95  95
#> [1225]  93  93  92  91  90  89  88  87  87  85  85  83  83  82  81  80  80  78
#> [1243]  78  77  76  75  74  73  72  72  70  70  68  68  67  65  64  64  62  61
#> [1261]  61  59  58  56  56  55  53  53  51  50  48  48  46  44  44  42  40  39
#> [1279]  38  37  35  34  33  31  29  29  26  14