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

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: lookang on September 29, 2010, 03:11:44 pm



Title: how to make a vectorField2D dynamically selectable?
Post by: lookang on September 29, 2010, 03:11:44 pm
how to make a vectorField2D dynamically selectable?

currently i can make it show if i go inside Ejs and change n = 11 to n =30.

but i can't remember and i can't find previous posting on this
can ask how to make a vectorField2D dynamically selectable?

want to allow students to vary the visual vectorField2D to see that it is just a representation like in the 2 attached picture.

thanks!
trying to make a better version of this http://webphysics.davidson.edu/physlet_resources/bu_semester1/c17_field.html http://webphysics.davidson.edu/physlet_resources/bu_semester1/index.html in Ejs


Title: Re: how to make a vectorField2D dynamically selectable?
Post by: Fu-Kwun Hwang on September 30, 2010, 04:48:37 pm
Quote
how to make a vectorField2D dynamically selectable?
What do you mean? Do you mean show/hide vectorField2D?


Title: Re: how to make a vectorField2D dynamically selectable?
Post by: lookang on September 30, 2010, 05:50:32 pm
Not show/hide. I know that already hahaha. Visible=true

What I need to understand:
A slider n that controls number of field vectors array [n][n] to plot.
See the 2 pictures attached in first post.


Title: Re: how to make a vectorField2D dynamically selectable?
Post by: Fu-Kwun Hwang on September 30, 2010, 10:35:15 pm
I have not done this before.
The following way might work. (But I am not sure).
EJS use the variable name to find out the dimension for that variable (to draw those vectors).

So you need to dynamically re-define/re-assign the array.
e.g. bx=new double[nx][ny]; by=new double[nx][ny]
And assign values (with loop) to those two arrays.



Title: Re: how to make a vectorField2D dynamically selectable?
Post by: lookang on October 01, 2010, 08:00:41 am
u r a geniune!
thx!

i got it to work!
cool!
the code looks like this

Code:
n=ns;
gx=new double[n][n]; gy=new double[n][n];
for(int i=0;i<n;i++){
 for(int j=0;j<n;j++){
gx[i][j]=0;
gy[i][j]= g;

 }
}