FuKwun Hwang


«
Embed this message
on: January 29, 2004, 04:08:42 pm » 

Registed user can get files related to this applet for offline access.Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list If java program did not show up, please download and install latest Java RUN TIMEor Due to so many requests from the users, source code for this applet is distributed with the ZIP files you will receive if you click get file for offline use button. Please do not ask me to send you the source code again!You are welcomed to check out another Collision 2D created with EJS.
Please check out latest 2D collision created with EJSLet's consider collisions in two dimension: Press Start to begin the animation. Two circular objects will move with predefined velocity (yellow arrow). Click left mouse button to suspend the animation. Now, you can Click near the tip of the velocity vector and drag the mouse button left/right to change its value (the initial velocity of that object). Click near the circular boundary and drag the mouse button to change its radius.
Right Click near the boundary of the circle to change it's size (also change it's mass, at the same time).
Click near the center of the circle and drag the mouse to change its location. Click the mouse button again to resume the animation. When the two objects collide, the animation will be suspend.
Press the mouse button ( Do not release it) to see the velocity vectors just after the collision. Press Reset button to reset parameters to default values.
eta is the coefficient of restitution eat Vf/Vi Vf=relative velocity just after collision Vi=relative velocity just before collision for elastic collision eta=1. for perfectly inelastic collision eta=0. You can select different frame of reference to view the relative motion of all the objects.
lab is a laboratory inertial frame. m_{1}, m_{2 }and CM are frame of reference with respect to left circular object m1, right circular object m2 and center of mass for m1 and m2. View collision in 1 dimension.
At the moment when they collide, the force between the two circle objects is along the line which connect the center of the two objects.
Now we have 1D collision problem: two object move in the direction along the line connect between their center, with velocitys along this directions. (Red vectors)
The vector perpendicular to the above components (green vectors) will not changed after collision. (If there is no friction force between the two objects)
Please check out Rigid Body Collisions for 2D collision between rectangle shape objects. Registed user can get files related to this applet for offline access.Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list If java program did not show up, please download and install latest Java RUN TIMEor

*** There are 1 more attached files. You need to login to acces it!


Logged




FuKwun Hwang


«
Embed this message
Reply #1 on: October 28, 2004, 02:19:44 pm » 

1. Find the time when two ball collide : D= R1+ R2 where D=Distance between center of two balls , and R1/R2 is radius of each balls 2. Find the line connect center of two balls. and calculate the component of the velocitry for each ball alone the line connect those two balls. For example : Velocity for each ball is Va and Vb (before collision) Calculate Vap and Vbp. (and another normal component Van,Vbn) 3. It is become a 1D collision problem: ball A with velocity Vap collide with ball B with velocity Vbp . You should be able to calculate velocity after collision for each ball. for example: Vap2=((m1m2)/(m1+m2))vap+ (2m2/(m1+m2))Vbp and Vbp2=(2 m1/(m1+m2))Vap+((m2m1)/(m2+m1))Vbp The tangential component is not changed Van2=Van, and Vbn2=Vbn 4. Calculate the vector sum for velocity of each ball after collision Va2=Vap2+Van2 and Vb2=Vb2p+Vbn2 (vector summation)



Logged




siput_tiung
Newbie
Offline
Posts: 3


«
Embed this message
Reply #2 on: March 12, 2005, 11:41:59 am » 

hi, is there any difference between balls or humans when collision occur? i am trying to write a human model for collision cases... and still trying very2 hard to make it in realistic way. your applet seems like good for me and i'm impressed with it... perhaps it would be good to be applied to my project.. can u explain it in detail how's the calculation for it? dividing it into 3 condition,(1.before,2. during..,3.after.. )would be really2 great... thanks.. ref: http://www.phy.ntnu.edu.tw/ntnujava/viewtopic.php?t=19Regards, Bazli Karim siput_tiung@yahoo.com



Logged




FuKwun Hwang


«
Embed this message
Reply #3 on: March 12, 2005, 02:20:41 pm » 

The above calculation assume it is an elastic collision between two balls. i.e. No energy is loss during the collision. And the ball would not change shape. For collision betwen two human, we will change our body movment. Would you explain in more detail why you need to calculate collision between human? While two persons are walking or ...?



Logged




siput_tiung
Newbie
Offline
Posts: 3


«
Embed this message
Reply #4 on: March 14, 2005, 10:07:58 am » 

let's see... here i'm trying to do collision avoidance among human... for example... human A is trying to go to point 1... and if there is another human blocking his way... then.. the human A must avoid it.. by changing to other direction and then, go to point 1.. here... i can detect the collision if there is human blocking another human.. but, i have problem with changing direction... to make it realistic..



Logged




FuKwun Hwang


«
Embed this message
Reply #5 on: March 14, 2005, 02:33:38 pm » 

Because you want to avoid collision among human. So there is no collision among human. You can check the velocity vector, if it is pointing to another person. Then someone is blocking his way. Provide the horizontal displayment, you can calculate the least change of the velocity. The person can change direction right at that point or change velocity gradually.



Logged




siput_tiung
Newbie
Offline
Posts: 3


«
Embed this message
Reply #6 on: March 16, 2005, 02:41:52 pm » 

thanks.. i got the idea now..



Logged




FuKwun Hwang


«
Embed this message
Reply #7 on: May 11, 2005, 07:03:51 am » 

Due to so many email questions asking for help. I rewrote this post to include more detail calculation steps: Assume the radius for two ball are r1 and r2, and the coordinates are (x1,y1) and (x2,y2). Usually, we calculate the distance between two balls d=sqrt( (x1x2)*(x1x2)+(y1y2)*(y1y2)); The collision should have occurred if d equal r1+r2; // if(d==r1+r2) However, there is a finite time step dt in the simulation calculation,so most often we would not be able to find the above condition (exact time when two ball real occurred). So we check if d<= r1+r2; Then we know the collision should have occurred. The real collision should have occurred before you detected that the distance between two center of the balls d is less than the sum of those two balls r1+r2. (d< r1+r2) The correct way is to find the time when the two ball really collide with each other. Suppose the center of those two ball are x1,y2 and x2,y2 dx=x2x1, dy=y2y1; d=sqrt(dx*dx+dy*dy); First calculate the component of velocity in the direction of (dx,dy) vp1= vx1 *dx/d+vy1*dy/d; vp2= vx2*dx/d+vy2*dy/d; Collision should have happened dt before you have detected r1+r2 and dt =(r1+r2d)/(vp1vp2); and dt =(r1+r2d)/(vp1vp2);// the collision should have occurred at tdt (Actually this is also an approximation).
So you should move those two ball backward x1= vx1*dt; y2 = vy1*dt; x2=vx2*dt; y2=vy2*dt;
Now the distance between center of the two balls is d'=r1+r2;
The following code take care of collision:
double dx = x2x1, dy = y2y1; // where x1,y1 are center of ball1, and x2,y2 are center of ball2 double distance = Math.sqrt(dx*dx+dy*dy); // Unit vector in the direction of the collision double ax=dx/distance, ay=dy/distance; // Projection of the velocities in these axes double va1=(vx1*ax+vy1*ay), vb1=(vx1*ay+vy1*ax); double va2=(vx2*ax+vy2*ay), vb2=(vx2*ay+vy2*ax); // New velocities in these axes (after collision): ed<=1, for elastic collision ed=1 double vaP1=va1 + (1+ed)*(va2va1)/(1+mass1/mass2); double vaP2=va2 + (1+ed)*(va1va2)/(1+mass2/mass1); // Undo the projections vx1=vaP1*axvb1*ay; vy1=vaP1*ay+vb1*ax;// new vx,vy for ball 1 after collision vx2=vaP2*axvb2*ay; vy2=vaP2*ay+vb2*ax;// new vx,vy for ball 2 after collision
(ax,ay) is the unit vector in the direction connected two objects. draw a line connect two object, assign the angle between this line and xaxis is θ, then cosθ=ax, sin θ=ay So vap1*ax=vap1*cosθ give xcomponent of vap1, and vap1*ay give ycomponent of vap1
Because vb1 and vb2 is in the direction perpendicular to the (ax,ay) ,then the angle between vb1 and xaxis is φ=θ+π/2 so cos φ=cos(θ+π/2)=sinθ=ay, sinφ=sin(θ+π/2)=cosθ=ax to calculate xcomponent of vb1 we need to calculate vb1*cos φ=vb1*(ay)=vb1*ay ,and (ycomponent of vb1) = vb1*sinφ=vb1*ax
Because we have move time backward dt, we need to move time forward dt. so x1+= vx1'*dt; y1+=vy1'*dt; x2+=vx2'*dt; y2+=vy2'*dt;
Now the distance between two ball will be larger than r1+r2.
If you did not correct the time dt (before you have found collision occurred, you will find balls clutch together. and they don't even let go.



Logged




rsnd
Newbie
Offline
Posts: 1


«
Embed this message
Reply #8 on: August 13, 2005, 10:33:14 am » 

sorry for bothering Its probably a 3 year old thread!!! Just wondering...what does vx0 represent in your code? Thanks Rsnd



Logged





FuKwun Hwang


«
Embed this message
Reply #10 on: September 21, 2005, 07:30:44 am » 

Is there a vx0 posted in this forum messages! Please explain what do you mean?



Logged




Janus20
Professional Truth Mechanic
Newbie
Offline
Posts: 5


«
Embed this message
Reply #11 on: September 29, 2005, 09:56:41 am » 

You have missed the spin component caused by the collision. It may have been there before collision occured. The spin neglect is an ENORMOUS ERROR. The information is dangerous due to its over simplification.



Logged




FuKwun Hwang


«
Embed this message
Reply #12 on: October 18, 2005, 09:17:59 am » 

Yes, the ball will also rotate if there are friction force between balls when collide. This is just an applet try to help student to understand basic physics (how to transform a 2D problem into two 1D problem).



Logged




sujitkane
Newbie
Offline
Posts: 1


«
Embed this message
Reply #13 on: October 19, 2005, 06:01:46 pm » 

Hello Professor Hwang I have been following these pages since its publication in january 2004, just happened to register today. I wonder how different will it be if we consider that the two colliding bodies are two circular discs. You might have heard of a board game called carrom , its very popular in India. Do take a look at it. Now we have tried to emulate the example you have put up here and applied it to the emulation of carrom. There are a few rough edges, but still the difference is not very clear. What changes will be necessary to make it work realistically? Regards Sujit Kane



Logged




FuKwun Hwang


«
Embed this message
Reply #14 on: October 20, 2005, 08:06:24 am » 

I do not know anything about carrom. Is there a URL for that? To add a rotation effect due to friction between two disks, the mathematics become more comples. The friction between two disks is proportional to the normal force when two disks collide. F(friction) = mu * F(normal) The normal force is the rate of change of momentum (in the direction between two centers) when two disks collide. The friction force might change the tangential component of the velocity if the friction force is not large enough ( sliding occurs) The torque due to the friction will change the angular momentum for those two disks. In 2D collision: vx,vy and w (angular momentum) are changed due to collision for each ball. There are 6 variables need to be update for two balls, so you need to solve 6 equations.



Logged




pleasedontgocrazy
Newbie
Offline
Posts: 4


«
Embed this message
Reply #15 on: October 23, 2005, 10:42:16 pm » 

what if the collision isnt perfectly inelastic/ elastic



Logged




FuKwun Hwang


«
Embed this message
Reply #16 on: October 24, 2005, 07:45:39 am » 

You just need to solve the problem differently for non perfect elastic collision. Momentum is still conserved. But the energy is not conserved.



Logged




pleasedontgocrazy
Newbie
Offline
Posts: 4


«
Embed this message
Reply #17 on: October 25, 2005, 05:39:17 pm » 

I keep trying to prove your equation by using the assumption that kinetic energy is not lost and momentum is not lost but I keep getting a different answer to yours. Could you give me some pointers about how to do solve it. SOLVED! Im doing this experiment for my A level coursework and I found that typically 90% of the mommentum is lost. Have I made a mistake?



Logged




pleasedontgocrazy
Newbie
Offline
Posts: 4


«
Embed this message
Reply #18 on: October 25, 2005, 06:56:26 pm » 

Yes! Ive solved it (and got the correct answer) But this is for an elastic collision. For an partial inelastic collision which equation do I use for kinetic energy? Do you lose a certain amount of energy or is it a percentage of energy lost?



Logged




SIBUK
Newbie
Offline
Posts: 1


«
Embed this message
Reply #19 on: November 28, 2005, 05:52:53 am » 

Hi Professor Hwang, This article is fantastic and has helped me a lot, but I am wondering if you might be able to help me out with a problem I have. I have made a program where I have multiple balls on the screen, each moving at a random velocity and in a random direction. The problem I have is that when 2 balls collide, they will often stick to each other (especially when ed is < 1) and spin around orbiting each other. Each of the balls has a radius of 15, and so my collision detection is very simple, when the distance between two balls is <= 30 then there has been a collision. So, the problem is that when the distance is less than 30, (say 25), then they are overlaping by 5, when I next update the positions of the balls, if they havnt moved more than a distance of 5 away from each other since the last update, then they are still overlapping and the collision is still true. So, what I need to do is before the next update, I need to move the balls appart from each other a distance of 5 in the new direction after the impact. But I cant seem to figure out the maths to do it. Also, I have implemented a bit of code to help handle when 3 or more balls collide at the same time, but it doesnt quite seem to work right. Do you have any tips for this?



Logged




FuKwun Hwang


«
Embed this message
Reply #20 on: April 15, 2006, 02:11:56 pm » 

The real collision should have occured before you detected that the distance between two center of the balls d is less than the sum of those two balls r1+r2. The correct way is to find the time when the two ball real collide with each other. Suppose the center of those two ball are x1,y2 and x2,y2 dx=x2x1, dy=y2y1; d=sqrt(dx*dx+dy*dy); First calculate the component of velocity in the direction of (dx,dy) vp1= vx1 *dx/d+vy1*dy/d; vp2= vx2*dx+vy2*dy/d; Collision should have happened dt before you have detected r1+r2<d; and dt =(r1+r2d)/(vp1+vp2); So you should move those two ball backward x1= vx1*dt; y2 = vy1*dt; x2=vx2*dt; y2=vy2*dtl Now the distance between center of the two balls is d'=r1+r2; Apply the collision to calculate new velocity for those two balls after collision. Support new velocity are vx1' , vy1', vx2',vy2' You need to move time dt forward so x1+= vx1'*dt; y1+=vy1'*dt; x2+=vx2'*dt; y2+=vy2'*dt; You can check out another simulation created with EJS and find out how I did it with EJS.



Logged




druidbartek
Guest


«
Embed this message
Reply #21 on: February 21, 2007, 03:49:40 am » 

hi sorry for bumping this old thread but ive some problems with ball collision (in C) the  the conservation of kinetic energy is property but not the conservation of momentum it's the simple ball collision 2D for old nokia mobiles static void redraw_screen(void) { /* ... */ ball_collision(&app.ball_a, &app.ball_b); <redraw_screen> }
static void ball_collision(struct ball *ball_a, struct ball *ball_b) { float dx = ball_b>x  ball_a>x; float dy = ball_b>y  ball_a>y; float d = sqrt(dx*dx+dy*dy);
if(d<=(float)bmap_ball.height) // r1+r2 = bmap_ball.height { // first we calculate the velocity in the direction of (dx,dy) float vp_a = (ball_a>vx*dx + ball_a>vy*dy)/d; float vp_b = (ball_b>vx*dx + ball_b>vy*dy)/d;
// collision should have happened dt before float dt =((float)bmap_ball.heightd)/(vp_avp_b);
// we should move those ball backward ball_a>x = ball_a>vx*dt; ball_a>y = ball_a>vy*dt; ball_b>x = ball_b>vx*dt; ball_b>y = ball_b>vy*dt;
dx = ball_b>x  ball_a>x; dy = ball_b>y  ball_a>y; d = sqrt(dx*dx+dy*dy);
// calculate the components of velocity float ap = dx/d; float an = dy/d;
vp_a = ball_a>vx*ap + ball_a>vy*an; float vn_a = ball_a>vx*an  ball_a>vy*ap;
vp_b = ball_b>vx*ap + ball_b>vy*an; float vn_b = ball_b>vx*an  ball_b>vy*ap; // calculate new velocity for those balls after collision ball_a>vx = vp_b*ap + vn_a*an; ball_a>vy = vp_b*an  vn_a*ap; ball_b>vx = vp_a*ap + vn_b*an; ball_b>vy = vp_a*an  vn_b*ap;
// now we need to move time dt forward ball_a>x += ball_a>vx*dt; ball_a>y += ball_a>vy*dt; ball_b>x += ball_b>vx*dt; ball_b>y += ball_b>vy*dt; } } and im stuck regards, Bartek oh, and mass1 = mass2 and eta =1


« Last Edit: February 21, 2007, 04:14:57 am by druidbartek »

Logged




FuKwun Hwang


«
Embed this message
Reply #22 on: February 22, 2007, 04:48:24 pm » 

This is the java code I use in my simulation: r12=Math.sqrt((x1x2)*(x1x2)+(y1y2)*(y1y2)); cs=(x2x1)/r12; sc=(y2y1)/r12; vp1=vx1*cs+vy1*sc; vp2=vx2*cs+vy2*sc; // back to collision time ddt=(dminr12)/(vp1vp2); if(ddt>dt)ddt=0.; x1=vx1*ddt; y1=vy1*ddt; x2=vx2*ddt; y2=vy2*ddt; r12=Math.sqrt((x1x2)*(x1x2)+(y1y2)*(y1y2)); //calculate component of velocity cs=(x2x1)/r12; sc=(y2y1)/r12; vp1=vx1*cs+vy1*sc; vp2=vx2*cs+vy2*sc; // normal components do not change vn1=vx1*scvy1*cs; vn2=vx2*scvy2*cs; //calculate component of velocity in original X,Y coordinate px1=vp1*cs; py1=vp1*sc; px2=vp2*cs; py2=vp2*sc; nx1=vn1*sc; ny1=vn1*cs; nx2=vn2*sc; ny2=vn2*cs; }



Logged




solashok
Newbie
Offline
Posts: 1


«
Embed this message
Reply #23 on: February 28, 2007, 09:22:43 am » 

Respected Sir, when two atoms collide using Conservation of Momentum and Energy we get expression for E2 = 4M1M2 cos square phi E0/(M1 + M2)square. Can U suggest me how this has come.



Logged




FuKwun Hwang


«
Embed this message
Reply #24 on: February 28, 2007, 10:15:32 am » 

What is the situation you want to discuss about? There is no way to discuss if question is not well defined! What are the meaning for E0,E2 and what is the formula you want to show? And how did you get that formula?



Logged




mrsdost
Newbie
Offline
Posts: 2


«
Embed this message
Reply #25 on: April 18, 2007, 11:13:41 pm » 

Hello Professor, I am currently working on the following question and was wondering if you could offer any help. I'm just not sure how to factor in the 30 degrees. this is of course a completely elastic collision. any help would be great. Thanks, mrsdost Two pool balls are rolling along a pool table. The red pool ball has a velocity of 10 cm/s west and the blue ball a velocity of 10 cm/s north 30° east. What are the velocities of the balls after the collision?



Logged




FuKwun Hwang


«
Embed this message
Reply #26 on: April 19, 2007, 01:01:41 am » 

You can find out the answer easily. Just use mouse to drag the velocity vector for each ball in the simulation (conditions match with your problem) and find out the answer by yourself!



Logged




mrsdost
Newbie
Offline
Posts: 2


«
Embed this message
Reply #27 on: April 19, 2007, 09:55:36 pm » 

Thank you Professor, but i need to learn how to do the calculations myself. So if you could help me with some formulas that include the vectors of the balls that would be great. Thank you, Mrsdost



Logged




FuKwun Hwang


«
Embed this message
Reply #28 on: April 19, 2007, 10:09:51 pm » 

Please look at all the forum messages in this topic carefully, all the steps (in detail) have been posted. I guess you did not read this forum messages carefully. If you did read it and still did not understand it. Please at least indicate where you did not get it.



Logged




arthurprs
Newbie
Offline
Posts: 10


«
Embed this message
Reply #29 on: July 22, 2007, 01:41:57 am » 

Hi professor, sorry to bother you, but im having some dificult here to make your code work This is my code in OPascal not much dif from java dx := ball[i].cx  ball[n].cx; dy := ball[i].cy  ball[n].cy; dist := Sqrt(Power(dx, 2) + Power(dy, 2)); if dist <= (ball[i].raio + ball[n].raio) then begin ax := dx / dist; ay := dy / dist; vp_n := (ball[n].vx * ax) + (ball[n].vy * ay); vp_i := (ball[i].vx * dx) + (ball[i].vy * ay); dt := ((ball[i].raio + ball[n].raio)  dist) / (vp_n + vp_i); ball[n].x := ball[n].x  (ball[n].vx * dt); ball[n].y := ball[n].y  (ball[n].vy * dt); ball[i].x := ball[i].x  (ball[i].vx * dt); ball[i].y := ball[i].y  (ball[i].vy * dt);
You can see something wrong ? *sorry my bad english, im from brazil EDIT: If u can send me the source code to my email it will be helpfull too


« Last Edit: July 22, 2007, 01:24:22 pm by arthurprs »

Logged




