A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: collision of circle and ellipse

  1. #1
    Senior Member DuMan's Avatar
    Join Date
    May 2002
    Posts
    184

    collision of circle and ellipse

    could anyone tell me how I can detect a collision between a circle and an ellipse? A rotating ellipse! It doesn't have to be pixel perfect.

  2. #2
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    Formular for Ellipse is:

    Math.pow(2*x/w,2)+Math.pow(2*y/h,2)=1;

    Make a virtural ellipse that is 2*circleRadius wider and higher; Then check the center with this hitTest.

    Here is the fla. Not pixel correct.
    Attached Files Attached Files
    Last edited by ericlin; 01-27-2003 at 11:28 AM.

  3. #3
    Senior Member DuMan's Avatar
    Join Date
    May 2002
    Posts
    184
    thank you very much.. I have a little problem though, your solution uses _xmouse and I need to control the ball with the keyboard. _xmouse and _root.circle._x will give different values even though they are in the same spot. How can i get around this?
    Last edited by DuMan; 01-27-2003 at 04:46 PM.

  4. #4
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    Change xm=_xmouse;ym=_ymouse; to the script below:

    pt = {x:circle._x, y:circle._y};
    globalToLocal(pt);
    xm = pt.x;
    ym = pt.y;

  5. #5
    Senior Member DuMan's Avatar
    Join Date
    May 2002
    Posts
    184
    thank you very much again. But I do have another addition to this problem and if you could help me out yet again it would be great. Now I need to test for a collision if the ellipse is rotating at one of its focus points (If i remember correctly, i think focus points are the spots on either end of the ellipse?)
    I think I'm on the right track, I set the center of the MC to one of the focus points, and then I'm guessing that I have to find the center of the ellipse as its rotating which I did by doing this...
    centerx = _x-55*Math.cos(_rotation*(Math.PI/180));
    centery = _y-55*Math.sin(_rotation*(Math.PI/180));
    but I don't know how to work that in with the other stuff.

  6. #6
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    My ellipse has its center at 0,0 point. I calculate the x,y value in the coordinate system of ellipse by localToGlobal function, so any x,y values modified by rotation have already been corrected by globalToLocal function.

    The other way might be simpler. It does not need complex math. That is : create virtual ellipse manually not by math. And use hitTest to detect collision.

    This principle can be applied to detect collision between a circle and any shape.

    Below is the fla. I have set the blue virtual ellipse _alpha=30; You can set it _alpha=0 to make it invisible.
    Attached Files Attached Files

  7. #7
    Senior Member DuMan's Avatar
    Join Date
    May 2002
    Posts
    184
    whoa thats cool. I never would have thought of that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center