Oval Collision

Hey am trying to find different ways to get hit detection but finding it hard to figure out how to get it with an oval here is what i have just now,
wondering if they are a similar way to do this -

public cpuMovement(int x, int y, int width, int height){
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.rect = new Rectangle(x, y, width, height);
}

public static void Collision(cpuMovement cm){
for (int i = 0; i < Physics.cpuMove.size(); i++) {
if(Physics.cpuMove.get(i).getRect().intersects(cm.getRect())){
if(Physics.cpuMove.get(i) != cm){
System.out.println(“Working”);
}
}
}
}

The top bit of code is working but how would i get an oval hit detection
Cheers for your time :slight_smile:

bump

Please, do not bump your own posts like that. Many of the people who regularly answer questions on this site are in completely different time zones. When they get on, someone will eventually answer your question or at least try to help you.

That said, Oval collision would take more information. You need to find the foci of the oval in question. See this link.

From there, you do something like this:


public class Oval {
public int aFocusX;
public int aFocusY;
public int bFocusX;
public int bFocusY;
public int locusDistanceSqrd;

public boolean collision(int x, int y) {
    int distance = Math.sqrt((aFocusX - x)*(aFocusX - x) + (aFocusY - y)*(aFocusY - y)) + Math.sqrt((bFocusX - x)*(bFocusX - x) + (bFocusY - y)*(bFocusY - y));
    return distance <= locusDistanceSqrd;
}
}