This is the web version of EJS interface
EJS version 4.3.7
  1. Title=Multiple Slit Diffraction
  2. Author=Fu-Kwun Hwang,Robert Mohr, Wolfgang Christian, lookang
  3. Keywords=multiple slit difraction, interference
  4. Level=beginner
  5. Language=English
  6. Abstract=Original model by Fu-Kwun Hwang adpted for Ejs 4.1 by Robert Mohr and Wolfgang Christian at Davidson College. remixed by lookang
  7. CaptureTools=true
  8. DataTools=false
  9. LanguageTools=true
  10. AppletColSupport=false
  11. UseMacMenuBar=true
  12. UseInterpreter=true
  13. DetectedFiles=./MultipleSlitDiffraction/MultipleSlitDiffraction.html;
  14. AuxiliaryFiles=./MultipleSlitDiffraction/;

Diffraction

    NameValueTypeDimension
    NameValueTypeDimension
    NameValueTypeDimension

    Init Page

    double dx=(xmax-xmin)/(nx-1); for(int i=0;i<nx;i++){ XP[i]=xmin+i*dx; // XPy[i]=xmin+i*dx; } lightPalette(lambdar); draw_interference ();
    _view.singleSlitTrial.clear(); _view.multipleSlitTrail.clear(); _view.singleSlitTrial2.clear(); // lookang _view.multipleSlitTrail2.clear();// lookang to clear plot lambda=lambdar*um; if(dr<1.2*ar) dr=1.2*ar; a=ar*um; d=dr*um; if(N==1)singleSlit=true; else singleSlit=false; double I,alpha,cst,dy,dyy,sc,beta,cst2,I2; double alphax, betax, scx,Ix,Ixx, I2x, cstx,cst2x;// lookang Imax=a*a*3.e8/N; dy=(spectrumy2-spectrumy1); //dyy=(spectrumy2y-spectrumy1y); // added lookang for(int i=0;i<nx;i++) { x = 0.01+(200-0.01)*i/nx; // lookang sc=XP[i]/Math.sqrt(XP[i]*XP[i]+L*5*L*5)*xscale; scx=x/Math.sqrt(x*x+L*5*L*5)*xscale; alpha=pi*a*sc/lambda; alphax=pi*a*scx/lambda*x ;// lookang beta=pi*d*sc/lambda; betax=pi*d*scx/lambda*x;// lookang if(alpha==0)I2=I=Imax; else { cst2=Math.sin(alpha)/alpha; cst2x=Math.sin(alphax)/alphax;// lookang if(singleSlit) { cst=cst2; cstx=cst2x;// lookang } else { cst=cst2*Math.sin(N*beta)/Math.sin(beta)/N; cstx=cst2x*Math.sin(N*betax)/Math.sin(betax)/N;// lookang } I=cst*cst; Ix=cstx*cstx;// lookang I2=cst2*cst2; I2x=cst2x*cst2x;// lookang } for(int j=0;j<ny;j++) { y = 200*j/ny; // lookang Intensity[i][j]=I*Imax*N/2; // nonlinear scale for screen Intensityy[j][i]=I*Imax*N/2; // flip i for j to get the rigth screen by lookang Intensityyx[j][i]=I*Imax*N/2; // code not working I for Ix, abandoned changes } YP[i]=spectrumy1+dy*I*yscale/50; // added divide 50 by lookang to draw yellow intensity lower YP2[i]=spectrumy1+dy*I2*yscale/50; // YPy[i]=spectrumy1y+dy*I*yscale; // YP2y[i]=spectrumy1y+dy*I2*yscale; }
    Array
    public void lightPalette (double wavelength) { for(int i=0, n=colors.length; i<n; i++){ int r=i; int g=i; int b=i; //colors[i]=new Color(r,g,b); float h=(float)(-2.5*wavelength+1.625); float s=1; if(wavelength>=0.65){ h=0; s=(float)(1-wavelength)/0.35f; } if(wavelength<=0.35){ h=0.75f; s=(float)(wavelength/0.35f); } colors[i]=java.awt.Color.getHSBColor(h,s,(float)(i/255.0)); colorlookang = java.awt.Color.getHSBColor(h,s,(float)(i/255.0)); } }
    // computes intensity in response to mouse action public void computeIntensity () { double x=_view.DrawingPanel.getMouseX(); double sc=x/Math.sqrt(x*x+L*L)*xscale; double alpha=pi*a*sc/lambda; double beta=pi*d*sc/lambda; if(alpha==0) { mouseReading=Imax*yscale; return; } double cst=Math.sin(alpha)/alpha; if(!singleSlit){ cst=cst*Math.sin(N*beta)/Math.sin(beta)/N; } mouseReading=cst*cst*yscale; }
    // computes intensity in response to mouse action // added by lookang to adapt to right panel public void computeIntensityy () { double x=_view.right.getMouseY(); double sc=x/Math.sqrt(x*x+L*L)*xscale; double alpha=pi*a*sc/lambda; double beta=pi*d*sc/lambda; if(alpha==0) { mouseReadingy=Imax*yscale; return; } double cst=Math.sin(alpha)/alpha; if(!singleSlit){ cst=cst*Math.sin(N*beta)/Math.sin(beta)/N; } mouseReadingy=cst*cst*yscale; }
    public void compute_y () { double y=_view.right.getMouseY()/200; yvalue = y; yvalueslider = yvalue*100; ystring = " y = "+ _view.format(y,"0.000")+ " m "; return ; }
    public void draw_interference () { for (i=0; i<nx; i++) { x = 0.01+(200-0.01)*i/nx; c = pi/(lambdar*x)*xscale/2.6; // factor 2.6 determined by trial and error lookang for (j=0; j<ny; j++) { y = 100+(200)*j/ny; if (N==1) { sum2[i][j]= 2.0*Math.abs((Math.sin(c*ar*(y-200.0)))/(c*ar*(y-200.0))); } else { if (N==2) { // sum2[i][j]= 2.0*Math.cos(c*dr*(y-200.0))*Math.cos(c*dr*(y-200.0)); // } // else { sum2[i][j]= 2.0*Math.cos(c*dr*(y-200.0))*Math.cos(c*dr*(y-200.0))*Math.abs((Math.sin(c*ar*(y-200.0)))/(c*ar*(y-200.0))); } } if (y == 200) { // centre line draw max sum2[i][j]= 2.0; } if (x > L) { // outside screen draw zero sum2[i][j]= 0.0; } } } }
    EJSVIEW: Click link to view it's content
    Control variables:(testing)
    double,int,double,double,double,double,double,double
    title="Multiple Slit Diffraction"
    layout=border
    visible=true
    location="496,85"
    size="640,447"
    position=center
    autoscaleX=false
    autoscaleY=false
    minimumX=xmin/2
    maximumX=xmax
    minimumY=ymin
    maximumY=ymax
    square=false
    x=-55.0
    y=-56.61971830985917
    showCoordinates=true
    BLmessage="top view"
    z=Intensity
    autoscaleZ=false
    minimumZ=0
    maximumZ=0.05/yscale/N
    expandedZ=2
    minimumX=xmin
    maximumX=xmax
    minimumY=spectrumy1
    maximumY=spectrumy2
    plotType=INTERPOLATED
    visible=false
    levels=100
    colormode=colors
    floorcolor=BLACK
    ceilingcolor=colors[255]
    showgrid=false
    inputX=XP
    inputY=YP2
    visible=false
    measured=false
    norepeat=true
    connected=true
    lineColor=MAGENTA
    inputX=XP
    inputY=YP
    visible=false
    measured=false
    norepeat=true
    connected=true
    lineColor=RED
    x=0
    y=0
    sizeX=2*200
    sizeY=2*200
    style=RECTANGLE
    lineColor=BLACK
    fillColor=BLACK
    z=sum2
    minimumZ=0.0
    maximumZ=2.0
    minimumX=0.0
    maximumX=200
    minimumY=-100
    maximumY=100
    plotType=INTERPOLATED
    colormode=colors
    showgrid=false
    z=Intensityyx
    minimumZ=0.0
    maximumZ=2.0
    minimumX=0.0
    maximumX=200
    minimumY=-100
    maximumY=100
    plotType=INTERPOLATED
    visible=false
    colormode=colors
    showgrid=false
    x=0
    y=0
    sizeX=0.45*200
    sizeY=0.07*200
    style=RECTANGLE
    elementposition=EAST
    lineColor=colorlookang
    fillColor=colorlookang
    x=0
    y=0
    sizeX=4
    sizeY=40
    enabledPosition=false
    movesGroup=false
    style=RECTANGLE
    elementposition=CENTERED
    lineColor=CYAN
    fillColor=CYAN
    visible=N==1
    x=0
    y=0
    sizeX=5
    sizeY=ar/1
    releaseAction=_initialize()
    style=RECTANGLE
    elementposition=CENTERED
    lineColor=BLACK
    fillColor=BLACK
    lineWidth=1
    x=0.0
    y=0
    visible=N>=2
    x=0
    y=dr/2/1
    sizeX=5
    sizeY=ar/1
    releaseAction=_initialize()
    style=RECTANGLE
    elementposition=CENTERED
    lineColor=BLACK
    fillColor=BLACK
    lineWidth=1
    x=0
    y=-dr/2/1
    sizeX=5
    sizeY=ar/1
    releaseAction=_initialize()
    style=RECTANGLE
    elementposition=CENTERED
    lineColor=BLACK
    fillColor=BLACK
    lineWidth=1
    x=-0.45*200
    y=0
    sizeX=-0.05*200
    sizeY=0
    scalex=4
    scaley=4
    style=TRIANGLE
    lineColor=WHITE
    fillColor=200,220,208
    x=L
    y=0
    sizeX=0
    sizeY=ymax-ymin
    visible=screenshow
    enabledPosition=ENABLED_X
    enabledSize=ENABLED_NONE
    movesGroup=true
    dragAction=_initialize()
    style=SEGMENT
    elementposition=CENTERED
    lineColor=WHITE
    fillColor=WHITE
    lineWidth=6
    visible=ypshow
    x=L
    y=yvalue*100
    sizeX=20
    sizeY=20
    pixelSize=true
    enabledPosition=ENABLED_Y
    style=WHEEL
    lineColor=MAGENTA
    fillColor=255,0,255,50
    lineWidth=1
    x=L
    y=0
    sizeX=0
    sizeY=yvalue*100
    style=ARROW
    lineColor=MAGENTA
    fillColor=MAGENTA
    lineWidth=3
    x=L-size/2
    y=y+ypspace
    sizeX=size*5
    sizeY=size*5
    pixelSize=true
    transformation=90
    text=%ystring%
    font=Arial,BOLD,20
    elementposition=EAST
    lineColor=MAGENTA
    fillColor=MAGENTA
    position=east
    autoscaleX=true
    autoscaleY=true
    minimumY=xmin
    maximumY=xmax
    pressaction=computeIntensityy (); compute_y ();
    dragaction=computeIntensityy (); compute_y ();
    showCoordinates=true
    xFormat=null
    yFormat=null
    xyExpression="mouseReadingy"
    xyFormat="I = 0.00"
    TLmessage="screen view"
    BRmessage=%ystring%
    visible=screenshow
    z=Intensityy
    autoscaleZ=false
    minimumZ=0
    maximumZ=0.05/yscale/N
    expandedZ=2
    minimumX=spectrumy1
    maximumX=spectrumy2
    minimumY=xmin
    maximumY=xmax
    plotType=INTERPOLATED
    levels=100
    colormode=colors
    floorcolor=BLACK
    ceilingcolor=colors[255]
    showgrid=false
    inputX=YP2
    inputY=XP
    visible=showXY
    measured=false
    norepeat=true
    connected=true
    lineColor=MAGENTA
    inputX=YP
    inputY=XP
    visible=showintensity
    measured=false
    norepeat=true
    connected=true
    lineColor=YELLOW
    lineWidth=2
    position=south
    layout=VBOX
    position=north
    layout=HBOX
    borderType=LOWERED_ETCHED
    layout=VBOX
    position=center
    layout=HBOX
    position=center
    text=" $\lambda$ = "
    background=colorlookang
    tooltip="Wavelength = 0.00 $\mu$m"
    position=north
    variable=lambdar
    format="0.00"
    action=lightPalette(lambdar); _initialize();
    tooltip="Wavelength = 0.00 $\mu$m"
    position=south
    text=" $\mu$m "
    background=colorlookang
    tooltip="$\mu$m"
    variable=lambdar
    minimum=0.1
    maximum=1.0
    dragaction=lightPalette(lambdar); _initialize();
    background=colorlookang
    tooltip="Wavelength = 0.00 $\mu$m"
    layout=VBOX
    position=center
    layout=HBOX
    position=center
    text=" N = "
    background=CYAN
    tooltip="number of slits"
    position=north
    variable=N
    format="00"
    action=_initialize()
    tooltip="number of slits"
    position=south
    background=CYAN
    variable=N
    value=2
    minimum=1
    maximum=2
    pressaction=_initialize()
    dragaction=_initialize()
    background=CYAN
    tooltip="number of slits"
    layout=VBOX
    position=center
    layout=HBOX
    position=center
    text=" a = "
    background=BLACK
    foreground=WHITE
    tooltip="Slit Width"
    position=north
    variable=ar
    format="0.00"
    action=_initialize()
    tooltip="Slit Width"
    position=south
    text=" $\mu$m "
    background=BLACK
    foreground=WHITE
    tooltip="$\mu$m"
    variable=ar
    value=1.5
    minimum=1
    maximum=2
    pressaction=_initialize()
    dragaction=_initialize()
    background=BLACK
    foreground=WHITE
    tooltip="Slit Width = 0 $\mu$m"
    layout=VBOX
    visible=!singleSlit
    position=center
    layout=HBOX
    position=center
    text=" d = "
    background=CYAN
    tooltip="Slit Separation = 0 $\mu$m"
    position=north
    variable=dr
    format="0.00"
    action=_initialize()
    tooltip="Slit Separation = 0 $\mu$m"
    position=south
    text=" $\mu$m "
    background=CYAN
    tooltip="$\mu$m"
    variable=dr
    minimum=3
    maximum=6
    enabled=!singleSlit
    pressaction=_initialize()
    dragaction=_initialize()
    background=CYAN
    tooltip="Slit Separation = 0 $\mu$m"
    layout=VBOX
    position=center
    layout=HBOX
    variable=screenshow
    background=WHITE
    tooltip="show screen "
    position=center
    text=" L = "
    background=WHITE
    tooltip="distance from slit to screen"
    position=north
    variable=Ladjusted
    format="0.00"
    action=L = Ladjusted*200; _initialize();
    tooltip="distance in x direction"
    position=south
    text=" m "
    background=WHITE
    tooltip="m"
    variable=showXY
    enabled=screenshow
    background=MAGENTA
    tooltip="Envelope"
    variable=showintensity
    enabled=screenshow
    background=YELLOW
    tooltip="show intensity"
    variable=Ladjusted
    minimum=0.1
    maximum=1.0
    dragaction=L = Ladjusted*200; lightPalette(lambdar); _initialize();
    background=WHITE
    tooltip="distance from slit to screen in m"
    layout=VBOX
    borderType=RAISED_BEVEL
    position=center
    layout=HBOX
    variable=ypshow
    background=MAGENTA
    tooltip="show ruler measurement "
    text=" y = "
    background=MAGENTA
    foreground=WHITE
    tooltip="y direction measurement from central line"
    variable=yvalue
    format="0.000"
    action=y = yvalue*100;
    tooltip="measurement in y direction"
    text=" m "
    background=MAGENTA
    foreground=WHITE
    tooltip="metre"
    variable=yvalueslider
    minimum=-100
    maximum=100
    ticks=6
    pressaction=yvalue = yvalueslider/100; _initialize();
    dragaction=yvalue = yvalueslider/100; _initialize();
    background=MAGENTA
    tooltip="measurement in y direction"
    position=south
    layout=HBOX
    borderType=LOWERED_ETCHED
    variable=xscale
    minimum=0.1
    maximum=10
    format="0.00"
    visible=false
    tooltip="Distance along screen."
    variable=yscale
    value=25
    minimum=1/N
    maximum=400/N
    format="0.00"
    orientation=HORIZONTAL
    enabled=true
    tooltip="Intensity Scale"
    position=west
    image="/org/opensourcephysics/resources/controls/images/reset.gif"
    action=_reset()
    tooltip="reset simulation"