Package jinngine.math

Examples of jinngine.math.Matrix3


    }

    @Test(expected = NullPointerException.class)
    public void testAssignMultiplyVector02() {
        new Matrix3().multiply((Vector3) null);
    }
View Full Code Here


      ListIterator<NCPConstraint> outConstraints
  ) {

    //Use a gram-schmidt process to create a orthonormal basis for the contact point ( normal and tangential directions)
    final Vector3 t1 = new Vector3(), t2 = new Vector3(), t3 = new Vector3();
    final Matrix3 B  = GramSchmidt.run(n);
    B.getColumnVectors(t1, t2, t3);

    // interaction points and jacobian for normal constraint
    final Vector3 r1 = p.sub(b1.state.position);
    final Vector3 r2 = p.sub(b2.state.position);

    // jacobians for normal direction
    final Vector3 nJ1 = n;
    final Vector3 nJ2 = r1.cross(n);
    final Vector3 nJ3 = n.negate();
    final Vector3 nJ4 = r2.cross(n).negate();

    //First off, create the constraint in the normal direction
    final double e = cp.restitution; //coeficient of restitution
    final double uni = nJ1.dot(b1.state.velocity) + nJ2.dot(b1.state.omega) + nJ3.dot(b2.state.velocity) + nJ4.dot(b2.state.omega);
    final double unf = uni<0 ? -e*uni: 0;   
   
    //compute B vector
    final Matrix3 I1 = b1.state.inverseinertia;
    final Matrix3 M1 = b1.state.inverseanisotropicmass;
    final Matrix3 I2 = b2.state.inverseinertia;
    final Matrix3 M2 = b2.state.inverseanisotropicmass;
    final Vector3 nB1 = M1.multiply(nJ1);
    final Vector3 nB2 = I1.multiply(nJ2);
    final Vector3 nB3 = M2.multiply(nJ3);
    final Vector3 nB4 = I2.multiply(nJ4);

    // clear out B's if mass is "infinity"
    if (b1.isFixed()) { nB1.assignZero(); nB2.assignZero(); }
    if (b2.isFixed()) { nB3.assignZero(); nB4.assignZero(); }

    //external forces acing at contact (obsolete, external forces are modelled using the delta velocities)
    //double Fext = B1.dot(b1.state.force) + B2.dot(b1.state.torque) + B3.dot(b2.state.force) + B4.dot(b2.state.torque);
    double correction = depth*(1/dt); //the true correction velocity. This velocity corrects the contact in the next timestep.
    final double escape = (cp.envelope-cp.distance)*(1/dt);
    final double lowerNormalLimit = 0;
    final double limit = 2;
   
   
    // if the unf velocity will make the contact leave the envelope in the next timestep,
    // we ignore corrections
    if (unf > escape) {
      //System.out.println("escape");
      correction = 0;
    } else {
      //even with unf, we stay inside the envelope
      //truncate correction velocity if already covered by repulsive velocity
      if (correction > 0) {
        if (unf > correction ) {
          correction = 0;
        } else {
          correction = correction - unf; // not sure this is smart TODO
        }
      }
    }
 
    // limit the correction velocity
    correction = correction< -limit? -limit:correction; 
    correction = correction>  limit?  limit:correction;
   
    // take a factor of real correction velocity
    correction = correction * 0.9;
   
    //correction=correction>0?0:correction;

    // the normal constraint
    final NCPConstraint c = new NCPConstraint();
    c.assign(b1,b2,
        nB1, nB2, nB3, nB4,
        nJ1, nJ2, nJ3, nJ4,
        lowerNormalLimit, Double.POSITIVE_INFINITY,
        null,
           -(unf-uni)-correction, -correction) ;
   
    // set distance (unused in simulator)
    c.distance = cp.distance;
   
    //normal-friction coupling
    final NCPConstraint coupling = enableCoupling?c:null;
   
    //set the correct friction setting for this contact
    c.mu = cp.friction;
           
    //first tangent
    final Vector3 t2J1 = t2;
    final Vector3 t2J2 = r1.cross(t2);
    final Vector3 t2J3 = t2.negate();
    final Vector3 t2J4 = r2.cross(t2).negate();
    final Vector3 t2B1 = b1.isFixed()? new Vector3(): M1.multiply(t2J1);
    final Vector3 t2B2 = b1.isFixed()new Vector3(): I1.multiply(t2J2);
    final Vector3 t2B3 = b2.isFixed()? new Vector3(): M2.multiply(t2J3);
    final Vector3 t2B4 = b2.isFixed()? new Vector3(): I2.multiply(t2J4);

    //then the tangential friction constraints
    double ut1i = t2J1.dot(b1.state.velocity) + t2J2.dot(b1.state.omega) + t2J3.dot(b2.state.velocity) + t2J4.dot(b2.state.omega); //relativeVelocity(b1,b2,p,t2);
    double ut1f = 0;
   
    //double t2Fext = t2B1.dot(b1.state.FCm) + t2B2.dot(b1.state.tauCm) + t2B3.dot(b2.state.FCm) + t2B4.dot(b2.state.tauCm);
    final NCPConstraint c2 = new NCPConstraint();
    c2.assign(b1,b2,
        t2B1, t2B2,  t2B3, t2B4,       
        t2J1, t2J2, t2J3, t2J4,
        -frictionBoundMagnitude, frictionBoundMagnitude,
        coupling,
        -(ut1f-ut1i),
        0
    );
   
    //second tangent
    final Vector3 t3J1 = t3;
    final Vector3 t3J2 = r1.cross(t3);
    final Vector3 t3J3 = t3.negate();
    final Vector3 t3J4 = r2.cross(t3).negate();
    final Vector3 t3B1 = b1.isFixed()? new Vector3(): M1.multiply(t3J1);
    final Vector3 t3B2 = b1.isFixed()? new Vector3(): I1.multiply(t3J2);
    final Vector3 t3B3 = b2.isFixed()? new Vector3(): M2.multiply(t3J3);
    final Vector3 t3B4 = b2.isFixed()? new Vector3(): I2.multiply(t3J4);

    double ut2i = t3J1.dot(b1.state.velocity) + t3J2.dot(b1.state.omega) + t3J3.dot(b2.state.velocity) + t3J4.dot(b2.state.omega); //relativeVelocity(b1,b2,p,t2);
    double ut2f = 0;
   
View Full Code Here

    Vector3 tt3i = Matrix3.multiply(b1.state.rotation, t3i, new Vector3());
    Vector3 tn1 = Matrix3.multiply(b1.state.rotation, ni, new Vector3());
    Vector3 tn2 = Matrix3.multiply(b2.state.rotation, nj, new Vector3());
   
    //jacobians on matrix form
    final Matrix3 Ji = Matrix3.identity().multiply(1);
    final Matrix3 Jangi = Matrix3.crossProductMatrix(ri).multiply(-1);
    final Matrix3 Jj = Matrix3.identity().multiply(-1);
    final Matrix3 Jangj = Matrix3.crossProductMatrix(rj);

//    Matrix3 MiInv = Matrix3.identity().multiply(1/b1.state.mass);
//    Matrix3 MjInv = Matrix3.identity().multiply(1/b2.state.mass);
    final Matrix3 MiInv = b1.state.inverseanisotropicmass;
    final Matrix3 MjInv = b2.state.inverseanisotropicmass;
   

    final Matrix3 Bi = b1.isFixed()? new Matrix3() : MiInv.multiply(Ji.transpose());
    final Matrix3 Bangi = b1.isFixed()? new Matrix3() : b1.state.inverseinertia.multiply(Jangi.transpose());
    final Matrix3 Bj = b2.isFixed()? new Matrix3() : MjInv.multiply(Jj.transpose());
    final Matrix3 Bangj = b2.isFixed()? new Matrix3() : b2.state.inverseinertia.multiply(Jangj.transpose());

    double Kcor = 0.9;
   
//    Vector3 u = b1.state.velocity.minus( ri.cross(b1.state.omega)).minus(b2.state.velocity).add(rj.cross(b2.state.omega));
    Vector3 u = b1.state.velocity.add( b1.state.omega.cross(ri)).sub(b2.state.velocity.add(b2.state.omega.cross(rj)));

    Vector3 posError = b1.state.position.add(ri).sub(b2.state.position).sub(rj).multiply(1/dt);
    //error in transformed normal
    Vector3 nerror = tn1.cross(tn2);
    u.assign( u.add(posError.multiply(Kcor)));
   
    linear1.assign(
        b1,  b2,
        Bi.column(0), Bangi.column(0), Bj.column(0), Bangj.column(0),
        Ji.row(0), Jangi.row(0), Jj.row(0), Jangj.row(0),
        Double.NEGATIVE_INFINITY,
        Double.POSITIVE_INFINITY,
        null,
        u.x, 0 );

    linear2.assign(
        b1,  b2,
        Bi.column(1), Bangi.column(1), Bj.column(1), Bangj.column(1),
        Ji.row(1), Jangi.row(1), Jj.row(1), Jangj.row(1),
        Double.NEGATIVE_INFINITY,
        Double.POSITIVE_INFINITY,
        null,
        u.y, 0 );

    linear3.assign(
        b1,  b2,
        Bi.column(2), Bangi.column(2), Bj.column(2), Bangj.column(2),
        Ji.row(2), Jangi.row(2), Jj.row(2), Jangj.row(2),
        Double.NEGATIVE_INFINITY,
        Double.POSITIVE_INFINITY,
        null,
        u.z, 0 )
View Full Code Here

    // it has 3 DOFs, thus removing 3, inducing 3 new constraints
    Vector3 ri = Matrix3.multiply(b1.state.rotation, p1, new Vector3());
    Vector3 rj = Matrix3.multiply(b2.state.rotation, p2, new Vector3());
   
    //jacobians on matrix form
    final Matrix3 Ji = Matrix3.identity().multiply(1);
    final Matrix3 Jangi =Matrix3.crossProductMatrix(ri).multiply(-1);
    final Matrix3 Jj = Matrix3.identity().multiply(-1);
    final Matrix3 Jangj = Matrix3.crossProductMatrix(rj);

   
//    final Matrix3 MiInv = Matrix3.identity().multiply(1/b1.state.mass);
    final Matrix3 MiInv = b1.state.inverseanisotropicmass;
    final Matrix3 Bi = MiInv.multiply(Ji.transpose());
    final Matrix3 Bangi = b1.state.inverseinertia.multiply(Jangi.transpose());

    if (b1.isFixed()) {
      Bi.assign(new Matrix3());
      Bangi.assign(new Matrix3());
    }
   
//    final Matrix3 MjInv = Matrix3.identity().multiply(1/b2.state.mass);
    final Matrix3 MjInv = b2.state.inverseanisotropicmass;
    final Matrix3 Bj = MjInv.multiply(Jj.transpose());
    final Matrix3 Bangj = b2.state.inverseinertia.multiply(Jangj.transpose());

    if (b2.isFixed()) {
      Bj.assign(new Matrix3());
      Bangj.assign(new Matrix3());
    }   

//    Vector3 u = b1.state.velocity.add( b1.state.omega.cross(ri)).minus(b2.state.velocity).add(b2.state.omega.cross(rj));
    Vector3 u = b1.state.velocity.add( b1.state.omega.cross(ri)).sub(b2.state.velocity.add(b2.state.omega.cross(rj)));

//    Vector3 posError = b1.state.rCm.add(b1.state.q.rotate(p1)).minus(b2.state.rCm).minus(b2.state.q.rotate(p2)).multiply(Kcor);
    Vector3 posError = b1.state.position.add(ri).sub(b2.state.position).sub(rj).multiply(1.0/dt);
   
    // correction velocity limit
    if ( posError.norm() > velocitylimit) {
      posError.assign( posError.normalize().multiply(velocitylimit));
    }
   
    u.assign( u.add(posError));
   
   
    //go through matrices and create rows in the final A matrix to be solved
    c1.assign(
        b1, b2,
        Bi.column(0), Bangi.column(0), Bj.column(0), Bangj.column(0),
        Ji.row(0), Jangi.row(0), Jj.row(0), Jangj.row(0),
        -forcelimit,
        forcelimit,
        null,
        u.x, 0);
    c2.assign(
        b1, b2,
        Bi.column(1), Bangi.column(1), Bj.column(1), Bangj.column(1),
        Ji.row(1), Jangi.row(1), Jj.row(1), Jangj.row(1),
        -forcelimit,
        forcelimit,
        null,
        u.y, 0);
    c3.assign(
        b1, b2,
        Bi.column(2), Bangi.column(2), Bj.column(2), Bangj.column(2),
        Ji.row(2), Jangi.row(2), Jj.row(2), Jangj.row(2),
        -forcelimit,
        forcelimit,
        null,
        u.z, 0);
View Full Code Here

   
   
    // at all times, n1iw and n2jw are orthogonal
   
    //jacobians on matrix form
    Matrix3 Ji = Matrix3.identity().multiply(1);
    Matrix3 Jangi = Matrix3.crossProductMatrix(riw).multiply(-1);
    Matrix3 Jj = Matrix3.identity().multiply(-1);
    Matrix3 Jangj = Matrix3.crossProductMatrix(rjw);

//    Matrix3 MiInv = Matrix3.identity().multiply(1/bi.state.mass);
//    Matrix3 MjInv = Matrix3.identity().multiply(1/bj.state.mass);
    final Matrix3 MiInv = bi.state.inverseanisotropicmass;
    final Matrix3 MjInv = bj.state.inverseanisotropicmass;


    Matrix3 Bi = bi.isFixed()? new Matrix3() : MiInv.multiply(Ji.transpose());
    Matrix3 Bangi = bi.isFixed()? new Matrix3() : bi.state.inverseinertia.multiply(Jangi.transpose());
    Matrix3 Bj = bj.isFixed()? new Matrix3() : MjInv.multiply(Jj.transpose());
    Matrix3 Bangj = bj.isFixed()? new Matrix3() : bj.state.inverseinertia.multiply(Jangj.transpose());

    double Kcor = 0.8;
   
//    Vector3 u = b1.state.velocity.minus( ri.cross(b1.state.omega)).minus(b2.state.velocity).add(rj.cross(b2.state.omega));
    Vector3 u = bi.state.velocity.add( bi.state.omega.cross(riw)).sub(bj.state.velocity.add(bj.state.omega.cross(rjw)));

    Vector3 posError = bi.state.position.add(riw).sub(bj.state.position).sub(rjw).multiply(1/dt);
    //error in transformed normal
    Vector3 nerror = n1iw.cross(n2jw);
    u.assign( u.add(posError.multiply(Kcor)));
   
    linear1.assign(
        bi,  bj,
        Bi.column(0), Bangi.column(0), Bj.column(0), Bangj.column(0),
        Ji.row(0), Jangi.row(0), Jj.row(0), Jangj.row(0),
        Double.NEGATIVE_INFINITY,
        Double.POSITIVE_INFINITY,
        null,
        u.x, 0 );

    linear2.assign(
        bi,  bj,
        Bi.column(1), Bangi.column(1), Bj.column(1), Bangj.column(1),
        Ji.row(1), Jangi.row(1), Jj.row(1), Jangj.row(1),
        Double.NEGATIVE_INFINITY,
        Double.POSITIVE_INFINITY,
        null,
        u.y, 0 );

    linear3.assign(
        bi,  bj,
        Bi.column(2), Bangi.column(2), Bj.column(2), Bangj.column(2),
        Ji.row(2), Jangi.row(2), Jj.row(2), Jangj.row(2),
        Double.NEGATIVE_INFINITY,
        Double.POSITIVE_INFINITY,
        null,
        u.z, 0 )
View Full Code Here

TOP

Related Classes of jinngine.math.Matrix3

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.