简体   繁体   中英

Determine if any 2D polygon (including convex or concave polygons) intersects with AABB bounding

I'm developing a 2D program that requires a lot of judgment on whether a polygon (generated or imported by the user, could be either convex or concave) is intersecting (overlaping) with AABBs. The data structure part I've implemented with kdtree, and I now need a way to determine whether a polygon intersects with an AABB box.

I have seen many discussions on the web, but they are all about convex polygons, and I have also seen methods that use each line segment of a polygon to determine if it intersects with an AABB, but since it is an AABB box, I am afraid this method is too expensive.

1 The polygon is defined by a series of Vector2 list stored in counterclockwise order, AABB Box is defined by List[minx,miny,maxx,maxy].

2 I only care whether they intersect or not, I don't need to return overlaping ranges or intersection points.

3 Any pre-processing of polygons is possible.

4 The language used is C#, and any available libraries are welcome.

It is possible to convert any polygon into triangles, this is called triangulation . Then you can use any triangle/aabb intersection algorithm you want.

In addition to this, you can draw an aabb around the polygon and check that against the other aabb first. If those don't intersect you don't have to check all the triangles separately.

Furthermore, you can use a bounding volume hierarchy to prevent doing unnecessary collision checks of the triangles and aabb. This is a nice explanation and implementation but it's in the context of raytracing. You can easily adapt it for your purposes though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM