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.
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.
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.
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.
Posts
That's really clever! I think I may have just figured out the formulaic solution, but your way is much cleaner.
Thank you!
(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!
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.
IOS Game Center ID: Isotope-X