-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsource.js
More file actions
28 lines (22 loc) · 774 Bytes
/
source.js
File metadata and controls
28 lines (22 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Source {
constructor(amplitude, wavelength, frequency, x, y) {
this.amplitude = amplitude;
this.wavelength = wavelength;
this.frequency = frequency;
this.x = x;
this.y = y;
this.timeElapsed = 0;
}
getDistanceToPoint(pointX, pointY) {
return (
Math.sqrt(Math.pow(pointX - this.x, 2) + Math.pow(pointY - this.y, 2)) * distancePerPixel
);
}
getDisplacement(x, y) {
let distance = this.getDistanceToPoint(x, y);
if (distance > this.timeElapsed * this.wavelength * this.frequency) return 0;
let currentPhase =
(6.28 / this.wavelength) * distance - 6.28 * this.frequency * this.timeElapsed;
return this.amplitude * Math.cos(currentPhase);
}
}