NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

JDK1.0.2 simulations (1996-2001) => Dynamics => Topic started by: Fu-Kwun Hwang on January 29, 2004, 04:14:42 pm

 Title: 1D collision : Conservation of Momentum Post by: Fu-Kwun Hwang on January 29, 2004, 04:14:42 pm 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 $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. Title: topic5 Post by: on January 30, 2004, 11:10:16 am Subject: Conservation of Linear Momentum Date: Tue, 28 Jul 1998 09:14:28 +0800 From: Lim Ai Phing Reply-To: lap@pacific.net.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 Title: circles Post by: on April 01, 2004, 10:04:35 pm The circles should be different colors to make it easier to differentiate between them. Title: Thank you for your suggestion Post by: Fu-Kwun Hwang on April 10, 2004, 01:53:40 pm As you wish!  I hope you like it better now! Title: topic5 Post by: andrewsmith 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? Title: Re: 1D collision : Conservation of Momentum Post by: Javed on June 13, 2007, 07:42:33 pm great program, can u please email me the source code, thanks Title: Re: 1D collision : Conservation of Momentum Post by: Fu-Kwun Hwang on June 20, 2007, 11:57:55 am You should have received the source code now. Title: Re: 1D collision : Conservation of Momentum Post by: Javed on June 20, 2007, 03:31:06 pm thank you Title: Re: 1D collision : Conservation of Momentum Post by: afg on December 22, 2008, 04:16:16 pm Hi,Your program is great. Can I get the source code for it?Thank you. Title: Re: 1D collision : Conservation of Momentum Post by: Fu-Kwun Hwang on December 22, 2008, 04:18:01 pm Please check out the attachment under the first message. Title: Re: 1D collision : Conservation of Momentum Post by: ArdTraveller on January 06, 2009, 06:30:14 pm Yeah it's a fantastic simulation can I get the source code too?THANKS Title: Re: 1D collision : Conservation of Momentum Post by: Fu-Kwun Hwang 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?  :o :o ::) Title: Re: 1D collision : Conservation of Momentum Post by: Question on January 14, 2009, 12:45:51 pm Hello sirsince u gave the source code for this 1D collisionI 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. Title: Re: 1D collision : Conservation of Momentum Post by: Fu-Kwun Hwang on January 14, 2009, 04:43:57 pm You will find the source code for JDK1.0.2 version collision 2D applet in the downloaded ZIP file for that applet. Title: Re: 1D collision : Conservation of Momentum Post by: Question on February 16, 2009, 09:19:33 am 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? Title: Re: 1D collision : Conservation of Momentum Post by: Fu-Kwun Hwang 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. Title: Re: 1D collision : Conservation of Momentum Post by: summer_zwx 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! Title: Re: 1D collision : Conservation of Momentum Post by: Fu-Kwun Hwang 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)? Title: Re: 1D collision : Conservation of Momentum Post by: Question 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 :) Title: Re: 1D collision : Conservation of Momentum Post by: Fu-Kwun Hwang 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;  Title: Re: 1D collision : Conservation of Momentum Post by: Question on February 23, 2009, 07:51:11 pm Hello sir I don't get this line of code thoughadd("North",p);what does the "North" signify? Title: Re: 1D collision : Conservation of Momentum Post by: Fu-Kwun Hwang on February 23, 2009, 08:16:16 pm The above simulation was created more than 10 years ago with JDK1.0.2.add("North",p);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! Title: Re: 1D collision : Conservation of Momentum Post by: Question 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. Title: Re: 1D collision : Conservation of Momentum Post by: Fu-Kwun Hwang 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 fileCode:  private void readData (java.io.LineNumberReader _input) throws java.lang.Exception {      String line = _input.readLine();      while (line != null) {        // Process the input line according to your needs:        _println (line);        line = _input.readLine();      }  }    private boolean readFromFile (String _filename) {    try {      java.io.Reader reader=null;      if (_filename.startsWith("url:")) {        java.net.URL url = new java.net.URL (_filename.substring(4));        reader = new java.io.InputStreamReader(url.openStream());      }      else {        java.io.File file = new java.io.File(_filename);        reader = new java.io.FileReader (file);      }      java.io.LineNumberReader lineReader = new java.io.LineNumberReader(reader);      readData (lineReader);      reader.close();      return true;    }    catch (java.lang.Exception ioe) {      System.err.println ("Error when trying to read "+_filename);      ioe.printStackTrace(System.err);      return false;    }  }  public void read () { readFromFile (filename); }I believe you should be able to search the web for more information about "How to write data to a file"! Title: Re: 1D collision : Conservation of Momentum Post by: Question 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-X0.){            ddt=dt-(X+size2-X)/V;            if(ddt