Determining whether Ellipse2D is overlapping with Rectangle

Tags: ,



Hello guys I would like to ask how to determine whether my Ellipse2D contains a Rectangle Let’s say I got rectangle as a player hitbox

playerHitBox = new Rectangle(x+36,y+16,51,107);

and for the enemy sight I’ve got an ellipse named sight

Ellipse2D sight = new Ellipse2D.Double(x,y,500,500);

what is the best way to determine whether these two are overlapping because if I use sight.contains(playerHitBox) seems like the whole rectangle has to be inside of the enemy sight

Answer

You need to use shape.intersects();



Source: stackoverflow