Ejemplo n.º 1
0
 private final void computeArea() {
   // The area of a quadrilateral is 0.5*p*q*sin(theta)
   // Where p and q are the length of the 2 diagonals and theta is the angle between them
   // If we rotate P in the right direction, then area = 0.5*p*q*cos(theta) where theta is
   // the angle between Q and the rotated P, but this is simply 0.5 * dot product of P' and Q
   // Note, it is possible because of the cos to get a negative area, when this happens, it means
   // that the quadrilateral has flipped and that the normally inward pointing normals are
   // now pointing outward, so if we get a negative area, we should flip the force vectors...
   Vector2D P = tv.getPosition().subtract(d.getPosition());
   Vector2D Q = dt.getPosition().subtract(v.getPosition());
   area = 0.5 * P.rotate90().dot(Q);
   if (Math.signum(area) != Math.signum(desiredArea) && desiredArea != 0) {
     System.err.println(
         "Compartment:" + this.toString() + " has flipped inside out. Area:" + area);
   }
 }