Welcome to the Monastery PerlMonks

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

by gone2015 (Deacon)
 on Aug 28, 2008 at 16:18 UTC ( #707534=note: print w/replies, xml ) Need Help??

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.

• Comment on Re^2: Some simple 2d game-related maths questions

Create A New User
Node Status?
node history
Node Type: note [id://707534]
help
Chatterbox?
 virtualsue will be sweeping/raking it up for days [virtualsue]: I need to get some cat pics into my talk http://www.cat- lovers-only.com/ images/three-cat- burritos-to-go-500 .jpg [holli]: put mine in :) [holli]: instant cat fame [virtualsue]: nice photo

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2017-11-21 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In order to be able to say "I know Perl", you must have:

Results (300 votes). Check out past polls.

Notices?