Skip to content

Commit

Permalink
tries to avoid microcollisions and vibrations
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagombp committed Apr 12, 2024
1 parent b83fde7 commit 493843d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
33 changes: 27 additions & 6 deletions budget-idea/prototypes/soft-body/mass-spring-pressure/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const params = {
"GRAVITY": 0,
"VECTOR_SIZE": 20,
"PRESSURE_FACTOR": 300,
"RESTITUTION_COEFFICIENT" : 0.8,
"RESTITUTION_COEFFICIENT" : 0.6,
"PARTICLE_RADIUS" : 16,
"DISPLAY_VECTORS": false,
'DISPLAY_SPRING_VECTORS': false,
Expand Down Expand Up @@ -138,6 +138,13 @@ blobs.push(
// populate all particles array
blobs.forEach(blob => all_particles.push(...blob.particles));


// fazer uma classe pra isso;
/*const interaction_particle = new Particle(new Vec(0,0));
interaction_particle.r = 50;
all_particles.push(interaction_particle);
*/

function clearCanvas() {
ctx.clearRect(0, 0, W, H);
}
Expand Down Expand Up @@ -323,10 +330,23 @@ function edges_constraints() {

// vertical borders

if ( (pos.y + r) > H ) {
//const g_ = new Vec(0, -1 * params.GRAVITY);
//p.add_force(Vec.mult( N_TOP, params.MASS ));
p.vel.selfMult(-1 * params.RESTITUTION_COEFFICIENT * params.VEL_DAMPING / 2);
if ( (pos.y + r) >= H ) {
const g_ = new Vec(0, -1 * params.GRAVITY);
p.add_force(Vec.mult( g_, params.MASS));
const v_caused_by_one_step_of_acc = Math.abs(Vec.dot( p.acc, N_BOTTOM) * 1)//20 / params.TIMESTEP);
//console.log(p.vel.mod(), v_caused_by_one_step_of_acc);
if ( p.vel.mod() <= v_caused_by_one_step_of_acc ) {

//console.log(p.vel.mod(), v_caused_by_one_step_of_acc);

p.vel = NULL_VEC;

} else {

p.vel.selfMult(-1 * params.RESTITUTION_COEFFICIENT);

}

p.pos.y = H - r;
}
else if ( (pos.y - r) < 0 ) {
Expand Down Expand Up @@ -396,8 +416,9 @@ function loop(t) {

accumulate_forces();
integrate(dt/params.TIMESTEP);
satisfy_constraints();
collision_system.update_collisions(all_particles);
satisfy_constraints();




Expand Down
2 changes: 2 additions & 0 deletions budget-idea/prototypes/soft-body/notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,6 @@ https://x.com/JuhaniHalkomaki/status/1624761948402319360

Escrevi pro Juhani.

Tentando evitar microvibrações. Aplicando esse conceito de "RESTING CONTACTS", do Millington (7.2.3). Calculando a velocidade da partícula devido à aplicação da aceleração em um frame, se for maior do que a velocidade atual, é por causa desse problema de resting contacts. Mas não está elegante, melhorar.


0 comments on commit 493843d

Please sign in to comment.