Math problem!

I want to calculate the distance of a PongBall to a PongPad using Pythagoras. (a*a) + (b*b) = (c*c) and so on, and then make that ball bounce off the pad and ONLY the pad.

which is not the best idea in a pong game because you can get some side effects like the ball will bounce even though it missed the pad on X axis.

I think you can somehow Manage this regarding ball.radius & pad.length but I wonder how this relation might be defined.

[462 byte] By [Aikwomana] at [2007-9-28 15:00:19]
# 1

Pythagoras is only useful when detecting collisions between circles[or spheres] (and possibly Ellipses)

seeing as the bat is not an circle, that realy isn't a good solution.

there are a whole load of different ways of doing it,

depending on whether your bat is axis aligned,

whether it has thickness or not (i.e can the ball hit the sides of the bat)

etc etc.

A dead simple way of doing it (though not particularly efficient) is something like...

Line2D.linesIntersect(bat.x1, bat.y1,

bat.x2, bat.y2,

ball.x, ball.y,

ball.x+ball.dx, ball.y+ball.dy);

Abusea at 2007-7-12 11:40:48 > top of Java-index,Other Topics,Java Game Development...
# 2
OK, I am using another way now too.I just thought the mathematical issue was interesting.Get yourself a Duke Drink...
Aikwomana at 2007-7-12 11:40:49 > top of Java-index,Other Topics,Java Game Development...
# 3
and what would this 'other' way be?
Abusea at 2007-7-12 11:40:49 > top of Java-index,Other Topics,Java Game Development...
# 4
a bounding box for the circle, and for the paddle?and do if (ball.intersects(paddle)) bounceDifferentWay();}Would that work?
javatypoa at 2007-7-12 11:40:50 > top of Java-index,Other Topics,Java Game Development...
# 5

That method would occasionally fail if the ball was moving quickly,

the beauty of my suggestion, was that it uses the swept volume of the ball.

(the ball being a point particle, when moved forms a line)

if u wanted a circular or rectangular ball, calculating the swept volume would get alot trickier.

Overkill for a pong game :D

Abusea at 2007-7-12 11:40:50 > top of Java-index,Other Topics,Java Game Development...