Bounding boxes denote the exten of geometries. It follows that bounding boxes are only defined for geometries that are located in space and have finite extent. Thus, vectors, lines, directions, rays, etc. does not have bounding boxes, while e.g. spheres, circles, segments, etc has. Since the extent of geometries cannot always be given exact (e.g. for circles), bounding boxes are defined in regular floating point precision. Bounding boxes can be compared for equality and be tested for whether they overlap. Adding bounding boxes together will give the bounding box containing both.

bbox(...)

is_bbox(x)

as_bbox(x)

is_overlapping(x, y)

x %overlaps% y

Arguments

...

Either a vector of geometries or a range of numeric vectors (4 for 2D bounding boxes and 6 for 3D) interpreted in the order xmin, ymin, zmin, xmax, ymax, zmax.

x, y

vectors of bounding boxes or geometries

Value

An euclid_bbox vector

Examples

# Construction bbox(10, -2, 15, 0)
#> <2D bounding boxes [1]> #> [1] <<10, -2>, <15, 0>>
seg <- segment(point(sample(10, 4), sample(10, 4)), point(sample(10, 4), sample(10, 4))) boxes <- bbox(seg) boxes
#> <2D bounding boxes [4]> #> [1] <<5, 2>, <5, 2>> <<10, 6>, <10, 7>> <<4, 3>, <7, 7>> <<8, 6>, <9, 8>>
plot(seg)
euclid_plot(boxes, fg = "firebrick")
# Comparison boxes[1] == boxes
#> [1] TRUE FALSE FALSE FALSE
boxes[1:2] %overlaps% boxes[3:4]
#> [1] FALSE FALSE
# Addition boxes[1] + boxes[2]
#> <2D bounding boxes [1]> #> [1] <<5, 2>, <10, 7>>
cumsum(boxes)
#> <2D bounding boxes [4]> #> [1] <<5, 2>, <5, 2>> <<5, 2>, <10, 7>> <<4, 2>, <10, 7>> <<4, 2>, <10, 8>>
plot(sum(boxes), bg = "grey", fg = NA)
euclid_plot(boxes)
# Conversion as.matrix(boxes)
#> [,1] [,2] [,3] [,4] #> [1,] 5 2 5 2 #> [2,] 10 6 10 7 #> [3,] 4 3 7 7 #> [4,] 8 6 9 8