How to calculate the rotation resulting from ball bounce

Hey all, still working to incorporate more physics simulation into my game (mentioned HERE). Now having the ball successfully and quite realistically bouncing a surface it hits, I wanted to make the ball spin off.

Now this seemed simple enough, I would calculate the rotation speed for the ball every time-tick and then rotate the ball by that much degrees upon drawing.

I knew that the speed of rotation would depend, upon impact, on:

1. Initial Speed of the ball hitting the surface (magnitude of ball velocity vector)
2. Friction co-efficient of ball & surface (constants for simulation)
3. Angle between ball impact velocity vector and the surface normal (approximated by dot vector value of impact and exit velocity vectors. 1 meaning high spin, -1 meaning no spin, and everything else relatively in between)

so, multiplying all of the above together, and making sure they were then transformed to the range 0-1, and multiplied by Max rotation speed, the ball seemed to respond in rotation speed as was expected. Except for one thing, it was always rotating clock-wise (because of positive values)

So my question is this:

1. What do you think of my method? I know it is not the most accurate, but it is good enough for simple simulation. Any easier ones?
2. If this method is fine, then what am I missing? How should I know when ball should rotate clock/anti-clock wise?

-

Your method is nice, because it's very simple. One thing you might need is dependency on previous spin on the ball, which you do not take into account. The spinning ball represents rotational energy, so a realistic simulation would probably have to conserve it along with the other energies.

However, if the ball is not rotating upon impact, I can't imagine a situation in which it begins rotation against the direction of the incident angle. That is, "clockwise" or "counterclockwise" should be relative to whichever side of the normal the incident angle is.

I think simply multiplying the result by the original x-direction vector (+1 if traveling left to right, -1 if traveling right to left) should do it.

Edit: You can use the cross-product for this. `Incident cross normal` provides a vector in the Z direction only (if we are on the 2D x-y plane). Look at the z-element: if it is positive, the ball's approach should cause it to spin clockwise. If it is negative, the ball should spin counterclockwise.

-
Hey eli Firstly, I am taking into consideration the original spin of the ball, just forgot to mention it in my post Secondly, I don't think that the x-direction system would work. I tried that, but if the ball hits the surface from below going left, the x vector would be -1, it would mean counter-clockwise rotation, while in reality it should be rotating clock-wise –  codemonkey Aug 10 '10 at 11:18
How do you take into account the original spin of the ball? If it is rotating very fast, it might launch itself away in a totally different direction. The problem with dot-product in your case is that it uses the cosine (an even function). You need something else to set the sign of the relationship between your vectors (incident and normal). You can use a cross-product (vector product) for this purpose. I have edited my answer to include a cross-product method. –  eli Aug 10 '10 at 17:40
re-reading the answer after the edit i like it. Tried it out and it worked quite fine. Regarding original spin, i was only talking about making the rotation change gradual... as for original spin affecting exit vector, well, thats my next step :) –  codemonkey Aug 10 '10 at 20:12
Ouch, the edit was one of the 3 different solutions I suggested, and I explained why you had to do it (dot only gives magnitude, not direction of angle). Alas, should be more concise I guess. –  Kaj Aug 11 '10 at 4:43
sorry for that kaj, it slipped me... no offense intended :) –  codemonkey Aug 11 '10 at 11:27

First get the surface tangent from the surface normal: t = (ny, -nx)

Then you can get the velocity component along the surface as vt = v dot t.

Now you can calculate the rotation of the ball: w = |(normal * r) cross vt|, where r is the radius of the ball.

Here I assume the ball has no rotational inertia and begins to spin instantly at the speed it would if it was to roll along the surface. You can use a coefficient of friction to make it more realistic and, if you want, take into account the rotational inertia of the ball.

-
Thanks for the answer Danik. I am already taking into consideration the ball's rotational inertia (by adding it to the new rotation) and also the friction of the surface as a coefficient to be multiplied by the total rotation speed. The more the friction, the higher the speed of rotation, right? –  codemonkey Sep 5 '10 at 15:04