This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Check if two AlignedBoxes intersect

Tags: None
(comma "," separated)
dsy
Registered Member
Posts
4
Karma
0

Check if two AlignedBoxes intersect

Wed Aug 08, 2012 4:55 pm
I have been wondering if there is a possibility (or what the preferred one would be) to check if two AlignedBoxes intersect.
Using squaredExteriorDistance() works:
Code: Select all
AlignedBox2d boxA;
AlignedBox2d boxB;
if (boxA.squaredExteriorDistance(boxB) == 0.0)
    std::cout << "Intersection." << std::endl;
But this is rather complicated and depends on a floating point equality check.
What I am looking for is a function like contains() that simply returns a boolean. Something like:
Code: Select all
/** \returns true if the box \a b is intersecting the box \c *this. */
inline bool intersects(const AlignedBox& b) const
{ return (m_min.array()<=(b.max)().array()).all() && ((b.min)().array()<=m_max.array()).all(); }

Is there any such function in Eigen that I might have overlooked? What would be the easiest way to check for intersecting boxes?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Indeed, this function seems missing. In the meantime you can do:

!a.intersection(b).isEmpty()
dsy
Registered Member
Posts
4
Karma
0
Thank you for the answer!
Should I prepare a patch and submit it to the bug tracker as a feature request?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
dsy wrote:Should I prepare a patch and submit it to the bug tracker as a feature request?


would be nice.
Hauke
Registered Member
Posts
109
Karma
3
OS
Any objections against making this function a free function as opposed to a member function? Or do we prefer member functions?

Regrads,
Hauke
dsy
Registered Member
Posts
4
Karma
0
I have created a patch and submitted it to the bug tracker as Bug 502.
dsy
Registered Member
Posts
4
Karma
0
Hauke wrote:Any objections against making this function a free function as opposed to a member function? Or do we prefer member functions?

I am not sure what the preferred style is, but I used the very similar contains() (member) function as a guideline.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]