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

Information about this web site => Physlet builder (Create your own simulation) => Topic started by: Fu-Kwun Hwang on August 30, 2007, 11:08:32 am



Title: Demo for BField (create two coils and find out the field lines
Post by: Fu-Kwun Hwang on August 30, 2007, 11:08:32 am
This demo shows how to create coils and display magnetic field line when double clicked into the simulation region.

Click Physlet Builder (http://www.phy.ntnu.edu.tw/ntnujava/physletBuilder/) to try it online.

         


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: lookang on August 30, 2007, 09:14:55 pm
movie not loaded  ;D


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: Fu-Kwun Hwang on August 30, 2007, 09:33:01 pm
Sorry! It should work now.


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: lookang on September 02, 2008, 10:24:07 am
i was exploring making a bar magnet using the builder

i made 2 coils align side by side and i could not figure out how to make the drag function

when the coils is drag, both coils move

can it be done on Physlets® html codes ?

http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=741.msg2753#msg2753

 name="AppletNames" value="Bfield">





Physlets®, i.e., the Java applets themselves, are a registered trademark of Wolfgang Christian.  


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: Fu-Kwun Hwang on September 02, 2008, 02:34:47 pm
You have added:
fkh.setDragable(id1,true);fkh.setDragable(id3,true);

So two of the coils can be dragged.


Quote
when the coils is drag, both coils move
???

Only the one being dragged is moving with the mouse.


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: lookang on September 03, 2008, 09:45:52 am
is there a way to set a constraint to force the drag to move id1 to id20 which are my magnetic coils, to move as one object?

in EJS, i think is possible :) in Physlet i hope can ?


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: Fu-Kwun Hwang on September 03, 2008, 05:26:13 pm
You can do almost what you want if you find the right functions available in physlet library and javascript codes.
Check out http://webphysics.davidson.edu/Applets/PhysletsDoc/index.html for information about physlet available functions.

You have the following javascript physlet code:
id1=fkh.addObject("coil","x=0,y=0,i=1,r=0.1");id2=fkh.addObject("coil","x=0.02,y=0,i=1,r=0.1");id3=fkh.addObject("coil","x=0.04,y=0,i=1,r=0.1");id4=fkh.addObject("coil","x=0.06,y=0,i=1,r=0.1");id5=fkh.addObject("coil","x=0.08,y=0,i=1,r=0.1");id6=fkh.addObject("coil","x=0.1,y=0,i=1,r=0.1");id7=fkh.addObject("coil","x=0.12,y=0,i=1,r=0.1");id8=fkh.addObject("coil","x=0.14,y=0,i=1,r=0.1");id9=fkh.addObject("coil","x=0.16,y=0,i=1,r=0.1");id10=fkh.addObject("coil","x=0.2,y=0,i=1,r=0.1");id11=fkh.addObject("coil","x=0.18,y=0,i=1,r=0.1");id12=fkh.addObject("coil","x=0.22,y=0,i=1,r=0.1");id13=fkh.addObject("coil","x=0.24,y=0,i=1,r=0.1");id14=fkh.addObject("coil","x=0.24,y=0,i=1,r=0.1");id15=fkh.addObject("coil","x=0.26,y=0,i=1,r=0.1");id16=fkh.addObject("coil","x=0.28,y=0,i=1,r=0.1");id17=fkh.addObject("coil","x=0.28,y=0,i=1,r=0.1");id18=fkh.addObject("coil","x=0.3,y=0,i=1,r=0.1");

where id1,id2,...id18 are integer variables. from the above web page you can find
double    getX(int id):           Get the x position of an object.
 boolean    setX(int id, double x)          Change the x of an object.
So if you only set id1 dragable with code
fkh.setDragable(id1,true);

Then, you can use x1=getX(id1); to get x coordinate for the dragged coil
then you can add
setX(id2,x1+=dx);
setX(id3,x1+=dx);
....
to set all the coils.
If you want user to drag coil in horizontal only. add the following code
setY(id1,0); // to fix y coordinate for the first coil


It will be easier if you use array object
for examples:
id=new Array(18);
x1=0;
for(i=0;i<18;i++){ // use this loop to create coils
 id=fkh.addObject("coil","x="+x1+",y=0,i=1,r=0.1");
 x1+=0.2;
}
Then it will be easier to move all the coil together
x1=getX(id[0]); y1=getY(id[0]);
for(i=1;i<18;i++){// move all the coils (x,y) together
 setX(id,x1+=dx);
 setY(id,y1);
}


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: lookang on September 08, 2008, 01:33:49 pm
amazing stuff, a bit difficult to follow for click click click type of users.

i found  http://webphysics.davidson.edu/Applets/PhysletsDoc/bfield/BField.html

setX

"public boolean setX(int id,
                    double x)

    Set X position of an object.

    Parameters:
        id - The ID of the object.
        x - The x coordinate."

i don't see

getX(int id):           Get the x position of an object. i can find getBx and getBy.


 but how do i use the code
"
x1=getX(id[0]); y1=getY(id[0]);
for(i=1;i<18;i++){// move all the coils (x,y) together
 setX(id,x1+=dx);
 setY(id,y1);
}
"
inside the rest of the html codes?

is there any examples to follow the syntax ? ;D


 






Title: Re: Demo for BField (create two coils and find out the field lines
Post by: Fu-Kwun Hwang on September 08, 2008, 04:02:40 pm


 name="AppletNames" value="Bfield">




OOPs!  You are correct. There is no getX function available.
I will write to Prof. Wolfgang and ask him what can be done to have the same effect.


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: Fu-Kwun Hwang on September 09, 2008, 01:07:16 pm
Prof. Wolfgang told me that : setX,setY and getX, getY will conflict with default java method.
So the function name have been change to setXPos, setYPos and getXPos,getYPos.

You can drag the leftmost coil in the previous physlet, then you need to click the button to move coils to new dragged position.

However, There is no onClick event available in physlet library.


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: lookang on September 09, 2008, 02:00:20 pm
1. the applets did not load on this page, is it because there are 2 applets ( one above by me, one just above by prof. hwang). strange maybe i am using firefox and i also open http://webphysics.davidson.edu/Applets/Poisson/Faraday.html

i think restart computer will solve it :)

it is super cool!!!, i saw it, it is fantastic!!


2. i can't modify your post to "see", how you use the coding, chance to discuss over at the board where i am a moderator ?
http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=741.msg2753#msg2753


thanks!


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: basementfloor on May 09, 2012, 01:23:06 pm
thanks...for...sharing....


-*-


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: roasting-88 on September 18, 2012, 12:15:21 pm
มันๆๆ  :o :o :o


Title: Re: Demo for BField (create two coils and find out the field lines
Post by: Comics-55 on September 19, 2012, 03:27:45 pm
ลุ้นด้วยกันป่าว ::) ::) ::) ::)