Revert "remove negligible vector projection"
This reverts commit 6123c02581
.
This commit is contained in:
parent
6123c02581
commit
f70370d05e
1 changed files with 18 additions and 2 deletions
20
sketch.js
20
sketch.js
|
@ -38,18 +38,34 @@ function move_charges() {
|
|||
const acceleration_mag = 1 / displacement.mag() * 0.005;
|
||||
let ai = displacement.copy().normalize().mult(acceleration_mag);
|
||||
let aj = p5.Vector.mult(ai, -1);
|
||||
charges[i].acceleration.add(ai);
|
||||
charges[j].acceleration.add(aj);
|
||||
let ai_norm = project_onto_plane(ai, charges[i].position);
|
||||
|
||||
let aj_norm = project_onto_plane(aj, charges[j].position);
|
||||
|
||||
charges[i].acceleration.add(ai_norm);
|
||||
charges[j].acceleration.add(aj_norm);
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < charges.length; i += 1) {
|
||||
let charge = charges[i];
|
||||
charge.velocity = charge.velocity.add(charge.acceleration);
|
||||
//charge.velocity = project_onto_plane(charge.velocity, charge.position);
|
||||
charge.position = charge.position.add(charge.velocity);
|
||||
charge.position.normalize();
|
||||
}
|
||||
}
|
||||
|
||||
function project_onto_unit_vector(v, unit_vector) {
|
||||
let size = p5.Vector.dot(v, unit_vector);
|
||||
return p5.Vector.mult(unit_vector, size);
|
||||
}
|
||||
|
||||
/// Project `v` onto the plane normal to `unit_vector`
|
||||
function project_onto_plane(v, unit_vector) {
|
||||
let v_proj = project_onto_unit_vector(v, unit_vector);
|
||||
return v.sub(v_proj)
|
||||
}
|
||||
|
||||
function make_charges(n) {
|
||||
charges = [];
|
||||
for (let i = 0; i < n; i += 1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue