#bounding-box #3d #union #intersection #csg

bbox

Managing axis aligned 3d Bounding Boxes

16 unstable releases (4 breaking)

0.11.2 Oct 19, 2020
0.11.1 Oct 18, 2020
0.10.0 Oct 18, 2020
0.9.2 Dec 2, 2019
0.7.6 Apr 29, 2018

#5 in #bounding-box

Download history 49/week @ 2024-02-19 14/week @ 2024-02-26 4/week @ 2024-03-04

67 downloads per month
Used in 2 crates

Apache-2.0 OR MIT

16KB
225 lines

bbox

Build Status Cargo License: Apache-2.0 License: MIT Downloads

bbox is crate for managing axis aligned 3d Bounding Boxes. Bounding Boxes can be created, dilated, transformed and joined with other Bounding Boxes using CSG operations. Finally you can test whether or not a Bounding Box contains some point and what approximate distance a Point has to the Box.

Examples

Intersect two Bounding Boxes

use nalgebra as na;
let bbox1 = bbox::BoundingBox::<f64>::new(na::Point3::new(0., 0., 0.),
                                          na::Point3::new(1., 2., 3.));
let bbox2 = bbox::BoundingBox::<f64>::new(na::Point3::new(-1., -2., -3.),
                                          na::Point3::new(3., 2., 1.));
let intersection = bbox1.intersection(&bbox2);

Rotate a Bounding Box:

use nalgebra as na;
let rotation = na::Rotation::from_euler_angles(10., 11., 12.).to_homogeneous();
let bbox = bbox::BoundingBox::<f64>::new(na::Point3::new(0., 0., 0.),
                                         na::Point3::new(1., 2., 3.));
let rotated_box = bbox.transform(&rotation);

Is a point contained in the Box?

use nalgebra as na;
let bbox = bbox::BoundingBox::<f64>::new(na::Point3::new(0., 0., 0.),
                                         na::Point3::new(1., 2., 3.));
let result = bbox.contains(na::Point3::new(1., 1., 1.));

Calculate approximate distance of a point to the Box:

use nalgebra as na;
let bbox = bbox::BoundingBox::<f64>::new(na::Point3::new(0., 0., 0.),
                                         na::Point3::new(1., 2., 3.));
let distance = bbox.distance(na::Point3::new(1., 1., 1.));

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~4MB
~80K SLoC