Bounding Volumes
ImplicitBVH.BBox
— Typestruct BBox{T}
Axis-aligned bounding box, highly optimised for computing bounding volumes for triangles and merging into larger bounding volumes.
Can also be constructed from two spheres to e.g. allow merging BSphere
leaves into BBox
nodes.
Methods
# Convenience constructors
BBox(lo::NTuple{3, T}, up::NTuple{3, T}) where T
BBox{T}(lo::AbstractVector, up::AbstractVector) where T
BBox(lo::AbstractVector, up::AbstractVector)
# Construct from triangle vertices
BBox{T}(p1, p2, p3) where T
BBox(p1, p2, p3)
BBox{T}(vertices::AbstractMatrix) where T
BBox(vertices::AbstractMatrix)
BBox{T}(triangle) where T
BBox(triangle)
# Merging bounding boxes
BBox{T}(a::BBox, b::BBox) where T
BBox(a::BBox{T}, b::BBox{T}) where T
Base.:+(a::BBox, b::BBox)
# Merging bounding spheres
BBox{T}(a::BSphere{T}) where T
BBox(a::BSphere{T}) where T
BBox{T}(a::BSphere{T}, b::BSphere{T}) where T
BBox(a::BSphere{T}, b::BSphere{T}) where T
ImplicitBVH.BSphere
— Typestruct BSphere{T}
Bounding sphere, highly optimised for computing bounding volumes for triangles and merging into larger bounding volumes.
Methods
# Convenience constructors
BSphere(x::NTuple{3, T}, r)
BSphere{T}(x::AbstractVector, r) where T
BSphere(x::AbstractVector, r)
# Construct from triangle vertices
BSphere{T}(p1, p2, p3) where T
BSphere(p1, p2, p3)
BSphere{T}(vertices::AbstractMatrix) where T
BSphere(vertices::AbstractMatrix)
BSphere{T}(triangle) where T
BSphere(triangle)
# Merging bounding volumes
BSphere{T}(a::BSphere, b::BSphere) where T
BSphere(a::BSphere{T}, b::BSphere{T}) where T
Base.:+(a::BSphere, b::BSphere)
Query Functions
ImplicitBVH.iscontact
— Functioniscontact(a::BSphere, b::BSphere)
iscontact(a::BBox, b::BBox)
iscontact(a::BSphere, b::BBox)
iscontact(a::BBox, b::BSphere)
Check if two bounding volumes are touching or inter-penetrating.
ImplicitBVH.isintersection
— Functionisintersection(b::BBox, p::AbstractVector, d::AbstractVector)
isintersection(s::BSphere, p::AbstractVector, d::AbstractVector)
Check if a forward ray, defined by a point p
and a direction d
intersects a bounding volume; p
and d
can be any iterables with 3 numbers (e.g. Vector{Float64}
).
Examples
Simple ray bounding box intersection example:
using ImplicitBVH
using ImplicitBVH: BSphere, BBox, isintersection
# Generate a simple bounding box
bounding_box = BBox((0., 0., 0.), (1., 1., 1.))
# Generate a ray passing up and through the bottom face of the bounding box
point = [.5, .5, -10]
direction = [0, 0, 1]
isintersection(bounding_box, point, direction)
# output
true
Simple ray bounding sphere intersection example:
using ImplicitBVH
using ImplicitBVH: BSphere, BBox, isintersection
# Generate a simple bounding sphere
bounding_sphere = BSphere((0., 0., 0.), 0.5)
# Generate a ray passing up and through the bounding sphere
point = [0, 0, -10]
direction = [0, 0, 1]
isintersection(bounding_sphere, point, direction)
# output
true
ImplicitBVH.center
— Functioncenter(b::BSphere)
center(b::BBox{T}) where T
Get the coordinates of a bounding volume's centre, as a NTuple{3, T}.