NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
September 25, 2017, 03:10:15 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Establish Good support system. ...Wisdom
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: Newton cradle  (Read 21504 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
on: June 10, 2008, 03:30:37 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

any interest to create a newton's cradle for learning objective:

conservation of momentum

conservation of kinetic energy


The current well reference applet is this one by walter but it is still can be modified to a learner centered exploration simulation instead of a show and tell"see".

good idea?

reference:
http://www.walter-fendt.de/ph11e/ncradle.htm


found the source code in german from http://duepublico.uni-duisburg-essen.de/servlets/DerivateServlet/Derivate-81/Pendel5.java
Code:
// Applet zur Simulation von fünf Pendeln
// (Demonstration von Impuls- und Energieerhaltungssatz
// 03.11.1997 - 22.05.1998

import java.applet.*;
import java.awt.*;
import java.util.*;

public class Pendel5 extends Applet implements Runnable {

  int width, height;
  Graphics g1, g2;
  Image offscreen;
  Thread animatorThread;
  Choice ch;  // Auswahlbox für Zahl der ausgelenkten Pendel
  final int n = 5;  // Zahl der Pendel
  int k = 2;  // Zahl der ausgelenkten Pendel
  final int r = 20;  // Radius der Pendelkörper
  final int ax = 120, ay = 50;  // Aufhängung des linken Pendels
  final int l = 200;  // Pendellänge
  final double A = 0.4;  // Amplitude (Bogenmaß)
  final double T = 2;  // Schwingungsdauer (s)
  final double omega = 2*Math.PI/T;  // Kreisfrequenz (1/s)
  double phi;  // Phase (Bogenmaß)
  Date d;
  long t0 = 0, t1 = 0;  // Zeit (ms)
  double t = 0;  // Zeit (s)
  int px, py;  // Mittelpunkt der Pendelkörper

  public void init() {
  width = bounds().width; height = bounds().height;
  g1 = getGraphics();
  offscreen = createImage(width,height); g2 = offscreen.getGraphics();
  animatorThread = null;
  ch = new Choice();
  ch.addItem("  1  "); ch.addItem("  2  "); ch.addItem("  3  "); ch.addItem("  4  ");
  add(ch); ch.select(1);
  }

  public void drawPendulum (int i) {
  while (t >= T) t -= T;
  phi = A*Math.cos(omega*t);
  if (((t<0.25*T || t>=0.75*T) && i=0.25*T && t<0.75*T && i>=n-k)) {
  px = (int)(ax+i*2*r-l*Math.sin(phi)+0.5);
  py = (int)(ay+l*Math.cos(phi)+0.5);
  g2.setColor(Color.black); g2.drawLine(ax+i*2*r,ay,px,py);
  g2.setColor(Color.blue); g2.fillOval(px-r,py-r,2*r,2*r);
  }
  else {
  g2.setColor(Color.black); g2.drawLine(ax+i*2*r,ay,ax+i*2*r,ay+l);
  g2.setColor(Color.blue); g2.fillOval(ax+i*2*r-r,ay+l-r,2*r,2*r);
  }
  }

  public void paint (Graphics g) {
  int i;
  g.setColor(Color.yellow); g.fillRect(0,0,width,height);
  g.setColor(Color.black); g.fillRect(50,ay-2,300,4);
  for (i=0;i<5;i++) drawPendulum(i);
  }

  public boolean action (Event e, Object o) {
  if (e.target==ch) k = ch.getSelectedIndex()+1;
  paint(g2); g1.drawImage(offscreen,0,0,this);
  return true;
  }

  public void start () {
  if (animatorThread == null) {
  animatorThread = new Thread(this);
  animatorThread.start();
  }
  }

  public void stop () {
  if (animatorThread != null && animatorThread.isAlive())
  animatorThread.stop();
  animatorThread = null;
  }

  // Laufen des Programms (Endlosschleife):

  public void run () {
  d = new Date(); t0 = d.getTime();
  while (true) {
  paint(g2); g1.drawImage(offscreen,0,0,this); 
  d = new Date();
  t1 = d.getTime(); t += (t1-t0)/1000.0;
  t0 = t1;
  }
  }

  }
« Last Edit: June 10, 2008, 04:15:39 pm by lookang » Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #1 on: June 10, 2008, 04:43:42 pm » posted from:Singapore,,Singapore

is it possible to copy and paste the source code above into the EJS Model Custom and get the code to work?


It will be cool if it can be done !!??

anyway this is the code message

Generating simulation file
  D:\EasyJavaSimulation\Ejs3.47_080301\Ejs\Simulations\_apps\a.app\a.java ...
D:\EasyJavaSimulation\Ejs3.47_080301\Ejs\Simulations\_apps\a.app\a.java:93: illegal start of type
  import java.applet.*;  // > Custom.Lib Page:4
  ^
D:\EasyJavaSimulation\Ejs3.47_080301\Ejs\Simulations\_apps\a.app\a.java:93: expected
  import java.applet.*;  // > Custom.Lib Page:4
  ^
D:\EasyJavaSimulation\Ejs3.47_080301\Ejs\Simulations\_apps\a.app\a.java:94: illegal start of type
  import java.awt.*;  // > Custom.Lib Page:5
  ^
D:\EasyJavaSimulation\Ejs3.47_080301\Ejs\Simulations\_apps\a.app\a.java:94: expected
  import java.awt.*;  // > Custom.Lib Page:5
  ^
D:\EasyJavaSimulation\Ejs3.47_080301\Ejs\Simulations\_apps\a.app\a.java:95: illegal start of type
  import java.util.*;  // > Custom.Lib Page:6
  ^
D:\EasyJavaSimulation\Ejs3.47_080301\Ejs\Simulations\_apps\a.app\a.java:95: expected
  import java.util.*;  // > Custom.Lib Page:6
  ^
6 errors
Compilation produced an error!
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #2 on: June 10, 2008, 09:39:26 pm »

The applet shown at http://www.walter-fendt.de/ph11e/ncradle.htm is not a real simulation.
It just use java to draw what you would expect.
You should be able to use EJS to do the same thing easily.
Try it. And I will help you.
And EJS can even create a real simulation, for example: what if the mass is different.

You can create a real simulation if you modify Simulations\BallsInBox.app\BallsInBox.xml
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #3 on: June 10, 2008, 10:22:30 pm » posted from:Singapore,,Singapore

ok i try Smiley

« Last Edit: June 11, 2008, 04:53:57 pm by lookang » Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #4 on: June 11, 2008, 04:59:10 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

File successfully read BallsInBox.xml
File saved successfully users/wee/BallsInBox.xml
Generating simulation file BallsInBox...
Compilation successful
Congratulations! The simulation was generated successfully.
Trying to run simulation BallsInBox...
Sorry! The simulation produced a run-time error.

strange after that i run again ok now............


Qn:  How to construct a string or rod constraint on the balls ?

My thoughts:
Experiment 2 looks the best to modify from.

« Last Edit: June 11, 2008, 05:08:10 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #5 on: June 11, 2008, 05:21:27 pm » posted from:Taipei,T\'ai-pei,Taiwan

If you use angle cta as independent variable, and write equation for cta, omega
For example:
 d(cta)/dt=omega;
 d(omega)/dt= -g*Math.sin(cta)/L;

x=xc+L*Math.sin(cta);
y=yc-L*Math.cos(cta);

Then you will have a pendulum.
This is one of the example I taught (if you have check out my flash tutorial about EJS).
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #6 on: June 11, 2008, 10:45:24 pm »

why is the
Code:
[flash=200,200][/flash]
not working ? Cheesy

anyway i did a search but cannot find the swf tutorial on pendulum

example for search result using the word "flash"

http://www.phy.ntnu.edu.tw/demolab/swf/shm1.swf
http://www.phy.ntnu.edu.tw/ntnujava/swf/micrometer2.swf

i also can't do a listing of the directory so i can't find the tutorial you are refering too.

i think i can manage a simple task that you hinted.

i notice you like to use cta , omega..... in other xml.....i try

is the logic ( big picture like this)

1. make one pendulum think i can find a sample
2. make 5 pendulum by duplicating position side by side
3. add in event handlers for collisions found in BallsInBox.xml

4. how to add the control for number of balls to displace ?
5. how to add when to release the balls?

i doubt i can follow even if you try to explain.
i will consult you again when need . thanks!

One more qn:
x=xc+L*Math.sin(cta);
y=yc-L*Math.cos(cta);
This is one of the example I taught (if you have check out my flash tutorial about EJS).

is xc the change in x ? if it is, then i understand

« Last Edit: June 12, 2008, 12:21:53 am by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #7 on: June 12, 2008, 04:52:23 pm » posted from:Taipei,T\'ai-pei,Taiwan

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 TIME

I just create an applet similar to the one at http://www.walter-fendt.de/ph11e/ncradle.htm





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 TIME
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #8 on: June 12, 2008, 06:49:38 pm »

you are amazing.

thanks for creating free interactive learning environments.

i see how you do it and learn, remix it to personalized learning for my students Grin
« Last Edit: June 12, 2008, 06:58:53 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #9 on: June 12, 2008, 08:38:08 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 TIME

But the above simulation did not really calculate the collision effect. It only use theoretical result to show expected result. I will try to create one which mass are not the same.
It is done. The following is the real simulation.
It is not quite the same as the above one, when all the mass are the same. (It is due to numerical error, but it is close to the real device).
When the simulation is paused: you can use slider to change the id (from 0-4) , then change the mass for the selected particle.
Press initialize to freeze all the particle, and move the first one with a small angle.


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 TIME
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #10 on: June 12, 2008, 11:52:28 pm »

yes i understand. it is a logic animation with simulation of the motion under gravity.

i was trying to find a way to show the energy

kineticenergy[1] = 0.5*mass[1]*L[1]*L[1]*omega[1]*omega[1]
and
potentialenergy[1] = mass[1]*g*L[1]*(1-Math.cos(cta[1])

and use the event handlers in BallsInBox.xml and the evolution for the balls.

it is a very interesting puzzle........ i need some time to think.

my thought strategy is use the BallsInBox.xml to build in the cta and omega because i can't use your due to my lack of code programming power.


anyway your newton cradle is now the most accurate java applet.

I thank you Smiley

« Last Edit: June 16, 2008, 10:30:39 pm by lookang » Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #11 on: June 13, 2008, 12:01:30 am »

your newtonscadlereal is now the most accurate simulation, just surpass your other simulation.

I will have to find time to read your code. Tongue again for personalizing it for my teaching objectives. 

Thanks!!
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #12 on: June 13, 2008, 04:57:18 pm » posted from:Taipei,T\'ai-pei,Taiwan

You can use the code in "newtonscadlereal" to study how to process "event" in EJS.
you need to return negative for EJS know event occurs, and it can adjust the time step to find the exact time event really happened.  (Adjust time step so that the return value is minimum).

Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #13 on: June 16, 2008, 08:12:31 pm »

i want to do this:

ketotal = kineticenergy[0]+kineticenergy[1]+kineticenergy[2]+kineticenergy[3]+kineticenergy[4];


but how to do it using the

Code:
for(int i=0;i
ketotal = ketotal+kineticenergy[i]++;

}

how to tell the program to reset the ketotal ?
« Last Edit: June 16, 2008, 09:59:20 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #14 on: June 16, 2008, 08:45:02 pm »

ketotal=0; // add this
for(int i=0;i<n;i++){
 ketotal=ketotal+kineticenergy;
}

Code:
If you want to show "<", you will have to type "& lt;". (without space in between)
If you want to show ">", you will have to type "& gt;".
Because you can use html code directly (while normal user can not), so the system will interprete "<" as part of html code.
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #15 on: June 16, 2008, 10:02:29 pm »

oic...........

Quote
ketotal=0; // add this

at the beginning of the loop statement....thanks!!

i managed to add the kinetic, potential n total energy


to do list:
1. i will try to add a simple way for the balls to be draggable, along the arc of the rotation.
2. i will then try to add a logic statement for dragging other balls.

this guy's flash is amazingly simple
http://www.flashkit.com/movies/Scripting/Physics/Newtons-Bryan_He-9109/index.php




« Last Edit: June 16, 2008, 10:44:22 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #16 on: June 17, 2008, 07:12:04 am »

The flash version assume pendulum1._rotation = ball1*(Math.exp(-damping*to))*angle*Math.sin(fac*to);
That is why it is simpler.
Logged
Pages: [1]   Go Up
  Print  
Establish Good support system. ...Wisdom
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Newton
Molecular Workbench
concord 0 10646 Last post August 21, 2005, 09:17:42 am
by concord
Understanding momentum and its relation to newton 2nd law (constant force)
Collaborative Community of EJS
LeeTl 7 11497 Last post February 19, 2009, 01:38:51 pm
by Fu-Kwun Hwang
Newton's Cradle by lookang
Simulations from other web sites
ahmedelshfie 3 8399 Last post June 30, 2015, 06:47:55 pm
by dana304
Newton's cradle
Dynamics
Fu-Kwun Hwang 9 14355 Last post November 28, 2010, 09:58:46 pm
by Fu-Kwun Hwang
Newton's cradle
dynamics
ahmedelshfie 1 7291 Last post October 20, 2010, 05:03:58 pm
by ahmedelshfie
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.109 seconds with 22 queries.since 2011/06/15