The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

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

kedinikkedinik Registered 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.

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 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
  • 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
    The idea that your vote is a moral statement about you or who you vote for is some backwards ass libertarian nonsense. Your vote is about society. Vote to protect the vulnerable.
  • kedinikkedinik Registered User regular
    edited June 2010
    Thank you too, enlightenedbum. Nice Colonization LP in G&T, btw, I've been enjoying it.

    kedinik on
  • 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.