# AABB inside Sphere vs. just intersecting

This topic is 2653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've been using the following code to test for intersection between an AABB and a sphere (I don't recall where it is from). Unfortunately it doesn't tell me whether the AABB is completely inside the sphere or just intersecting. Should I add an "completely inside" test at the end, or is there a more elegant solution to do this?

 IntersectType Sphere::intersect(const Aabb &aabb) const { Vector3 min, max; aabb.getMinMax(min, max); float d = 0.f; if (m_pos.x < min.x) { float s = m_pos.x - min.x; d += s * s; } else if (m_pos.x > max.x) { float s = m_pos.x - max.x; d += s * s; } if (m_pos.y < min.y) { float s = m_pos.y - min.y; d += s * s; } else if (m_pos.y > max.y) { float s = m_pos.y - max.y; d += s * s; } if (m_pos.z < min.z) { float s = m_pos.z - min.z; d += s * s; } else if (m_pos.z > max.z) { float s = m_pos.z - max.z; d += s * s; } if (d <= m_radius * m_radius) return intersect_in; else return intersect_out; }

EDIT: Apparently the above method for testing AABB-Sphere overlapping is called Arvo's method.

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633352
• Total Posts
3011483
• ### Who's Online (See full list)

There are no registered users currently online

×