Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given a ray in a 2D world at position p with initial velocity u and acceleration a how can I tell when it's within a certain distance r from a certain point.

share|improve this question

Uniform motion: s = ut + at^2/2

Or p(t) - p(0) = ut + at^2 / 2

You want the first t >= 0 for which (p(t) - C).(p(t) - C) = r^2.

If u and a could be non-perpendicular then I think you have to solve a quartic.

share|improve this answer
Thanks, yes the directions are arbitrary. I was fearing a quartic as I'm unfamiliar in solving them, but is it just a case of running the constants through some published quartic solution and using the least positive amount? – user5548 Feb 18 '11 at 23:52
@Nick, I think it should be, yes, although there's no guarantee of a numerically stable solution - see – Peter Taylor Feb 19 '11 at 0:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.