Calculating the Angle of Reflection from Co-ordinates

321 Views Asked by At

I've been attempting to build a rudimentary physics engine that handles the collision of a ball on an angled surface but I have run into issues with understanding the maths behind calculating the angle of reflection.

I have the (x,y) coordinates for the current position of the ball, the velocity of the ball in (velX,velY) and I have the start and end (x,y) coordinates of the line the ball is colliding with. I'm able to calculate the collision correctly but I am unable to understand how to calculate the angle of reflection from the data I have. I've been able to find the following equations and pictures describing the problem but been unable to piece it all together.

I was hoping someone would be able to explain and maybe show examples of how to calculate the various parts of the below example.

Example of Angle of Reflect

  • What form does "d" need to take? (Need to convert from (x,y) format?)
  • How do you calculate "n"? (and then normalize it)

I had found another post that stated the following equation to find "r", so hopefully, with your help I'll be able to use this to calculate the angle of reflection of the ball.


$$r = d - 2 (d \cdot n) n$$

"where d⋅n is the dot product, and n must be normalized."


Apologies if this has already been clearly explained elsewhere, I haven't been able to find a clear explanation yet, but if one exists please just link me to it.

Thanks in advance for the help :)

1

There are 1 best solutions below

0
On

This post is old but I came across the same problem so I thought I would post my solution. I couldn't find an answer in vector format so I had to expand vectors as follows

d = [d1, d2, d3]

r = [r1, r2, r3]

n = [x, y, z]

r - d = -2(d . n) n

solve for x y z using the following equations

r1-d1 = -2*(d1*x^2 + d2*x*y+d3*x*z)

r2-d2 = -2*(d2*y^2 + d1*x*y+d3*y*z)

r3-d3 = -2*(d3*z^2 + d2*z*y+d1*x*z)

The algebra got pretty hairy real quick but here were the solutions I got

n1 = (d1 - r1)/(sqrt(2) * sqrt(d1**2 + d2**2 + d3**2 - d1 * r1 - d2 * r2 - d3 * r3))
n2 = (d2 - r2)/(sqrt(2) * sqrt(d1**2 + d2**2 + d3**2 - d1 * r1 - d2 * r2 - d3 * r3))
n3 = (d3 - r3)/(sqrt(2) * sqrt(d1**2 + d2**2 + d3**2 - d1 * r1 - d2 * r2 - d3 * r3))