bool intersect2d::aabb_triangle(const AABB_2D &aabb, const Triangle2D &tri) { //First check if any of the triangles corners is in the aabb: if(aabb.contains(tri.p1) || aabb.contains(tri.p2) || aabb.contains(tri.p3)) return true; //Then if any of the aabb corners are in the triangle for(const glm::vec2 & c: aabb.corners()) { if(tri.contains(c)) return true; } //Then test if any lines intersect: return aabb_line(aabb, Line2D(tri.p1, tri.p2)) || aabb_line(aabb, Line2D(tri.p2, tri.p3)) || aabb_line(aabb, Line2D(tri.p3, tri.p1)); }
/*********************************************************** test if inside triangle ***********************************************************/ bool Point2D::is_inside (const Triangle2D & t) const { return t.contains (*this); }