Class Rectangle, is there a circular class?

6

I know that Class Rectangle is in rectangular form for object collision, is there a Circular class for that purpose?

    
asked by Rodolfo 01.06.2016 в 17:32

1 answer

8

Yes, there is. It's the Ellipse2D

You can use your methods contains and intersects to check for collisions.

Of course, an ellipse is not necessarily a circle; but an ellipse with height and width with the same measure, is a circle: -)

Note that the Ellipse2D class itself is abstract, so you should use your daughters Ellipse2D.Float or Ellipse2D.Double , depending on the precision you want. For example:

Ellipse2D elipse = new Ellipse2D.Float(x ,y, w, h);

To change the coordinates of the ellipse after instantiating it, use the setFrame method. For example:

elipse.setFrame(x, y, w, h);
    
01.06.2016 / 17:52