Class Rectangle, is there a circular class?

Asked

Viewed 86 times

6

I know that Class Rectangle is rectangular shaped for collision of objects, there is a Circular class for this purpose?

  • 2

    What is the context? Give more details, only with this can not even have idea of what you are talking.

1 answer

8


Yes, there is. It’s the Ellipse2d

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

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

Important to note that the class Ellipse2D in itself is abstract, so you should use your daughters Ellipse2D.Float or Ellipse2D.Double, depending on the desired accuracy. For example:

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

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

elipse.setFrame(x, y, w, h);
  • you could give me an example of implementation, because I’m using Rectangle where the x ,y, width e height by the builder in this I don’t know where I pass them?

  • @Rodolfo You can pass the constructor as well. Edited answer.

  • 'Cause I can’t do it this.elipse.x = this.x ? already in the Rectangle worked

  • @Rodolfo When changing the ellipse, you need to set all your coordinates at the same time. Edited answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.