how would i detect the collision between a rectangle and a circle? both of these are images btw.
public static boolean cricleVsRect(PCircle c, PRectangle p){
if(p.containsPoint(PVector.add(c.getLocation(), new PVector(0, c.getRadius())))
|| p.containsPoint(PVector.add(c.getLocation(), new PVector(0, -c.getRadius())))
|| p.containsPoint(PVector.add(c.getLocation(), new PVector(c.getRadius(),0)))
|| p.containsPoint(PVector.add(c.getLocation(), new PVector(-c.getRadius(),0)))){
return true;
}
if(c.containsPoint(p.getLocation())
|| c.containsPoint(PVector.add(p.getLocation(), new PVector(p.getWidth(), 0)))
|| c.containsPoint(PVector.add(p.getLocation(), new PVector(0, p.getHeight())))
|| c.containsPoint(PVector.add(p.getLocation(), new PVector(p.getWidth(), p.getHeight())))
)
return true;
return false;
}
“[rectangle].getLocation()” returns the upper left corner of the rectangle.
“[circle].getLocation()” returns the middle of the circle.
If it’s possible to solve it faster, feel free to critizise
best regards
i do not understand this at all…lol and i am getting a bunch of errors when trying to use this
wreed, you can just use AABB to do it. DrHalfway posted an article int he Articles section that explains the AABB method.
PVector and PRectangle are custom classes. You can’t just copy the code, but if you have questions about it, feel free to ask.