#-------------------------------------------
#  Diffrazione da due fenditure
#  
#  GdA, giugno 2024
#------------------------------------------

d =  1.67   # micron (dstanza fenditure) 
lg = 0.55   # micron (lambda -> verde)
lr = 0.7    #                -> rosso
lb = 0.4    #                -> blue/viola

th.max = pi/3
th <- seq(-th.max, th.max, len=10001)
Img <- cos(d/lg*pi*sin(th))^2 
Imr <- cos(d/lr*pi*sin(th))^2
Imb <- cos(d/lb*pi*sin(th))^2 

old.mar = par("mar")
par(mar=c(4.5,4.2,1.0,0.3))   # margini ottimizzati
par(mfrow= c(2,1) )
plot(sin(th), Img, ylab='I', ty='l', lwd=2, col='green')
abline(v=lg/d*(-4:4), lty=2, col='green')
Sys.sleep(1)
points(sin(th), Imr, ty='l', lwd=2, col='red')
abline(v=lr/d*(-4:4), lty=2, col='red')
Sys.sleep(1)
points(sin(th), Imb, ty='l', lwd=2, col='blue')
abline(v=lb/d*(-4:4), lty=2, col='blue')


Sys.sleep(1)
rg <- 180/pi
plot(th*rg, Img, ty='l', xlab='theta (gradi)', ylab='I', lwd=2, col='green')
Sys.sleep(1)
points(th*rg, Imr, ty='l', lwd=2, col='red')
Sys.sleep(1)
points(th*rg, Imb, ty='l', lwd=2, col='blue')
par(mfrow= c(1,1) )
par(mar=old.mar)
