Tuesday, October 15, 2019

2d - How to calculate the exit speed of ball bouncing off a solid surface


Hey all, I am working on a simple game to include some rigid body dynamics, involving placing (moving & rotating) some springs to bounce a falling ball into a target area.


My problem is correctly calculating the exit velocity of the ball after it hits the spring surface (Vexit, Ve for short)


Assume the following:
Initial ball velocity vector at point of impact is known (Vimpact, Vi for short)
Surface orientation vector is known (Vsurface, Vs for short)
Bounce coefficient (Bc for short) of ball after hitting surface is constant (for example |Ve| = 1.2 x |Vi|)



My algorithm is as follows:
-get surface normal vector, Vn
-get Vi inverse (reversing both x,y components to get reversed direction vector)
-get normalised Vi inverse, call this Vin
-get angle between Vin & Vn, by arccos(Vin . Vn). Let this be angle A
-rotate Vin by (2A) degrees to get normalised exit vector Ven
-Ve = Ven . Bc


Now as far as I can tell, this would work well. However, I am unable to know on whether to perform the rotation step in clock-wise, or anti-clock-wise motion; since the angle i get is always positive


What do you all think of this algorithm anyways?
Can anyone help me out on how to figure out the rotation direction?

Anyone have a better (faster,simpler,more accurate, etc) algorithm to use?


Thanks a lot!



Answer



I think you're over-thinking this, you can achieve reflection, as it can be calculated by doing:


Ve = Vi - 2 * (Vi dot Vn) * Vn


(Where dot refers to the dot product)


Then you can simply scale Ve by your Bc to get the final result.


Reference: http://mathworld.wolfram.com/Reflection.html


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...