#3d #union #intersection #boundingbox #csg

bbox

Managing axis aligned 3d Bounding Boxes

7 releases

0.7.6 Apr 29, 2018
0.7.5 Apr 28, 2018

#3 in #union

Download history 12/week @ 2018-08-23 1/week @ 2018-08-30 8/week @ 2018-09-06 6/week @ 2018-09-13 2/week @ 2018-09-20 20/week @ 2018-09-27 46/week @ 2018-10-04 22/week @ 2018-10-11 169/week @ 2018-10-18 35/week @ 2018-10-25 17/week @ 2018-11-01 89/week @ 2018-11-08 42/week @ 2018-11-15

43 downloads per month
Used in 2 crates

GPL-3.0 license

17KB
235 lines

bbox

Build Status Cargo License: GPL-3.0 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

extern crate nalgebra as na;
extern crate bbox;
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:

extern crate nalgebra as na;
extern crate bbox;
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?

extern crate nalgebra as na;
extern crate bbox;
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:

extern crate nalgebra as na;
extern crate bbox;
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.));

Dependencies

~2MB
~43K SLoC