Author Topic: Demo for BField (create two coils and find out the field lines  (Read 31314 times)

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
This demo shows how to create coils and display magnetic field line when double clicked into the simulation region.

Click Physlet Builder to try it online.



lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Demo for BField (create two coils and find out the field lines
« Reply #1 on: August 30, 2007, 10:14:55 pm »
movie not loaded  ;D

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Demo for BField (create two coils and find out the field lines
« Reply #2 on: August 30, 2007, 10:33:01 pm »
Sorry! It should work now.

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Demo for BField (create two coils and find out the field lines
« Reply #3 on: September 02, 2008, 11: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.

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Demo for BField (create two coils and find out the field lines
« Reply #4 on: September 02, 2008, 03: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.

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Demo for BField (create two coils and find out the field lines
« Reply #5 on: September 03, 2008, 10: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 ?

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Demo for BField (create two coils and find out the field lines
« Reply #6 on: September 03, 2008, 06: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);
}

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Demo for BField (create two coils and find out the field lines
« Reply #7 on: September 08, 2008, 02: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


 





Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Demo for BField (create two coils and find out the field lines
« Reply #8 on: September 08, 2008, 05: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.

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Demo for BField (create two coils and find out the field lines
« Reply #9 on: September 09, 2008, 02: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.

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: Demo for BField (create two coils and find out the field lines
« Reply #10 on: September 09, 2008, 03: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!
« Last Edit: September 09, 2008, 03:13:21 pm by lookang »

basementfloor

  • Newbie
  • *
  • Posts: 1
    • Basement Flooring
Re: Demo for BField (create two coils and find out the field lines
« Reply #11 on: May 09, 2012, 02:23:06 pm »
thanks...for...sharing....


-*-

roasting-88

  • Newbie
  • Posts: -1
Re: Demo for BField (create two coils and find out the field lines
« Reply #12 on: September 18, 2012, 01:15:21 pm »
?????  :o :o :o

Comics-55

  • Newbie
  • *
  • Posts: 2
Re: Demo for BField (create two coils and find out the field lines
« Reply #13 on: September 19, 2012, 04:27:45 pm »
??????????????? ::) ::) ::) ::)