diff --git a/sim6.html b/sim6.html
index 3364666..40b7a3a 100644
--- a/sim6.html
+++ b/sim6.html
@@ -13,11 +13,11 @@
-
+
Slits: 3
-
+
Slit Width: 500 μm
diff --git a/static/js/shared/screen.js b/static/js/shared/screen.js
index 469a9cd..36ff30f 100644
--- a/static/js/shared/screen.js
+++ b/static/js/shared/screen.js
@@ -23,4 +23,27 @@ class Screen {
}
}
-export { Screen };
\ No newline at end of file
+class HorizontalScreen {
+ constructor(cvs, c, x, y, w) {
+ this.cvs = cvs;
+ this.c = c;
+ this.x = x;
+ this.y = y;
+ this.w = w;
+
+ this.minY = 0.25 * cvs.height;
+ this.maxY = 0.85 * cvs.height;
+ }
+
+ draw = () => {
+ this.c.beginPath();
+ this.c.strokeStyle = SCREENS.COLOR;
+ this.c.lineWidth = SCREENS.WIDTH;
+ this.c.moveTo(this.x - this.w / 2, this.y);
+ this.c.lineTo(this.x + this.w / 2, this.y);
+ this.c.closePath();
+ this.c.stroke();
+ }
+}
+
+export { Screen, HorizontalScreen };
\ No newline at end of file
diff --git a/static/js/shared/slit.js b/static/js/shared/slit.js
index 58118aa..3b21839 100644
--- a/static/js/shared/slit.js
+++ b/static/js/shared/slit.js
@@ -50,12 +50,12 @@ class DoubleSlit {
}
class NSlit {
- constructor(cvs, c, x, y, h, width, separation, slits) {
+ constructor(cvs, c, x, y, w, width, separation, slits) {
this.cvs = cvs;
this.c = c;
this.x = x;
this.y = y;
- this.h = h;
+ this.w = w;
this.width = width;
this.separation = separation;
this.slits = slits;
@@ -65,18 +65,18 @@ class NSlit {
this.c.beginPath();
this.c.strokeStyle = SLITS.COLOR;
this.c.lineWidth = SLITS.WIDTH;
- this.c.moveTo(this.x, this.y - this.h / 2);
- let dist = this.y - (this.slits * this.width) / 2 - ((this.slits - 1) * this.separation) / 2;
- this.c.lineTo(this.x, dist);
+ this.c.moveTo(this.x - this.w / 2, this.y);
+ let dist = this.x - (this.slits * this.width) / 2 - ((this.slits - 1) * this.separation) / 2;
+ this.c.lineTo(dist, this.y);
for (let i = 1; i <= this.slits; i++) {
dist += this.width;
- this.c.moveTo(this.x, dist);
+ this.c.moveTo(dist, this.y);
if (i < this.slits) {
dist += this.separation;
- this.c.lineTo(this.x, dist);
+ this.c.lineTo(dist, this.y);
}
}
- this.c.lineTo(this.x, this.y + this.h / 2);
+ this.c.lineTo(this.x + this.w / 2, this.y);
this.c.closePath();
this.c.stroke();
}
diff --git a/static/js/simulations/nSlit.js b/static/js/simulations/nSlit.js
index 3827da6..59256b4 100644
--- a/static/js/simulations/nSlit.js
+++ b/static/js/simulations/nSlit.js
@@ -1,5 +1,5 @@
import {Simulation} from "./index.js";
-import {Screen} from "../shared/screen.js";
+import {Screen, HorizontalScreen} from "../shared/screen.js";
import {interpolate, w2h} from "../utils/color.js";
import {distance} from "../utils/math.js";
import {DoubleSlit, NSlit, Slit} from "../shared/slit.js";
@@ -8,8 +8,8 @@ class NSlitSimulation extends Simulation {
constructor(cvs, c, wavelength = 500 / 1_000_000_000 , slitWidth = 500 / 1_000_000, slitSeparation = 50 / 1_000_000, slits = 3) {
super(cvs, c);
this.wavelength = wavelength;
- this.screen = new Screen(cvs, c, 0.85 * cvs.width, cvs.height / 2, cvs.height - 50);
- this.slit = new NSlit(cvs, c, 0.15 * cvs.width, cvs.height / 2, cvs.height - 50, slitWidth / this.ypx2m, slitSeparation / this.ypx2m, slits);
+ this.screen = new HorizontalScreen(cvs, c, cvs.width / 2, 0.25 * cvs.height, cvs.width - 50);
+ this.slit = new NSlit(cvs, c, cvs.width / 2, 0.9 * cvs.height, cvs.width - 50, slitWidth / this.xpx2m, slitSeparation / this.xpx2m, slits);
this.t = 0;
this.dt = 1 / 60;
@@ -21,8 +21,8 @@ class NSlitSimulation extends Simulation {
theta = Math.round(theta * 1_000_000) / 1_000_000;
if (theta in this.cache) return this.cache[theta];
let sine = Math.sin(theta);
- let beta = Math.PI * this.slit.width * this.ypx2m * sine / this.wavelength;
- let alpha = Math.PI * (this.slit.width + this.slit.separation) * this.ypx2m * sine / this.wavelength;
+ let beta = Math.PI * this.slit.width * this.xpx2m * sine / this.wavelength;
+ let alpha = Math.PI * (this.slit.width + this.slit.separation) * this.xpx2m * sine / this.wavelength;
let tmp = Math.sin(beta) / beta * Math.sin(this.slit.slits * alpha) / Math.sin(alpha);
this.cache[theta] = tmp * tmp / this.slit.slits / this.slit.slits;
return this.cache[theta];
@@ -37,13 +37,13 @@ class NSlitSimulation extends Simulation {
this.slit.draw();
this.plotIntensity();
this.redraw = false;
- } else this.c.clearRect(this.slit.x + 2.5, 0, this.screen.x - this.slit.x - 5, this.cvs.height);
+ } else this.c.clearRect(0, this.screen.y + 2.5, this.cvs.width, this.slit.y - this.screen.y - 5);
this.c.save();
this.displayMeasurements();
- for (let x = 0; x < this.screen.x - 3; x += 5) {
- for (let y = 0; y <= this.cvs.height; y += 5) {
+ for (let x = 0; x <= this.cvs.width; x += 5) {
+ for (let y = this.screen.y + 5; y <= this.cvs.height - 5; y += 5) {
this.c.globalAlpha = this.intensityAt(x, y);
this.c.fillStyle = this.colorAt(x, y);
this.c.fillRect(x, y, 3, 3);
@@ -56,11 +56,11 @@ class NSlitSimulation extends Simulation {
this.c.beginPath();
this.c.lineWidth = 3;
this.c.strokeStyle = this.color;
- for (let y = 0; y <= this.cvs.height; y++) {
- const theta = Math.atan2((y - this.slit.y) * this.ypx2m, (this.screen.x - this.slit.x) * this.xpx2m);
+ for (let x = 0; x <= this.cvs.width; x++) {
+ const theta = Math.atan2((x - this.slit.x) * this.xpx2m, (this.slit.y - this.screen.y) * this.ypx2m);
const intensity = this.evaluate(theta) * 100;
- if (y === 0) this.c.moveTo(this.screen.x + 5 + intensity, y);
- else this.c.lineTo(this.screen.x + 5 + intensity, y);
+ if (x === 0) this.c.moveTo(x, this.screen.y - 5 - intensity);
+ else this.c.lineTo(x, this.screen.y - 5 - intensity);
}
this.c.stroke();
}
@@ -68,15 +68,15 @@ class NSlitSimulation extends Simulation {
displayMeasurements = () => {
this.c.save();
this.c.beginPath();
- this.c.moveTo(this.slit.x, this.cvs.height * 0.9);
- this.c.lineTo(this.screen.x, this.cvs.height * 0.9);
+ this.c.moveTo(this.cvs.width * 0.9, this.slit.y);
+ this.c.lineTo(this.cvs.width * 0.9, this.screen.y);
this.c.strokeStyle = "#179e7e";
this.c.stroke();
- this.c.translate((this.slit.x + this.screen.x) / 2, this.cvs.height * 0.9 - 18);
+ this.c.translate(this.cvs.width * 0.9 + 40, (this.slit.y + this.screen.y) / 2);
this.c.font = "20px arial";
this.c.textAlign = "center";
this.c.fillStyle = "#179e7e";
- const dist = Math.round((this.screen.x - this.slit.x) * this.xpx2m * 1000) / 10;
+ const dist = Math.round((this.slit.y - this.screen.y) * this.ypx2m * 1000) / 10;
this.c.fillText(`${dist} cm`, 0, 10);
this.c.restore();
}
@@ -88,13 +88,13 @@ class NSlitSimulation extends Simulation {
}
setSlitWidth = (slitWidth) => {
- this.slit.width = slitWidth / this.ypx2m;
+ this.slit.width = slitWidth / this.xpx2m;
this.redraw = true;
this.cache = {};
}
setSlitSeparation = (slitSeparation) => {
- this.slit.separation = slitSeparation / this.ypx2m;
+ this.slit.separation = slitSeparation / this.xpx2m;
this.redraw = true;
this.cache = {};
}
@@ -106,13 +106,13 @@ class NSlitSimulation extends Simulation {
}
intensityAt = (x, y) => {
- if (x < this.slit.x) return 1;
- const theta = Math.atan2((y - this.slit.y) * this.ypx2m, (x - this.slit.x) * this.xpx2m);
+ if (y > this.slit.y) return 1;
+ const theta = Math.atan2((x - this.slit.x) * this.xpx2m, (y - this.slit.y) * this.ypx2m);
return this.evaluate(theta);
}
colorAt = (x, y) => {
- const dist = (x < this.slit.x ? x : distance(this.slit.x, this.slit.y, x , y));
+ const dist = (y > this.slit.y ? this.cvs.height - y : distance(this.slit.x, this.slit.y, x, y));
const v = 2 * dist / (this.wavelength * 50000000) - 10 * this.t;
const factor = (1 + Math.cos(v)) / 2;
return interpolate("#000000", this.color, factor);
@@ -123,16 +123,16 @@ class NSlitSimulation extends Simulation {
mouseUp = (event) => {};
mouseMove = (event, x, y) => {
- this.screen.x = Math.max(Math.min(x, this.screen.maxX), this.screen.minX);
+ this.screen.y = Math.max(Math.min(y, this.screen.maxY), this.screen.minY);
this.redraw = true;
}
get xpx2m() {
- return 2 / (this.screen.maxX - this.slit.x);
+ return 2 / 1_000_00;
}
get ypx2m() {
- return 1 / 1_000_00;
+ return 2 / (this.slit.y - this.screen.minY);
}
get color() {