
Another question on Angles & Vectors 
gary_ramsgate
Member #8,619
May 2007

Heeeeelp. I have two circles moving around onscreen. If my two circles are: Circle 1 = x1,y1,vx1,vy1,r1 x,y = screen position Would anyone be as kind as to write a few lines of code to enable the angle of bounce to be calculated? I've spent about the last week trying to get my head around vectors and dot products, but am having no luck 
Johan Halmén
Member #1,550
September 2001

Time n: Circles don't intersect The collision should have appeared somewhere between time n and time n+1. Think of time as discrete frames. If you want a ralistic collision, you have to calculate the exact time n+d of the collision, do the collision calculus and then calculate the situation for frame n+1. The simpler way is to act like if the collision took place in n+1, even though the circles intersect in n+1. In n+2 the circles have moved in their new directions. But they might still intersect in n+2, which might cause problem. You can also make it simpler by actink like the collision took place in frame n. You kind of peek into n+1 and find out that the circles intersect. Then you calculate the collision and calculate the n+1 situation with the new directions. If the time steps are small enough, you can go this simpler way. Say the radius is 10 and circle movement from frame to frame is 0.1. Anyway, the collision calculus is something as follows: Imagine two beads, one is at rest and the other hits it. The one at rest takes completely over the speed of the other bead, while the other bead stops. They swap their speeds! If they however have different masses, the situation might be other. In any collision of two beads or two circles, you can think of them swapping the normal vectors, while the tangent vectors are unchanged. I should probably complete this with a drawing. And do study vector maths! Dividing vx and vy into vx_{normal}, vy_{normal}, vx_{tangent} and vy_{tangent} is heavy pain compared with doing it with vectors. With my vector class I would do something like. Vektor normal(circle1.coord, circle2.coord); Vektor c1_vt, c1_vn, c2_vt, c2_vn; circle1.speed.components(normal, &c1_vt, &c1_vn); // divide speed into two vectors, one //in normal direction, other perpendicular to normal circle2.speed.components(normal, &c2_vt, &c2_vn); // ditto circle1.speed = c1_vt + c2_vn; circle2.speed = c2_vt + c1_vn;
[edit] Someone take over from this point and explain how the collision makes the objects spin and how the spinning affects further collisions. Now why did you make me explain all this? Now I have to make a simple simulation application to find out this all is not just bulls hit. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. 
Paul whoknows
Member #5,081
September 2004

Not a reply but an article itself. Bookmarked!. Johan, it would be nice if you continue with this stuff, this thread has become really interesting now. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today."  Jordan Mechner. 
Johan Halmén
Member #1,550
September 2001

I don't intend to. That's all there is. The spinning thing could be interesting, but there are too many things that are involved in it. Are the objects like circles like in air hockey? Or are they balls like in pools? Are they slippery against the surface or do they stick like rubber? Not to mention differing masses. [edit] {"name":"592291","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/8\/689a8a93efe3d3b96959c8a908edd4d4.png","w":809,"h":629,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/8\/689a8a93efe3d3b96959c8a908edd4d4"} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. 
gary_ramsgate
Member #8,619
May 2007

I found some code on the net, which I've modified slightly to suit my program. sprite[??].x, sprite[??].y  sprite coordinates

