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

## Easy Java Simulations (2001- ) => Collaborative Community of EJS => Topic started by: lookang on August 05, 2011, 09:21:32 pm

 Title: Ejs Open Source 2 Mass Model with Gravity Field Vector, Field Lines, Potential Post by: lookang on August 05, 2011, 09:21:32 pm Ejs Open Source 2 Mass Model with Gravity Field Vector, Field Lines, Potential Visualization.author: Fu-Kwun Hwang and slightly edited by lookangreference:http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=539.0http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1968.0re-purposed from charge to mass by m1 = -q1;m2 = -q2; Title: Re: Ejs Open Source 2 Mass Model with Gravity Field Vector, Field Lines, Potential Post by: lookang on September 06, 2011, 06:40:27 pm additional changes, added on 06 September 2011added value of potential to be shown adapted codes from http://www.compadre.org/OSP/items/detail.cfm?ID=11443 Point Charge Electric Potential Model written by Wolfgang Christian // adapted from http://www.compadre.org/OSP/items/detail.cfm?ID=11443public void potentialMessage () {  double xm=_view.DrawingPanel.getMouseX();   // mouse x-location  double ym=_view.DrawingPanel.getMouseY();   // mouse y-location  double v=0;//  for(int p=0; p    double dx=xm-x1; // for first charge                        // x-separation from grid point    double dy=ym-y1;                         // y-separation from grid point    double r2=dx*dx+dy*dy;             // charge to grid point distance squared    double dx2=xm-x2; // for second charge                        // x-separation from grid point    double dy2=ym-y2;                         // y-separation from grid point    double r22=dx2*dx2+dy2*dy2;             // charge to grid point distance squared        if(r2==0||r22==0){                                 // check for singularity      v=Double.NaN;                            // field is not defined at singularity//      break;                                   // break from loop      }else{                                      v = G*q1/Math.sqrt(r2)+G*q2/Math.sqrt(r22);      // add scalar potential//      Evalue = G*q1/r2+G*q2/r2;    } // end of if statement//  } // end of charge loop  dragMsg="$\\phi$ = "+_view.format(v,"0.0E0")+ " J/kg";//  dragMsgE="g = "+_view.format(Evalue,"0.0E0")+ " N/kg";  }added value of field strength to be shown redesigned by myself with reference and using http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=539.0http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1968.0 by Fu-Kwun Hwang.// adapted from http://www.compadre.org/OSP/items/detail.cfm?ID=11443public void fieldMessage () {  double xm=_view.DrawingPanel.getMouseX();   // mouse x-location  double ym=_view.DrawingPanel.getMouseY();   // mouse y-location  double Evalue=0;//  for(int p=0; p    double dx1=xm-x1;   //first charge                      // x-separation from grid point    double dy1=ym-y1;                         // y-separation from grid point    double r12=dx1*dx1+dy1*dy1;                     // charge to grid point distance squared     double dx2=xm-x2;    //second charge                     // x-separation from grid point    double dy2=ym-y2;                         // y-separation from grid point    double r22=dx2*dx2+dy2*dy2;             // charge to grid point distance squareddouble dx=q1*dx1/(r12*Math.sqrt(r12))+q2*dx2/(r22*Math.sqrt(r22));double  dy=q1*dy1/(r12*Math.sqrt(r12))+q2*dy2/(r22*Math.sqrt(r22));   double d=Math.sqrt(dx*dx+dy*dy);double   Evaluex=dx;double   Evaluey=dy; //double Evalue = Math.sqrt(Evaluex*Evaluex+Evaluex*Evaluex); if(r12==0||r22==0){                                 // check for singularity      Evaluex=Double.NaN;                            // field is not defined at singularity     Evaluey=Double.NaN; //      break;                                   // break from loop    }else{                                   Evaluex=G*dx;   Evaluey=G*dy; Eangle = Math.atan2(Evaluey,Evaluex)*180/pi;   //      v = G*q1/Math.sqrt(r2)+G*q2/Math.sqrt(r2);      // add scalar potential    Evalue = Math.sqrt(Evaluex*Evaluex+Evaluey*Evaluey);    } // end of if statement // } // end of charge loop//  dragMsg="V = "+_view.format(v,"0.0E0")+ " V";  dragMsgEx="gx = "+_view.format(Evaluex,"0.0E0")+ " N/kg";    dragMsgEy="gy = "+_view.format(Evaluey,"0.0E0")+ " N/kg";    dragMsgE="|g| = "+_view.format(Evalue,"0.0E0")+ " N/kg at angle =" +_view.format(Eangle,"000") +"to +x-axis counterclockwise";    }