java - What is wrong with this simple circle/rectangle collision detection? -



java - What is wrong with this simple circle/rectangle collision detection? -

i have issue simple 2d collision detection circle , rectangle. checker see if center of circle overlaps point on rectangle.

heres checker:

boolean overlaps(circle circle) { (double = topleft.x; < (topleft.x + width); i++) { (double j = topleft.y; j < (topleft.y + height); j++) { if (circle.center.x == && circle.center.y == j) { homecoming true; } } } homecoming false; }`

very simple, , point. error comes play @ if statement, circle.center.x, and/or circle.center.y.

here code circle class:

public class circle { point center; double radius; /** * constructor. * * @param center center point of circle * @param radius radius of circle */ public circle(point center, double radius) { center = this.center; radius = this.radius; } /** * current center point of circle. * * @return center point of circle */ public point getcenter() { homecoming center; } /** * set center point of circle. * * @param center (new) center point of circle */ public void setcenter(point center) { this.center = center; } /** * current radius. * * @return current radius */ public double getradius() { homecoming radius; } /** * set radius. * * @param radius (new) radius of circle */ public void setradius(double radius) { this.radius = radius; }

}`

where going wrong? cannot issue point class, mean plenty of other things would've gone wrong now. in advance.

your method should be:

boolean overlaps( circle circle ) { homecoming topleft.x <= circle.center.x && circle.center.x <= topleft.x + width && topleft.y <= circle.center.y && circle.center.y <= topleft.y + height; }

java collision circle rectangles

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -