NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
January 21, 2018, 12:09:15 am

"Vision, mission and action." ...Wisdom

 Pages: [1]   Go Down
 Author Topic: 1D collision : Conservation of Momentum  (Read 229664 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message on: January 29, 2004, 04:14:42 pm » posted from:,,Satellite Provider

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
There are 7 translations,
Higher number at the end means more translation been done.
or

Newton's law of motion look the same to all observers in inertial frames of reference.
It is equally true that if momentum is conserved in one inertial reference frame, it is conserved in all inertial frames.

This java applet apply the above concept to one dimensional collision problem.
Two circular objects are confined to move in one diminution (between two gray blocks).
Press start button to run the animation.
Circular objects will move with some predefined velocity (yellow arrow).

Click the mouse button to pause. Click it again to resume the animation.

While the animation is suspended:
Click near the arrow of the velocity vector and drag it left/right to change the initial velocity.
Click at the center of the circle to move it : drag the object left <--> right.
Click within the circle to change the mass of that object.
Click right mouse button to increase mass by one unit.
Click left mouse button to decrease mass one unit.

Press Reset to reset most parameters to default values.
eta is the coefficient of restitution
eta = | relative velocity just after collision/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 $m_1$, right circular object math_failure (math_image_error): m_2 and center of mass for $m_1$ and $m_2$.

The velocity of two objects after collision ($V'_1,V'_2$)can be calculated from velocity before collisions ($V_1,V_2$) and mass of two objects ($m_1,m_2$).

From conservation of momentum $m_1 V_1+m_2 V_2=$ $m_1 V'_1+m_2 V'_2$,
and conservation of energy $\tfrac{1}{2}m_1V_1^2+\tfrac{1}{2}m_2V_2^2=\tfrac{1}{2}m_1V_1'^2+\tfrac{1}{2}m_2V_2'^2$
So $m_1 (V_1-V_1')=m_2(V_2'-V_2)$
and $\tfrac{1}{2}m_1 (V_1^2-V_1'^2)=\tfrac{1}{2}m_2 (V_2'^2-V_2^2)$, which means $\tfrac{1}{2}m_1 (V_1-V_1')(V_1+V_1')=\tfrac{1}{2}m_2 (V_2'-V_2)(V_2'+V_2)$
So $V_1+V_1'=V_2'+V_2$

i.e. The equation need to be solved are
$m_1 V_1'+m_2 V_2'=$ $m_1 V_1+m_2V_2$ and $V_2'-V_1'=V_2-V_1$

The result is
$V'_1= \frac{m_1-m_2}{m_1+m_2} V_1 +\frac{2m_2}{m_1+m_2}V_2=V_{cm}+\frac{m_2}{m_1+m_2}(V_2-V_1)=2V_{cm}-V_1$
and $V'_2=\frac{2m_1}{m_1+m_2}V_1+\frac{m_2-m_1}{m_2+m_1}V_2=V_{cm}+\frac{m_1}{m_1+m_2}(V_1-V_2)=2V_{cm}-V_2$
where $V_{cm}=\frac{m_1V_1+m_2V_2}{m_1+m_2}$

It means that $V'_1-V_{cm} = - (V_1-V_{cm})$ and $V'_2-V_{cm}= - (V_2-V_{cm})$
or $V'_{1cm}= -V_{1cm}$ and $V'_{1cm}= -V_{1cm}$ where $V'_{1cm}=V'_1-V_{cm}$ ...etc.
From the point of center of mass coordinate system: both particles bounce back with the same speed (relative to center of mass).

-*-

You are welcomed to check out collision in 2 dimension.

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
There are 7 translations,
Higher number at the end means more translation been done.
or
 *** There are 1 more attached files. You need to login to acces it! Logged
Guest
 « Embed this message Reply #1 on: January 30, 2004, 11:10:16 am » posted from:,,Satellite Provider

Subject: Conservation of Linear Momentum
Date: Tue, 28 Jul 1998 09:14:28 +0800
From: Lim Ai Phing <zuc@moe.edu.sg>
To: hwang@phy03.phy.ntnu.edu.tw
hi!!
I'm a physics teacher presently teaching my students dynamics.
Your collision java applet is really good, I'll ask my students to take a look here!!
But can I suggest that the colour of the numbers be changed
because yellow doesn't show up much against a gray background?
Aiping
 Logged
Guest
 « Embed this message Reply #2 on: April 01, 2004, 10:04:35 pm »

The circles should be different colors to make it easier to differentiate between them.
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #3 on: April 10, 2004, 01:53:40 pm »

As you wish! I hope you like it better now!
 Logged
andrewsmith
Newbie

Offline

Posts: 1

 « Embed this message Reply #4 on: November 27, 2004, 12:59:44 am »

Could you use some visual indication of relative mass? Maybe increase the size of the masses or the thickness of the circle?
 Logged
Javed
Newbie

Offline

Posts: 2

 « Embed this message Reply #5 on: June 13, 2007, 07:42:33 pm »

great program, can u please email me the source code, thanks
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #6 on: June 20, 2007, 11:57:55 am »

You should have received the source code now.
 Logged
Javed
Newbie

Offline

Posts: 2

 « Embed this message Reply #7 on: June 20, 2007, 03:31:06 pm »

thank you
 Logged
afg
Newbie

Offline

Posts: 1

 « Embed this message Reply #8 on: December 22, 2008, 04:16:16 pm »

Hi,

Your program is great. Can I get the source code for it?

Thank you.
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #9 on: December 22, 2008, 04:18:01 pm » posted from:Taipei,T'ai-pei,Taiwan

Please check out the attachment under the first message.
 Logged
ArdTraveller
Newbie

Offline

Posts: 12

 « Embed this message Reply #10 on: January 06, 2009, 06:30:14 pm »

Yeah it's a fantastic simulation can I get the source code too?THANKS
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #11 on: January 06, 2009, 08:26:13 pm »

The source code is available as an attachment at the first message. I do not know why you did not see it?
 Logged
Question
Newbie

Offline

Posts: 10

 « Embed this message Reply #12 on: January 14, 2009, 12:45:51 pm »

Hello sir

since u gave the source code for this 1D collision

I would be happy if u could provide the source code for the Collision 2D
(the code that is not generated by EJS), coz it turns out that if i rewrite the code again in Netbeans i can't compile it, i want the output 2 be like the one for this 1D collision, meaning the source code of this 1D when i rewrote in Netbeans I could compile and run but not Collision 2D, thx 4 your help.
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #13 on: January 14, 2009, 04:43:57 pm » posted from:Taipei,T'ai-pei,Taiwan

You will find the source code for JDK1.0.2 version collision 2D applet in the downloaded ZIP file for that applet.
 Logged
Question
Newbie

Offline

Posts: 10

 « Embed this message Reply #14 on: February 16, 2009, 09:19:33 am » posted from:Kuala Lumpur,Kuala Lumpur,Malaysia

Sir what does the greenish x that is always in between the circular objects signify, and at what code line that enables it to move with the objects sir?
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #15 on: February 16, 2009, 09:47:19 am »

The greenish x mark is the coordinate of the center of mass for those two objects.

The center of mass is moving at constant velocity, either before or after the collision.
Because there is no extra force acting on the system (system with the above two objects).

Xcm= m1*x1+m2*x2/(m1+m2);

If you switch to cm(selection box): observer at center of mass , you will find the greenish x mark will not move.

 Logged
summer_zwx
Newbie

Offline

Posts: 1

 « Embed this message Reply #16 on: February 18, 2009, 05:39:06 am »

Hi, your Java Applet applications are so great!
Could you please  e-mail me the source code?
I am doing a project for designing an interface and I can't figure out how to draw the dynamic arrows.

Thank you so much!
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #17 on: February 18, 2009, 07:49:55 am »

There is an attached file (java source code) for the first message. Did not you see it (source code)?
 Logged
Question
Newbie

Offline

Posts: 10

 « Embed this message Reply #18 on: February 21, 2009, 11:52:40 am »

Sir, in the code there is this variable mcm( an int type) but I'm not sure what is it for, and the part where the collision is detected is at what code sir?

Oh yeah n one more thing sir, what technique did u use, in order to get the proper collision detection or what technique/s is involved to create this simulation, in the physics aspect as well( I don't want to know how to create the simulation from the EJS though-not yet), thx
 « Last Edit: February 21, 2009, 11:59:50 am by Question » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #19 on: February 21, 2009, 01:46:30 pm »

The above simulation was not created with EJS. It was created more than 10 years ago with JDK1.0.2.

The coordinate of center of mass Xcm=(m1*X1+m2*X2)/(m1+m2)=(m1*X1+m2*X2)/mcm;
So mcm=m1+m2 is the sum of those two particles.
It is defined to make calculate property in the center of mass system much easier.
e.g. Vcm=(m1*V1+m2*V2)/(m1+m2)=(m1*V1+m2*V2)/mcm;

The radius of two circles are R1 and R2,  the distance between two center of the curcle d=|x2-x1|,
if d < R1+R2 then we know the circles should have collided with each other when d=R1+R2;
So we need to move time backward with ddt=(R1+R2-d)/|V2-V1|.

X1=X1-V1*ddt;
X2=X2-V2*ddt;
This is moment those two circle collide with each other.
Then, use the formula shown at the first message (or check out standard physics textbook) to calculate velocity for each circle. (V1', V2')
Then move the time forward to t:
X1=X1+V1'*ddt;
X2=X2+V2'*ddt;

 Logged
Question
Newbie

Offline

Posts: 10

 « Embed this message Reply #20 on: February 23, 2009, 07:51:11 pm »

Hello sir I don't get this line of code though

what does the "North" signify?
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #21 on: February 23, 2009, 08:16:16 pm »

The above simulation was created more than 10 years ago with JDK1.0.2.

means add p element to the north side of current Panel (another GUI element).

I would suggest you understand the physics model in the code.
I would suggest you study how to create GUI in java or use EJS to generate GUI for you if you want to create another by yourself!
 Logged
Question
Newbie

Offline

Posts: 10

 « Embed this message Reply #22 on: February 28, 2009, 10:39:48 am »

Salutations sir, well being a novice in this Java thingy I was jus curious from the code of this 1D collision is it possible to like save results of collision or in other words the data into a text file  ???and how  ???what do I have to import and at what part to put the codes, could u pleaz help, thx.
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #23 on: February 28, 2009, 11:06:06 am »

Code:
private void saveData (java.io.FileWriter _output) throws java.lang.Exception {
// include one line for each ASCII line in your file
_output.write("A line of text\r\n"); // \r\n in Windows, only \n in Unix
_output.write("Another line of text\r\n");
}

private boolean saveToFile (String _filename) {
try {
java.io.File file = new java.io.File(_filename);
java.io.FileWriter fout = new java.io.FileWriter(file);
saveData (fout);
fout.close();
return true;
}
catch (java.lang.Exception ioe) {
System.err.println ("Error when trying to save"+_filename);
ioe.printStackTrace(System.err);
return false;
}
}

You can write
System.out.println(String_data);
to output String to java console as a quick way to get data.

If you need to read data from file
Code:
while (line != null) {
// Process the input line according to your needs:
_println (line);
}
}

private boolean readFromFile (String _filename) {
try {
if (_filename.startsWith("url:")) {
java.net.URL url = new java.net.URL (_filename.substring(4));
}
else {
java.io.File file = new java.io.File(_filename);
}
return true;
}
catch (java.lang.Exception ioe) {
System.err.println ("Error when trying to read "+_filename);
ioe.printStackTrace(System.err);
return false;
}
}

I believe you should be able to search the web for more information about "How to write data to a file"!
 Logged
Question
Newbie

Offline

Posts: 10

 « Embed this message Reply #24 on: March 09, 2009, 12:25:59 am »

Salutations sir, I'v got a problem again..I guess this line of code is where the collision is detected right, of the ball and the wall, rite?

if(X[5]-X[2]<size2){// m2 & wall
if(coeff>0.){
ddt=dt-(X[2]+size2-X[5])/V[2];
if(ddt<dt){
X[2]-=(V[2]-v0)*ddt;
X[5]-=(V[5]-v0)*ddt;
//V[2]=-coeff*V[2];
V[2]=-V[2];
if(frame==3)v0=(m1*V[1]+m2*V[2])/mcm;
v0=V[frame];
X[2]-=(V[2]-v0)*ddt;
X[5]-=(V[5]-v0)*ddt;
}
}else if(V[1]==V[2]) V[1]=V[2]=0.;
else V[2]=0;
}
V[3]=(m1*V[1]+m2*V[2])/mcm;
v0=V[frame];
X[3]=((m1*X[1]+m2*X[2])/mcm);
drawIt();
}

But when i changed the distance of the two walls further apart...

original code

g.fillRect((int)X[4]-size,yc-size4,size2,size8);
g.fillRect((int)X[5]-size,yc-size4,size2,size8);

to this

g.fillRect(0,yc-size4,size2,size8);
g.fillRect((int)X[5]+39,yc-size4,size2,size8);

..the balls don't move rite to the wall and before even reaching the wall they bounce back as if bouncing off the walls however proceed with the normal collision  .

Can u help me sir in explaining how do the balls actually "know" when they hit the wall and how should I lengthen the ability of the balls to travel, similar to how the balls in your collision 2D are capable of  . Thank you so much
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #25 on: March 09, 2009, 09:28:48 am » posted from:Taipei,T\'ai-pei,Taiwan

It has been a long time ago when I wrote the above code.
I guess x[2] is the center for ball 2, and x[5] is the coordinate for the wall.
If there distance x[5]-x[2]<size2 (assume x[5] is always large than x[2] )
Then the ball collide with the wall, so some code are used to calculated the collision process.

If you just want to change the wall position, you should change value for x[5] and keep the rest the same.

If you just change where you draw the wall, and you did not change the code to check the collosion: x[5].
The ball will be bounced back at the same place.
It is the same as you draw the wall at the wrong place.
 Logged
Question
Newbie

Offline

Posts: 10

 « Embed this message Reply #26 on: March 13, 2009, 05:02:34 pm » posted from:Kuala Lumpur,Kuala Lumpur,Malaysia

Salutations again sir, okay now I get how it is able to detect the wall, what bothers me now is how do I get the rectangle to change its area size

I'v tried to put this code thinking I can chng the rectangle size(in red):

public class collision extends Applet implements Runnable{

Dimension area= new Dimension(300,300);

but somehow when it starts or it runs the window frame is still the same before I modified
(End of first question)

Q2.
and I don't get wat does

this

area=size();code really mean
why is the size() method have the slash on the word size?-How do I know what the width of the frame or window is so that I know what area.width is wat value

Q3.
U said in order for the mass2 to detect the wall i have to change X[5] rite
(N i managed to get the blue circle to hit the border of the rectangle but had to change the X[5]=area.width-X[4];
to X[5]=area.width+5;)
I tried to change X[1] value
and X[4] value but the red circle keeps on bouncing back wen it didn't even hit the wall yet(in this case now I want it to hit the rectangle border)..therefore I plead from u sir could u plz shed some light on this, coz I'm at blur ..i know that the division of X[4]by 6 has to with the plot in the frame similar to X[1] but how to make the red circle hit the the border of the rectangle I just don't know It's the reason I asked about the area.width thingyit must have some relation rite?Thx again
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #27 on: March 13, 2009, 05:31:36 pm » posted from:Taipei,T'ai-pei,Taiwan

In my code, the (width,height) of the applet is determined from parameter of the applet.
(You need to specify the width and height values in the applet tag-- Please check out html source for this page.)
area=size(); // get width and height value from applet created by browser. (browser use width/height value in applet tag to allocate area in the browser).
The above area include the area for the button/... at the top.
area.height-=yOffset;
to get the real area for the simulation region (exclude the top button/text input...).

Wall in the simulation was drawn with
//draw wall 1,wall2
g.setColor(Color.gray);
g.fillRect((int)X[4]-size,yc-size4,size2,size8);
g.fillRect((int)X[5]-size,yc-size4,size2,size8);
X4 and X5 is the x value for center of wall 1 and wall 2, and size2 is the width of the wall.
If you want to change the size, you should change 3th/4th parameters.
But you need to change the condition for collision according to the real width of the wall and radius of the circle.
Quote
U said in order for the mass2 to detect the wall i have to change X[5] rite
No. What I said was
Quote
If you just want to change the wall position, you should change value for x[5] and keep the rest the same.

I am will to help if you have problem with the physics involved.
You need to understand what is the condition to check for collision.
The best way is to write your own code. If you want to follow my code, you will need to understand how it work.
 Logged
aizen
Newbie

Offline

Posts: 1

 « Embed this message Reply #28 on: March 09, 2010, 05:04:11 pm » posted from:Angeles,Angeles,Philippines

Sir,
Thankyou very much! This is a very big help to me and my students as well.
 Logged
lookang
Hero Member

Offline

Posts: 1784

http://weelookang.blogspot.com

 « Embed this message Reply #29 on: March 10, 2010, 08:41:39 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

Agreed aizen!

The applets here are really helpful in learning.

The feature that is cool for me is:
the centre of mass., will add it here Ejs open source java applet 1D collision carts Elastic and Inelastic Collision http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=831.0 when time permits!

Thanks Prof Fu-Kwun Hwang!
 Logged
 Pages: [1]   Go Up
"Vision, mission and action." ...Wisdom