Skip to main content
GameDev.net gamedev.net
🔒 Locked

Calculating Angle Of Deflection

Started by RLS0812 Nov 24, 2011 at 4:28 PM 4 replies 21.4k views
Original Post
RLS0812
RLS0812
I have been working on a project both in Python 3, and Stencyl ( which I hate ) that involves a variant of pong.

I would like to know the best mathematical method of calculating the angle of deflection off of an angled surface.

For example: the ball is traveling at a 30 D angle ( North is 0 D, South is 180 D ), and just collided with a surface that is set at 70 D ... which angle would it deflect at ?

This is a simplification of the situation, due to the fact I am using x y vectors instead of angles, but the trig should work out.

Thank you for your time.
I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me. ~ Ralph Waldo Emerson
RLS0812
RLS0812
I'm attempting

D = 2W - P

P = balls path
W = walls angle
D = deflection
I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me. ~ Ralph Waldo Emerson
Imgelling
Imgelling
In my pong game I made many moons ago, I just negated one of the vectors depending on which side I hit.
// Collide with something on the left or right
x = -x;
// Collide with something on above or below
y = -y;

This gave a "perfect" bounce for walls at 90 degree increments. I say "perfect" because it doesn't take friction, spinning of the ball, energy loss to deformation or heat, etc.

For walls of 45 degrees, I think just swapping the vectors should work.
// Collide with a 45 degree wall
z = x; // temp for swap
x = y;
y = z;

Now for walls at any given angle. [s]Since angle of hit is = angle of rebound, you will need to find a 2D vector perpendicular to the 2D vector you have.[/s] I don't know.

Edit: I would ponder it for a bit, but it is time for me to get ready to shove tons of food down my throat. Happy Thanksgiving!
my blog contains ramblings and what I am up to programming wise.
Vectorian
Vectorian
You need to know the angle the ball travels at, and the angle of the wall the ball hits (known as the normal) (this also depends on which side the wall is hit, by 180 degrees).

Once you have both angles, new angle can be calculated as: [s]360 - ball_angle - 2 * wall_normal[/s] (not correct, looking for the right formula)[s]
[/s]

RLS0812
RLS0812
http://wiki.answers....gle_of_the_wall


A = Known angle
B = Unknown Reflection
C = Surface
If C = 0 { A + B = 1.57079633 }
Else { (A - C) + (B - C) = 1.57079633 }

Does that sound correct ?
I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me. ~ Ralph Waldo Emerson
luca-deltodesco
luca-deltodesco
oh god.

To the OP. working with angles is infact a complication of the situation

Given the normal [N] of the surface (the unit vector point out of the surface at right angle (which given your post, you either already have, or at least have the direction of the wall at right angles to the normal; in which case the normal is (-ey,ex) where (ex,ey) is the unit vector for the direction of the wall)
And the vector [V] corresponding to the balls direction of motion (doesn't need to be unit)

the reflected vector is: V - 2N(N.V) where N.V is the dot product of N and V, if you don't know what the dot procut is, then N.V = Nx*Vx + Ny*Vy, so that you end up with the vector { Vx - 2*Nx*dot, Vy - 2*Ny*dot } <-- no trigonometric functions needed.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.