Best approximation of ellipse for collision detection.

88 Views Asked by At

I'm working on a personal JavaFX project, and I need to check if two sprites overlap. Originally, I modelled them as ellipses. I was then able to then simplify the problem into checking the intersection of a circle and a non-rotated ellipse centered at the origin. For extra context, what I did was center one of the ellipses at the origin via a translation of $\mathbb{R}^2$, then applied a transformation $\begin{pmatrix}k&0\\0&1\end{pmatrix}$ so that the centered ellipse became a circle. I then translated once again so that the ellipse was centered, and the rotated the plane so that the ellipse was no longer rotated.

However, no matter what I tried (system of equations, checking which curve intersected a ray passing through the origin first, minimizing inequalities, etc.), I always ended up with a quartic equation, which is just not viable to solve. So, I decided to use some other curves to represent the sprites. I first thought of Bezier curves, but I don't think using degree 3 or higher polynomials would improve the situation.

My question is, is there a type of curve that is roughly ovular, where calculating the intersection of such curves is easier?

1

There are 1 best solutions below

0
On

There are a few options:

  1. Approximate your ellipses by polylines, as suggested by @JeanMarie.

  2. Approximate your ellipses by bi-arc curves. These are just strings of circular arcs, for which distance and overlap calculations are easy. For more details, you can either Google “biarc” or start with the answers to this question.

  3. Use bitmap representations of your ellipses. Then overlap checking is easy. You could even do it on the GPU, which would be extremely fast.