I'm working with Java and I am trying to detect the intersection of an ovale with a rectangle.
I tough at first using Intersect would be sufficient :
Shape rect = new Rectangle2D.Double(ant.getPosX(), ant.getPosY(), 5, 5);
for (Shape obstacle : obstaclesShape) {
if(obstacle.intersects(rect.getBounds())){
System.out.println("Boom");
}
}
obstaclesShape is an ArrayList of oval shape.
Shape oval = new Ellipse2D.Double(getRandomX(), getRandomY(), obstacle.getRandomWidth(), obstacle.
this.obstaclesShape.add(oval);
But using this method is not reliable enough. The event seems to be triggered almost randomly.
So I was asking myself wouldn't it be better to use mathematic and determine the position of the border of my ellipsis? Something which would be determine by the angle and height / width I guess.
The thing is how to determine it precisely? What is the formula for it? Or is there a better way?