Click to See Complete Forum and Search --> : Rotating of a pool ball


dezo
December 2nd, 2007, 06:49 PM
Hi,
I'm trying to create a simple pool game. The ball is moving with speed vx along x axis and vy along y axis. This way I can easily compute the rotation in x and y direction. But how can I compute the rotation when the ball is not moving along any axis? Because rotating by angle about x axis followed by rotation by angle along y axis doesn't give the right result.

Thanks for any suggestions.

Zachm
December 3rd, 2007, 02:37 AM
I'm not sure if this is what you mean, but if a ball is not moving then the only rotation possible is around the z axis (z is perpendicular to the table).

dezo
December 3rd, 2007, 09:35 AM
No, sorry, I wasn't clear enough. I mean this situation:
http://www.fi.muni.cz/~xkacer/other/ball.png

Zachm
December 3rd, 2007, 10:52 AM
I'm sorry, but all I see in your drawing is a speed vector broken into it's x and y components.

What rotation are you seeking ?
is it the rotation of the ball as it rolls around the table ? If it doesn't roll, then it's vx speed and vy speed are 0 and therefore it doesn't rotate.

MikeAThon
December 3rd, 2007, 10:56 AM
If you assume motion without sliding, then the axis of rotation will always be perdendicular to the motion vector, and in the same plane as the plane of motion.

But most cue balls also slide when struck, so non-sliding motion is proably not a good assumption.

Mike

dezo
December 3rd, 2007, 12:08 PM
What rotation are you seeking ?
is it the rotation of the ball as it rolls around the table ?
Yes, exactly. I break the vector of movement into x and y part. Then I can compute: along x axis the ball has rotated by xxx degrees and along y axis by yyy degrees (easy computation from perimeter).
Now I want to paint the ball. If I rotate by xxx degrees around y axis and THEN by yyy around x axis, the result is wrong. I need something which will combine these TWO rotations into ONE.

Hope it's clear :)

msg555
December 4th, 2007, 01:27 AM
You'll need to find the amount of rotation along the axis of rotation (ie, perpendicular to the direction of movement in the same plane). You can find the correct rotation by first rotating the pool ball so that it's direction of movement is incident an axis, and then perform the rotation around the axis of rotation of the ball, and finally rotate it back to its original position.

I imagine you should get something like this

x' = cos_v * x + sin_v * y
y' = cos_v * y - sin_v * x
z' = z

x'' = cos(r) * x' + sin(r) * z'
y'' = y'
z'' = cos(r) * z' - sin(r) * x'

x''' = cos_v * x'' - sin_v * y''
y''' = cos_v * y'' + sin_v * x''
z''' = z''

where (x,y,z) are your inital coordinates, cos_v is v_x/sqrt(v_x^2+v_y^2), sin_v is v_y/sqrt(v_x^2+v_y^2), and r is the angle the ball has rotated around its axis.

I haven't actually confirmed the correctness of these eqauations.

dezo
December 4th, 2007, 09:09 AM
Thanks, this could work. But imagine a situations when the ball hits the wall. From that time on, I will have to compute the rotation in different direction. But to get a right result, I will have to remember the final rotation of the movement before the ball hit the wall. I mean rotate the ball to the position when it hit the wall and then according to the next movement. That's why I wanted to have rotations in x and y axis to have it easily to remember and compute the resulting rotation from these 2 ones.

Or am I not right?

msg555
December 4th, 2007, 04:28 PM
Perhaps this will help

http://en.wikipedia.org/wiki/Euler_angles

I think, if applied correctly, this can do exactly what you want in a very clean way.

Initially, let R be the identity matrix. When the user hits the ball, multiply it by a rotation around the xy plane so that the ball is now moving along one of the y axis (or x). While the ball is moving, you can figure out the orientation of your sphere by multiplying R by your rotation in the xz (or yz) plane. When the ball finally hits a wall, set R to be the product of itself multiplied by the final rotation around the xz (or yz) plane followed by a rotation around the xy plane (so that the ball is again facing the correct direction)

You can get the (x,y,z) coordinates from a rotation R as

[x'] [x]
|y'| = R * |y|
[z'] [z]

(x',y',z') is the point (x,y,z) rotated by R

Edit: Sorry, I made a mistake in this equation earlier (it didn't really make sense)