As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/

[SOLVED] Setting a slope equal to a circle's derivative

kedinikkedinik Captain of IndustryRegistered User regular
edited June 2010 in Help / Advice Forum
I'm working on a personal programming project and I've hit a roadblock with a collision algorithm.

I'm trying to find the 2 points on a circle where the slope of the circle equals a given constant.

How do I solve m = -(x/y) for the two x values that correspond to the solutions? When I try to substitute in (r^2 - x^2)^(1/2) for y, the best I can manage is a messy quartic.

I made a game! Hotline Maui. Requires mouse and keyboard.
kedinik on

Posts

  • SeolSeol Registered User regular
    edited June 2010
    kedinik wrote: »
    I'm working on a personal programming project and I've hit a roadblock with a collision algorithm.

    I'm trying to find the 2 points on a circle where the slope of the circle equals a given constant.

    How do I solve m = -(x/y) for the two x values that correspond to the solutions? When I try to substitute in (r^2 - x^2)^(1/2) for y, the best I can manage is a messy quartic.
    The tangent of a circle's curve is perpendicular to the radius. So, take the normal of the slope you want, and the points you want will be a vector equal to travelling along the normal by the circle's radius from its centre.

    Seol on
  • kedinikkedinik Captain of Industry Registered User regular
    edited June 2010
    Seol wrote: »
    kedinik wrote: »
    I'm working on a personal programming project and I've hit a roadblock with a collision algorithm.

    I'm trying to find the 2 points on a circle where the slope of the circle equals a given constant.

    How do I solve m = -(x/y) for the two x values that correspond to the solutions? When I try to substitute in (r^2 - x^2)^(1/2) for y, the best I can manage is a messy quartic.
    The tangent of a circle's curve is perpendicular to the radius. So, take the normal of the slope you want, and the points you want will be a vector equal to travelling along the normal by the circle's radius from its centre.

    That's really clever! I think I may have just figured out the formulaic solution, but your way is much cleaner.

    Thank you!

    kedinik on
    I made a game! Hotline Maui. Requires mouse and keyboard.
  • enlightenedbumenlightenedbum Registered User regular
    edited June 2010
    Take the equation of your circle:

    (x-a)^2 + (y-b)^2 = r^2

    Differentiate everything with respect to x:

    2 * (x -a) + 2 * (y - b) * (dy/dx) = 0

    Solve for dy/dx

    2 * (x - a) = -2 * (y-b) (dy/dx)

    - (x - a) / (y - b) = dy/dx

    So yeah, you're going to end up with a messy quartic.

    - (x - a) / (r^2 - x^2) ^ (1/2) = m

    Fractions are evil, so destroy them:

    - (x - a) = m * (r^2 - x^2) ^ (1/2)

    Radicals are also evil...

    (x - a) ^ 2 = m ^ 2 (r^2 - x ^2)

    Expand:

    x ^2 - 2 * a * x + a^2 = m^2 * r^2 - m^2 * x ^ 2

    (m^2 + 1) * x ^ 2 - 2 * a * x + a^2 - m^2 * r^2 = 0

    Apply quadratic formula, ta da!

    enlightenedbum on
    Self-righteousness is incompatible with coalition building.
  • kedinikkedinik Captain of Industry Registered User regular
    edited June 2010
    Thank you too, enlightenedbum. Nice Colonization LP in G&T, btw, I've been enjoying it.

    kedinik on
    I made a game! Hotline Maui. Requires mouse and keyboard.
  • GoodOmensGoodOmens Registered User regular
    edited June 2010
    I think it might be easier to do it this way:
    Translate the circle so that its center is at the origin (so that you can ignore a and b).
    Find the location on the new circle using x^2 + y^2 = r^2 and differentiating.
    Then translate the circle back to its original location, which would involve translating that point as well.

    That way, a and b don't end up as part of your calculation. More steps but a simpler computation than enlightendbum's (excellent and comprehensive) solution.

    GoodOmens on
    steam_sig.png
    IOS Game Center ID: Isotope-X
Sign In or Register to comment.