CollisionDetection icon indicating copy to clipboard operation
CollisionDetection copied to clipboard

point in ellipse

Open kokobango opened this issue 3 years ago • 2 comments
trafficstars

I see many function for circle collision, but do not see any for ellipse. Here is my version for Point / Ellipse:

function pointEllipse(px, py, cx, cy, r1, r2){
    var dx = px-cx;
    var dy = py-cy;
    return ((dx*dx)/(r1*r1)+(dy*dy)/(r2*r2)<=1);
}

kokobango avatar Mar 29 '22 15:03 kokobango

Oh wow, thanks! It was my understanding that ellipse collision is super complicated but this seems relatively straightforward. Could you explain the last bit to me?

jeffThompson avatar Mar 31 '22 12:03 jeffThompson

Oh, this is not my discover. I looked for such collision and found it in one answer. Tested it and it is working very well. Also I found an article for that subject: http://yehar.com/blog/?p=2926

kokobango avatar Apr 01 '22 07:04 kokobango