1

I need to check if an instance of Polygon intersects another Polygon. (The intersects() method won't do this because it only accepts a Rectangle2D or a rectangular area as an arguement).

If it matters, the two Polygons that I want to check if they intersect, are both of rectangular shape, but are rotated in an angel which is not 90 degress, so I can't use the intersects() method, or at least I think I can't.

How can I do this? Thanks

user3150201
  • 1,901
  • 5
  • 26
  • 29

1 Answers1

9

Try converting the polygons to class Area. Use method "public void intersect(Area rhs)" from the javadoc.

http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Area.html

The intersects(...) method can take another area. Intersect the two areas to see if there is a remaining area by calling isEmpty() on the remainder.

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Drifter64
  • 1,103
  • 3
  • 11
  • 30