Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions clustering/simulation.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ <h3>Algorithm</h3>
<li>
The metric used here is Euclidean distance
</li>
<li>
There is a bug that occurs with 6 clusters. Two of the centroids are of same color.
</li>
<li>
Related: <a href="../gradient_descent/simulation.html">Gradient Descent</a>,
<a href="../natural_selection/simulation.html">Genetic Algorithm</a>,
Expand All @@ -135,4 +132,4 @@ <h3>Algorithm</h3>
<p class="center-align">Developed by ChanRT | Fork me at <a href="https://www.github.com/chanrt">GitHub</a></p>
</div>

</html>
</html>
4 changes: 2 additions & 2 deletions clustering/simulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function getColor(group) {
case 4:
return "#aaaaaa";
case 5:
return "#ffcocb"
return "#ff00ff";
}
}

Expand Down Expand Up @@ -248,4 +248,4 @@ function distanceBetweenPoints(point1, point2) {

function distanceBetweenCoordAndPoint(x, y, point) {
return Math.sqrt(Math.pow(point.x - x, 2) + Math.pow(point.y - y, 2));
}
}
15 changes: 9 additions & 6 deletions nuclear_fusion/Nucleus.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class Nucleus {

this.undefined_safeguard = true;
}
update() {
this.vx += this.ax * dt;
this.vy += this.ay * dt;
update_init() {
this.vx += 0.5*this.ax * dt;
this.vy += 0.5*this.ay * dt;

this.agitate();

Expand All @@ -40,10 +40,13 @@ class Nucleus {
this.vy = -Math.abs(this.vy);
this.y = canvas_height - this.radius;
}

this.ax = 0;
this.ay = 0;
}
update_finish() {
this.vx += 0.5*this.ax * dt;
this.vy += 0.5*this.ay * dt;
}
applyForce(force_x, force_y) {
if(this.undefined_safeguard) {
if(force_x !== undefined) {
Expand Down Expand Up @@ -85,10 +88,10 @@ class Nucleus {
this.color = "#0000ff";
}
else if(this.mass == 2) {
this.color = "#00ff00";
this.color = "#ffff00";
}
else {
this.color = "#aaaaaa";
}
}
}
}
9 changes: 7 additions & 2 deletions nuclear_fusion/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let dt = 0.001;

function update() {
for (let nucleus of nuclei) {
nucleus.update();
nucleus.update_init();
}

for(let fusion_event of fusion_events) {
Expand All @@ -54,6 +54,10 @@ function update() {
heatUp();
}

for (let nucleus of nuclei) {
nucleus.update_finish();
}

frame++;
frame = frame % fps
if(frame == 0) {
Expand Down Expand Up @@ -224,6 +228,7 @@ function makeScene() {
}
nuclei.push(new Nucleus(x, y, 1, 1, 100));
}
internuclearInteractions();
}

function makeGrid() {
Expand All @@ -249,4 +254,4 @@ function distanceBetweenCoordAndNucleus(x, y, nucleus) {

function distanceBetween(nucleus1, nucleus2) {
return distance_scaling * Math.sqrt(Math.pow(nucleus2.x - nucleus1.x, 2) + Math.pow(nucleus2.y - nucleus1.y, 2));
}
}
11 changes: 6 additions & 5 deletions nuclear_fusion/simulation.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ <h3>Components</h3>
<li>
<b>Dynamics</b> <br>
<p>
The motion of nuclei obtained using the following equations:
\[ a = F / m \]
\[ v(t + \Delta t) = v(t) + a \Delta t \]
\[ x(t + \Delta t) = x(t) + v(t + \Delta t) \Delta t \]
The motion of nuclei obtained using the following Verlet method updates:
\[ v(t + 0.5\Delta t) = v(t) + 0.5 a(t) \Delta t \]
\[ x(t + \Delta t) = x(t) + v(t + 0.5\Delta t) \Delta t \]
\[ a(t + \Delta t) = F(x(t + \Delta t)) / m \]
\[ v(t + \Delta t) = v(t+0.5\Delta t) + 0.5 a(t + \Delta t) \Delta t \]
Where \( \Delta t = 10^{-3} \ units \). Further, when a nucleus moves through a heated cell, it gets agitated,
resulting in an increase in it's velocity. Lighter nuclei are more influenced by heat than heavier nuclei.
</p>
Expand Down Expand Up @@ -234,4 +235,4 @@ <h2>Analysis</h2>
<p class="center-align">Developed by ChanRT | Fork me at <a href="https://www.github.com/chanrt">GitHub</a></p>
</div>

</html>
</html>