Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

1 Answer 1

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 www-staff.it.uts.edu.au/~don/pubs/solving.html –  Peter Taylor Feb 19 '11 at 0:04

Your Answer

 
discard

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