Reputation: 103
How do you find whether two boxes are overlapping each other? I need help with a 3D implementation of it.
Considering
Upvotes: 0
Views: 102
Reputation: 60004
An N-dimensional box oriented along coordinate axes is a product of N segments [l_i;h_i]
for i=1..N
.
Two such boxes overlap iff (if and only if) the corresponding segments overlap in each dimension.
Two line segments [a;b]
and [c;d]
are disjoint iff a>d || c>b
, IOW, they intersect iff a<=b && c<=b
.
If you are interested in open boxes (a;b)
instead of [a;b]
, replace >
with >=
and <=
with <
.
Upvotes: 2