NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
December 13, 2017, 06:50:20 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Wisdom is to form a good attitude and a healthy lifestyle. ...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: Displacement and Distance travelled logic in Easy java simulation  (Read 13171 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: September 26, 2008, 11:52:02 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

Displacement and Distance traveled logic in Easy java simulation.


Displacement = Displacement - Displacement_initial; // easy in EJS

I was wondering how to do this elegantly?

Distance_travel = Math.abs ( Displacement) ?? does not look correct


Q1 :is there a

Distance_travel = Math.XXX ( Displacement) ? Smiley



or must i think of a  If ... else statement Huh

if (Displacement < initial_Displacement) {
  statements  ;

it is a bit more complicated that i thought

 }
 else if (expr) {
  statements;
 }
 else {
  statements;
 }

 Reference:
http://en.wikipedia.org/wiki/Java_syntax#If_..._else
« Last Edit: September 26, 2008, 01:35:02 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #1 on: September 26, 2008, 05:39:34 pm » posted from:Taipei,T'ai-pei,Taiwan

Displacement is a vector. Distance is line integral of absolute value of displacement.

It is possible to have zero displacement (back to original point) but the distance traveled is not zero.
For 2D case if you wan to calculate distance traveled=d.
define coordinate x,y and xs,ys (xs=x,ys=y, initially).
set d=0 at initialize page.

Assume evolution page is
dx/dt=vx;
dy/dt=vy;

At constraint page add the following lines:
d+= Math.sqrt((x-xs)*(x-xs)+(y-ys)*(y-ys));
xs=x;
ys=y;

Then, d is the distance traveled in 2D plane.
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #2 on: September 26, 2008, 10:28:54 pm »

thanks for the tip! i  will implement after 12 OCT 2008 as i am going to USA and Canada for holiday.

i  have not used "+=" before

At constraint page add the following lines:
d+= Math.sqrt((x-xs)*(x-xs)+(y-ys)*(y-ys));  // what is += ??  is it a syntax for line integral of absolute value of displacement.
xs=x;
ys=y;

that is so cool!
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #3 on: September 26, 2008, 11:15:33 pm »

d+=a; is a the same as d=d+a;
d-=a; is the same as d=d-a;
d*=a; is the same as d=d*a;
d/=a; is the same as d=d/a;

d++; is the same as d=d+1;
d--; is the same as d=d-1;

But d++ is not quiet the sam as ++d;

if  d=3;
x=d++; is the same as x=d; d=d+1;
so x=3; after x=d++; is execute

x=++d; is the same as d=d+1; x=d;
so x=4; after x=d++; is execute

For the above two case: d=4; after x=d++; is execute

I have chinese version web page about basic syntax for java. Please check out Java 程式基礎說明資料
There are similar document in english available on the web. Google will help you find it.

Enjoy you holiday! :-) Cheesy
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #4 on: October 14, 2008, 04:12:58 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

Hi prof!

I adapted the logic into the codes,

where d1 = distance traveled

x1s = x1 slider position
x1area = dummy variable for x1s counting of line integral


Codes:
d1 = d1 + Math.sqrt((x1s-x1area)*(x1s-x1area)); // same as +=
// d1 += Math.sqrt((x1-x1area)*(x1-x1area));
x1area=x1s; // x1area is just a way to do line integral
Codes:


The problem:
as I slide the time slider bar that controls ts = time slider variable.
The value of d1 is still counting as I slide time variable ts, which makes the value run continually which is not was i wanted.

I want to make it give the value for d1 = distance travel for time ts = 0 to ts = current position.

I tested these codes and they work fine in normal situation/simulation without the slider "ts".

Any tips how to trick the program into replay the value of d1 and ts ?

or do i need a different approach or strategy?

in case u need, the source code is attached Smiley
« Last Edit: October 14, 2008, 04:43:47 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #5 on: October 15, 2008, 10:02:53 am » posted from:Taipei,T'ai-pei,Taiwan

It is seems that what you need is not a real time simulation. You just need to show how displacement and velocity changed with time for constant acceleration.
The formula is all well know:
x(t)=x(0)+v(0)*t+0.5*t*t;
v(t)=v(0)+a*t;

Use the above equestion directly will be the easiest way to implement.
You can show the x-t or v-t diagram directly.
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #6 on: October 15, 2008, 11:54:58 am » posted from:Singapore,,Singapore

i see what you mean.......

x(t)=x(0)+v(0)*t+0.5*t*t;
v(t)=v(0)+a*t;

is good and already implemented it this way.

codes:
x1 = x1s - x10;


but the distance traveled is another concept in secondary school as the Math.abs (integral of the area under the v-t graph) as distance traveled.

i am having difficulty implementing it elegantly (because there is positive area and Math.abs|negative| area).
 Grin


Thanks!

so far, i think the best approach for me is by brute force aka not so elegant way Smiley( if statements )
codes:
if(v10>=0 && v1s>=0){
d1 = Math.abs(0.5*(v10+v1s)*(ts-0));
}
if(v10<=0 && v1s<=0){
d1 = Math.abs(0.5*(v10+v1s)*(ts-0));
}
if(v10>=0 && v1s<0){
tprime= v10*ts/(v10-v1s);
dtest = Math.abs(0.5*(ts-tprime)*v1s);
d1 = Math.abs(0.5*(v10)*tprime) + Math.abs(0.5*(ts-tprime)*v1s);
}
if(v10<=0 && v1s>0){
tprime= v10*ts/(v10-v1s);
dtest = Math.abs(0.5*(ts-tprime)*v1s);
d1 = Math.abs(0.5*(v10)*tprime) + Math.abs(0.5*(ts-tprime)*v1s);
}

I have do it!!!
« Last Edit: October 15, 2008, 02:12:39 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #7 on: October 15, 2008, 04:37:23 pm » posted from:Taipei,T'ai-pei,Taiwan

The above code can be simplified as
if(v10>=0 && v1s<0){
tprime= v10*ts/(v10-v1s);
dtest = Math.abs(0.5*(ts-tprime)*v1s);
d1 = Math.abs(0.5*(v10)*tprime) + Math.abs(0.5*(ts-tprime)*v1s);
}else if(v10<=0 && v1s>0){
tprime= v10*ts/(v10-v1s);
dtest = Math.abs(0.5*(ts-tprime)*v1s);
d1 = Math.abs(0.5*(v10)*tprime) + Math.abs(0.5*(ts-tprime)*v1s);
}else{
d1 = Math.abs(0.5*(v10+v1s)*(ts-0));
}

Logged
Pages: [1]   Go Up
  Print  
Wisdom is to form a good attitude and a healthy lifestyle. ...Wisdom
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Easy java simulation (Download and related informations)
Information and Download
Fu-Kwun Hwang 20 86606 Last post January 04, 2017, 07:13:01 pm
by smily
Offcial web site for Easy Java Simulation
Information and Download
Fu-Kwun Hwang 4 12320 Last post October 12, 2015, 12:41:26 pm
by dissertationwriting
Research Papers on Easy Java Simulation
Information and Download
lookang 10 29056 Last post April 14, 2016, 04:03:56 pm
by saima
HCI Ed Tech 2010 Introduction to the basic use of Easy Java Simulations. part 1
EJS tutorial (How to create simulation with EJS)
lookang 2 6353 Last post April 05, 2010, 09:41:12 am
by Fu-Kwun Hwang
Stopwatch using Easy Java Simulation
Information and Download
dhasthagheer 7 23873 Last post August 17, 2012, 09:32:22 pm
by meng1004
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.058 seconds with 23 queries.since 2011/06/15