Partícula Flotante

Source Code

En este ejercicio aplicamos las funciones que determinan la fuerza de flotación a una partícula. Estas fuerzas se expresan de la siguiente forma:

$$ F_{flotación} = densidad · gravedad · V_{sumergido}$$

Para calcular el Volumen sumergido de la partícula usamos las siguientes expresiones:

La implementación resultante sería la siguiente:

PVector getForce(){
  PVector sumF = new PVector( 0, 0);
  
  // Gravity
  PVector fg = PVector.mult( Fg, this.mass);
  
  sumF.add( fg);

  // Inmortal Particle has to be the flotant(?) one
  if( this.inmortal){
    // Calculate Flotant(?) Force
    PVector Fb = new PVector();
    float Vs = 0;

    if( this.s.y + radius - waterLevel > this.radius*2){ // Totally sumerged
      Vs = 2 * PI * pow( this.radius, 2) / 2;
    } else if( waterLevel - this.s.y < this.radius){ // Partially sumerged
      float h = abs( waterLevel - (this.s.y + this.radius));
      float a = sqrt( 2 * h * this.radius - pow( h, 2));
      Vs = (( 3 * pow( a, 2) * PI * h) / 6);
      if( hasMadeSplash == false)
        ps.makeSplash( this.v.mag());
      hasMadeSplash = true;
    } else {
      hasMadeSplash = false;
    }

    Fb.set( PVector.mult( Fg.normalize( null).mult( -1), waterDensity).mult( Vs));
    sumF.add( Fb);
  }

  return sumF;
}