Title: Ejs Open Source 2 Bar Magnets & Compass Model java applet Post by: lookang on April 26, 2010, 04:29:18 pm Ejs Open Source 2 Bar Magnet & Compass Model java applet
it is an applet based on codes from Wolfgang Christian, Francisco Esquembre, Anne Cox and FuKwun Hwang http://www.compadre.org/osp/items/detail.cfm?ID=9414 http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1582.0 Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: lookang on April 26, 2010, 04:31:12 pm trying the make a 2 magnet model.
still debugging 1. working from an earlier model i remixed into http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1582.0 2. removed some stuff 3 added the ability to Lon and Ron thanks to Prof Hwang's code http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1602.msg6216#msg6216 4 added a scale on the right side of the applet for aid visualization 5 change the number of xField and yField to 41 instead to allow a zoom of 2 6 got the BField to work correctly by adding Prof Hwang's code http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1602.msg6216#msg6216 7 adding the B , Bx , By, angle to the display 8 debugging to get it to work beautifully challenges: getting getB to work for inside the magnets which i conceptualize to saturate to 225 arbitrarily following the Phet numbers still the applet will hang when the compass moves on drag. challenges: the compass reading, inside magnet, decide whether overlap magnets how? Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: FuKwun Hwang on May 14, 2010, 11:17:57 pm I am sorry that I was too busy in the last two weeks so that I was not able to help you with the coding.
Finally, I tried to modify from my previous version and the result (for two magnets) is the following : Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: lookang on May 15, 2010, 12:59:26 am it is beautiful!
thanks! there is so much to learn for this forum. U have made great difference for free access to education. Thanks a million. by the way, are you going to AAPT National Meetings Summer 2010, July 1721 (Portland, OR)? didn't see your name here http://www.aapt.org/Conferences/sm2010/loader.cfm?csModule=security/getfile&pageid=25158 I have an abstract accepted ;D WEE Loo Kang Physics Educators as Designers of Simulation Using Easy Java Simulation Simulated Learning/ Using Simulations to Teach Physics Contributed FI05 Salon Ballroom II 7/20/2010 2:30 PM 2:40 PM http://sgeducation.blogspot.com/2010/02/americanassociationofphysics.html Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: FuKwun Hwang on May 15, 2010, 09:38:51 pm I will attend GIREP2010 and MPTL join conference this Aug. , but I will not attend the AAPT meeting.
Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: lookang on May 16, 2010, 09:39:47 pm all the best!
working on the 2 bar magnet now. it works now! thanks for Code: bf1=getB(x*cs+y*sc,x*sc+y*cs,xMagnet*cs+yMagnet*sc,xMagnet*sc+yMagnet*cs);//FKH this the code that made the 2 bar magnet work ;Dbf2=getB(x*cs2+y*sc2,x*sc2+y*cs2,xMagnet2*cs2+yMagnet2*sc2,xMagnet2*sc2+yMagnet2*cs2);//FKH //xField[i][j] = b[0]; //yField[i][j] = b[1]; xField[i][j] = bf1[0]*csbf1[1]*sc+bf2[0]*cs2bf2[1]*sc2;//FKH yField[i][j] = bf1[0]*sc+bf1[1]*cs+bf2[0]*sc2+bf2[1]*cs2;//FKH // magField[i][j]=b[2]; magField[i][j]=Math.sqrt(xField[i][j]*xField[i][j]+yField[i][j]*yField[i][j]); Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: FuKwun Hwang on May 16, 2010, 10:18:25 pm It seems that there are someting wrong in your latest code.
Please check it again! Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: lookang on May 16, 2010, 10:38:16 pm is it? i didn't upload the jar yet, only the attachment cos it is still unfinished.
i am still working on it. but i just reuploaded 02 version on the first post in case you are looking at that one. i managed to work 2 bar magnets now, i will try to have no magnet( not working) , one magnet(seems to work) , 2 bar magnet (working ). i am working on the magnet field only, the compass is not correct yet because i wanted to show the magnet inside as a uniform magnetic field of 225T which the original wolfgang and paco version shows as a large uniform magnetic field due to short distance to any of the dipoles. will fix the compass after i figure out the field part. thanks! Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: FuKwun Hwang on May 16, 2010, 11:31:53 pm I thought you have found way to modify the code and upload it.
That is fine. Keep up with your work. ;) Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: FuKwun Hwang on May 17, 2010, 10:19:04 pm Lookang: I just made some change to the code. Please download latest version.
Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: lookang on May 18, 2010, 09:03:11 pm your the man! thanks for the Lon and Ron, will study your technique. hope to be like u one day ;D
Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: FuKwun Hwang on May 18, 2010, 10:56:31 pm The following functions has been modified:
public double[] getB(double xm,double ym) : to compute magnetic field at (xm,ym) related to (xMagnet,yMagnet) in public void computeField () : bf1=getB((xxMagnet)*cs+(yyMagnet)*sc,(xxMagnet)*sc+(yyMagnet)*cs);//FKH bf2=getB((xxMagnet2)*cs2+(yyMagnet2)*sc2,(xxMagnet2)*sc2+(yyMagnet2)*cs2);//FKH // the above two lines calculate field from two magnets xField[ i ][j] = lcst*(bf1[0]*csbf1[1]*sc)+rcst*(bf2[0]*cs2bf2[1]*sc2);//FKH yField[ i ][j] = lcst*(bf1[0]*sc+bf1[1]*cs)+rcst*(bf2[0]*sc2+bf2[1]*cs2);//FKH //calculate the sum of magnet field from two magnets magField[ i ][j]=Math.sqrt(xField[ i ][j]*xField[ i ][j]+yField[ i ][j]*yField[ i ][j]); Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: lookang on June 08, 2010, 08:47:17 am Hi prof Hwang!
i been thinking and looking at the codes for the 2 bar magnet java applet. I am unable to remix applet faster now, due to my baby girl 3 month old! ;D ;D need to pay more attention to family needs. BTW U can join facebook to see more photos of the baby! LOL http://www.facebook.com/lookang i managed to get your codes to work in my own remix java applet at the top post. i am stuck figuring out a clever way to make the getB values to saturate to the direction of the orientation of the bar magnet for both magnets. I have a version 04 that works for one magnet(http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=1602.0;attach=2846;image) but not both (http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=1602.0;attach=2848;image). This is your code! public double[] getB(double xm,double ym) { double[] b=new double[2]; for(int i=0; i < nd; i + +) { double dx=xmdipoles[ i ][0];//xm;////(xMagnet*cs+yMagnet*sc);//FKH double dy=ymdipoles[ i ][1];//ym;//(xMagnet*sc+yMagnet*cs);//FKH double r2=dx*dx+dy*dy; double r=Math.sqrt(r2); double r3=r2*r; double cos=dx/r; double sin=dy/r; b[0]+=m*(3*cos*cos1)/r3; //x component b[1]+=m*3*sin*cos/r3; //y component if(r2==0) { b[0]=b[1]=0; } } // b[2] = Math.sqrt(b[0]*b[0]+b[1]*b[1]); // magnitude // b[3] = Math.atan2(b[1],b[0]); // angle return b; } This is my code changes (latest version which i still couldn't get it to work the way inside the magnet) //inside any magnet if (xCompass<(xm+Magnetsizex/2) && xCompass>(xm(Magnetsizex/2)) && yCompass<(ym+Magnetsizey/2) && yCompass>(ymMagnetsizey/2)) { test = true; b[0] = (225)*vectorfieldmaxopposite/100; // saturate to direction of magnet Bx'=255 if vectorfieldmaxopposite=1 b[1] = (0)*vectorfieldmaxopposite/100; // saturate to direction of magnet By' =0 } else // original code for field { test=false; b[0]+=m*(3*cos*cos1)/r3*vectorfieldmaxopposite/100; ; //x component vectorfieldmaxopposite/100 is a factor i made b[1]+=m*3*sin*cos/r3*vectorfieldmaxopposite/100; ; //y component } it is not working the way that i conceptualize it would work. chance to look at it and make the codes work? i think your teaching method is great, u do it on your applet and i study it. can help? ;D Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: FuKwun Hwang on June 08, 2010, 03:53:31 pm Are you trying to add a visual effect to the applet, or you really need a very accurate calculation for the magnetic field insode the magnet?
The magnetic field of the above applet were calculated with finite number of current loop. The magnetic field strength is inverse proportional to distance squrare. So the error dur to field calculation become too large. May be that is the reason you try to "saturate: it. I would suggest you just calculate the field at one of the end point as the magnetic field inside the magnet. i.e. assume the field is uniform inside the magnet (the same vector as the field at the center of end point). Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: lookang on June 08, 2010, 07:46:38 pm Are you trying to add a visual effect to the applet, or you really need a very accurate calculation for the magnetic field inside the magnet? the visual effect of a uniform B field, not accurate calculation.The magnetic field of the above applet were calculated with finite number of current loop. Yes! i don't believe B field inside the bar magnet can be so big and direction random, it should an uniform B field in my understanding.The magnetic field strength is inverse proportional to distance square. So the error dur to field calculation become too large. May be that is the reason you try to "saturate: it. I would suggest you just calculate the field at one of the end point as the magnetic field inside the magnet. i.e. assume the field is uniform inside the magnet (the same vector as the field at the center of end point). i don't quite get what is mentioned here.but i will try again soon :) Title: Re: Ejs Open Source 2 Bar Magnet & Compass Model java applet Post by: lookang on June 08, 2010, 09:56:18 pm i did it!!! with your guidance for the past 3 years+, i managed to do this just now! LOL ;D ;D
// inside both magnet1&2 if ((xCompass<(xMagnet+Magnetsizex/2) && xCompass>(xMagnet(Magnetsizex/2)) && yCompass<(yMagnet+Magnetsizey/2) && yCompass>(yMagnetMagnetsizey/2))&&(xCompass<(xMagnet2+Magnetsizex2/2) && xCompass>(xMagnet2(Magnetsizex2/2)) && yCompass<(yMagnet2+Magnetsizey2/2) && yCompass>(yMagnet2Magnetsizey2/2))) { //test = true; // create uniform field bxField = (lcst*(225*cs0*sc)+rcst*(225*cs20*sc2))*vectorfieldmaxopposite/100; // saturate to direction of magnet Bx'=0 for both magnets byField = (lcst*(225*sc+0*cs)+rcst*(225*sc2+0*cs2))*vectorfieldmaxopposite/100;//saturate to direction of magnet By' =0 for both magnets } //inside magnet1 else if (xCompass<(xMagnet+Magnetsizex/2) && xCompass>(xMagnet(Magnetsizex/2)) && yCompass<(yMagnet+Magnetsizey/2) && yCompass>(yMagnetMagnetsizey/2)) { //test = false; bxField = (lcst*(225*cs0*sc)+rcst*(bf2[0]*cs2bf2[1]*sc2))*vectorfieldmaxopposite/100;// uniform B1x=225 but B2x still calculate normally byField = (lcst*(225*sc+0*cs)+rcst*(bf2[0]*sc2+bf2[1]*cs2))*vectorfieldmaxopposite/100;//uniform B1y=0 but B2y still calculate normally } // inside magnet2 else if (xCompass<(xMagnet2+Magnetsizex2/2) && xCompass>(xMagnet2(Magnetsizex2/2)) && yCompass<(yMagnet2+Magnetsizey2/2) && yCompass>(yMagnet2Magnetsizey2/2)) { //test = false; bxField = (lcst*(bf1[0]*csbf1[1]*sc)+rcst*(225*cs20*sc2))*vectorfieldmaxopposite/100;// calculate normally B1x but B2x = 225 uniform byField = (lcst*(bf1[0]*sc+bf1[1]*cs)+rcst*(225*sc2+0*cs2))*vectorfieldmaxopposite/100;//calculate normally B1y but B2y = 0 uniform } else { // test=false; bxField = lcst*(bf1[0]*csbf1[1]*sc)+rcst*(bf2[0]*cs2bf2[1]*sc2);//FKH byField = lcst*(bf1[0]*sc+bf1[1]*cs)+rcst*(bf2[0]*sc2+bf2[1]*cs2);//FKH } Thanks again Prof Hwang! your forum rocks! Title: Re: Ejs Open Source 2 Bar Magnets & Compass Model java applet Post by: FuKwun Hwang on June 08, 2010, 11:32:44 pm It is great that you find out the way to solve it. :D
