math stuff : converting from circle to ellipse

Discussion in 'Game Development (Technical)' started by svero, May 19, 2011.

  1. svero

    Moderator Original Member Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    3,392
    Likes Received:
    6
    So... I have a 2d collision routine to intersect a circle and line segment. Broadly this boils down to the pseudocode...

    point = Get Closest Point On Line from circle
    if(distance(point to circle-center)<=circle radius) { ok collides! }

    Now what I want to do is convert that so it works with a center and a "radius vector" instead of a radius, so I can collide with ellipses instead of circles. What is the best/fastest way to do this?
     
  2. Wyzfen

    Wyzfen New Member

    Joined:
    Mar 22, 2011
    Messages:
    1
    Likes Received:
    0
    What if you transform the line to be relative to the ellipse, then scale everything to make the ellipse a circle, then test against the circle.

    Assuming ellipse is at [Ex,Ey], with radii Rx, Ry, aligned along axes (if rotated, you'll need to rotate the line too)
    1. create a new line; each end does (x,y) -> ((x-Ex) * Ry/Rx, y - Ey)
    2. get the closest point of that line to circle, centred at [0, 0], with radius Ry.

    hope that helps,
    Matthew
     
    #2 Wyzfen, May 19, 2011
    Last edited: May 20, 2011

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer