[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] detecting reflection angle



Hi Alex,

I have made a quick drawing so if I made a mistake please forgive:

You have to always refer yourself according to a non-moving reference.
So let's say this reference vector plane is defined by your screen.

The platform has an angle alpha with the reference.
The shooting object has an angle beta with the reference

In that case I found that your shooting object will have an angle
pi(3.14159)-2*alpha-beta

with alpha=arctan((endingpoint.y-startingpoing.y)/(endingpoint.x-startingpoint.x))
beta=arctan((collisionpos.y-lastpos.y)/(collisionpos.x-lastpos.x))

(more or less)

then your final angle should be

Pi-2*alpha-beta

After that, you can take that tan of this to get the slope... (wonder if all that is correct mathematically)

Have you tried to start everything with a polar coordinate system?

Guillaume


alex wrote:
I have a moving dot and a bunch of  static walls which this dot collides
into.
each wall is being represented as a line segment with its starting and
ending positions
on each frame I take the dot's previous and current position and represent
this as a segment. Then I check if this segment intersects with any wall
segment (this works ok), and if they do I have to calculate the reflection
angle.. there comes my problem.

how can I calculate this reflection or bouncing angle by knowing:
dot's movement segment (previous_pos,current_pos)
wall's segment (starting_point, ending_point)

I know I can get the direction of each segment by using -math.atan2(....)
but then all further attempts to get the right bouncing angle have failed, I
don't know what I'm doing wrong, I had this working once... but now, argh!
It's driving me crazy...

can someone provide some code or pseudo-code solution for this problem?

Thanks a lot!

Alex


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org



____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org