示例#1
0
 /** @return */
 public double getFaceArea() {
   if (_halfedge == null) {
     return 0;
   }
   final WB_Coord n = getFaceNormal();
   if (WB_Vector.getLength3D(n) < 0.5) {
     return 0;
   }
   final double x = WB_Math.fastAbs(n.xd());
   final double y = WB_Math.fastAbs(n.yd());
   final double z = WB_Math.fastAbs(n.zd());
   double area = 0;
   int coord = 3;
   if ((x >= y) && (x >= z)) {
     coord = 1;
   } else if ((y >= x) && (y >= z)) {
     coord = 2;
   }
   HE_Halfedge he = _halfedge;
   do {
     switch (coord) {
       case 1:
         area +=
             (he.getVertex().yd()
                 * (he.getNextInFace().getVertex().zd() - he.getPrevInFace().getVertex().zd()));
         break;
       case 2:
         area +=
             (he.getVertex().xd()
                 * (he.getNextInFace().getVertex().zd() - he.getPrevInFace().getVertex().zd()));
         break;
       case 3:
         area +=
             (he.getVertex().xd()
                 * (he.getNextInFace().getVertex().yd() - he.getPrevInFace().getVertex().yd()));
         break;
     }
     he = he.getNextInFace();
   } while (he != _halfedge);
   switch (coord) {
     case 1:
       area *= (0.5 / x);
       break;
     case 2:
       area *= (0.5 / y);
       break;
     case 3:
       area *= (0.5 / z);
   }
   return WB_Math.fastAbs(area);
 }
示例#2
0
  public double findSmallestSpanAroundStrut(final int i) {
    final int n = struts.size();
    if ((i < 0) || (i >= n)) {
      throw new IllegalArgumentException("Index beyond strut range.");
    }
    final ArrayList<WB_FrameNode> nnodes = getNeighbors();
    if (n == 1) {
      return 2 * Math.PI;

    } else if (n == 2) {
      final WB_Vector u = nnodes.get(0).subToVector(this);
      final WB_Vector w = nnodes.get(1).subToVector(this);
      u._normalizeSelf();
      w._normalizeSelf();

      final double udw = WB_Math.clamp(u.dot(w), -1, 1);
      if (udw < WB_Epsilon.EPSILON - 1) {
        return Math.PI;
      } else {
        return Math.acos(udw);
      }
    } else {
      double minAngle = Double.MAX_VALUE;

      final WB_Vector u = nnodes.get(i).subToVector(this);
      u._normalizeSelf();
      for (int j = 0; j < n; j++) {
        if (i != j) {
          final WB_Vector w = nnodes.get(j).subToVector(this);
          w._normalizeSelf();
          final double a = Math.acos(u.dot(w));

          minAngle = WB_Math.min(minAngle, a);
        }
      }

      return minAngle;
    }
  }