XP is just a number PerlMonks

### Re: Some simple 2d game-related maths questions

by JavaFan (Canon)
 on Aug 27, 2008 at 21:06 UTC ( #707308=note: print w/replies, xml ) Need Help??

in reply to Some simple 2d game-related maths questions

http://mathworld.wolfram.com/Circle-LineIntersection.html has a formula for circle line intersection, with the line being infinite. You could use that, and if there's intersection, check if at least one of the intersection points lies between the end points of your line segment.
• Comment on Re: Some simple 2d game-related maths questions

Replies are listed 'Best First'.
Re^2: Some simple 2d game-related maths questions
by gone2015 (Deacon) on Aug 28, 2008 at 16:18 UTC

There's a fair amount of arithmetic to do to get the final result.

You might save cycles by doing an initial check whether the bounding box around the ball intersects the bounding box around the line -- depending on the length of the line and its angle.

The other approach may be to avoid performing a calculation on every (dx, dy) step. In particular, if the ball is moving in a straight line (or any other path that you have a polynomial for), you can calculate where the centre will be if it meets the line, then after each step you can check if the centre has gone past that point (the bounding box (x, y, x+dx, y+dy) encloses the impact point). Until, of course, the ball changes direction.

Create A New User
Node Status?
node history
Node Type: note [id://707308]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2017-08-22 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (337 votes). Check out past polls.

Notices?