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,751
  • 5
  • 23
  • 27

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
  • 29,586
  • 38
  • 176
  • 304
Drifter64
  • 1,063
  • 2
  • 11
  • 29