Since your ellipses are very specific, in that they are just circles, squeezed along the Y axis, you can imagine what happens if you stretch a plane along the Y axis with a coefficient of 2. You will agree that these overlapping ellipses become overlapping circles, and those that do not overlap will also not overlap after stretching. You could imagine it as if the ellipses were drawn on an elastic material, and you simply stretch the material in the vertical direction: this, of course, will not change any overlapping state.
So you can write this:
var stretchedDistance = Math.sqrt(dx * dx + 2 * dy * 2 * dy);
... and continue with the condition, because it is based on the radius in the X direction, which after stretching is also the radius in the Y direction. Of course, I named the variable differently, so you should check this variable. So, to complete the code, we get:
var stretchedDistance = Math.sqrt(dx * dx + 4 * dy * dy); if (stretchedDistance < circle1.radius + circle2.radius) {
Note that stretching is taken into account by multiplying dy by 2. In the distance formula, this is equivalent and shorter to write 4 * dy * dy .
Here is a nice interactive fiddle you created with my update.
source share