static Vector3f getCenter(final Vector<Vector3f> theVertices, final Triangle theTriangle) {
    final Vector3f myCenter = new Vector3f();
    final Vector3f v0 = theVertices.get(theTriangle.p[0]);
    final Vector3f v1 = theVertices.get(theTriangle.p[1]);
    final Vector3f v2 = theVertices.get(theTriangle.p[2]);
    final Vector3f myNormal = new Vector3f(0, 0, 1);

    final Vector3f pA = mathematik.Util.sub(v2, v0);
    pA.scale(0.5f);
    Vector3f pAc = new Vector3f();
    pAc.cross(pA, myNormal);
    pAc.add(v0);
    pAc.add(pA);
    pA.add(v0);

    final Vector3f pB = mathematik.Util.sub(v2, v1);
    pB.scale(0.5f);
    Vector3f pBc = new Vector3f(pB);
    pBc.cross(pB, myNormal);
    pBc.add(v1);
    pBc.add(pB);
    pB.add(v1);

    mathematik.Intersection.lineLineIntersect(pA, pAc, pB, pBc, myCenter, new Vector3f(), null);
    return myCenter;
  }
示例#2
0
  public void pre_step() {
    Vector3f ab = mathematik.Util.sub(mParticleA.position(), mParticleB.position());
    Vector3f cb = mathematik.Util.sub(mParticleC.position(), mParticleB.position());
    final float mCurrentAngle = ab.angle(cb);

    if (mCurrentAngle < mMinAngle) {
      final int TINY_FACTOR_MODELL = 0;
      final int TRIG_MODELL = 1;
      final int MAX_DISTANCE_MODELL = 2;

      final int mModell = TRIG_MODELL;

      switch (mModell) {
        case TINY_FACTOR_MODELL:
          {
            final float TINY_FACTOR = 1.1f;
            final float mDistance =
                mParticleA.position().distance(mParticleC.position()) * TINY_FACTOR;
            restlength(mDistance);
          }
          break;
        case TRIG_MODELL:
          {
            // a = sqrt ( b*b + c*c - 2bc*cosA )
            final float b = ab.length();
            final float c = cb.length();
            final float mDistance =
                (float) Math.sqrt(b * b + c * c - 2 * b * c * (float) Math.cos(mMinAngle));
            restlength(mDistance);
          }
          break;
        case MAX_DISTANCE_MODELL:
          {
            final float mDistance =
                mParticleA.position().distance(mParticleB.position())
                    + mParticleC.position().distance(mParticleB.position());
            restlength(mDistance);
          }
          break;
      }
      active(true);
    }
  }