Package jinngine.math

Examples of jinngine.math.Matrix3


        new Matrix3().assignSubtract(null);
    }

    @Test
    public void testIsNan() {
        final Matrix3 m = new Matrix3(
                -1., -2., -3.,
                -4., -5., -6.,
                -7., -8., -9.);
        assertFalse(m.isNaN());
        assertMatrixEquals(new double[]{
                    -1., -2., -3.,
                    -4., -5., -6.,
                    -7., -8., -9.}, m);

        assertTrue(new Matrix3(
                Double.NaN, -2., -3.,
                -4., -5., -6.,
                -7., -8., -9.).isNaN());
        assertTrue(new Matrix3(
                -1., Double.NaN, -3.,
                -4., -5., -6.,
                -7., -8., -9.).isNaN());
        assertTrue(new Matrix3(
                -1., -2., Double.NaN,
                -4., -5., -6.,
                -7., -8., -9.).isNaN());
        assertTrue(new Matrix3(
                -1., -2., -3.,
                Double.NaN, -5., -6.,
                -7., -8., -9.).isNaN());
        assertTrue(new Matrix3(
                -1., -2., -3.,
                -4., Double.NaN, -6.,
                -7., -8., -9.).isNaN());
        assertTrue(new Matrix3(
                -1., -2., -3.,
                -4., -5., Double.NaN,
                -7., -8., -9.).isNaN());
        assertTrue(new Matrix3(
                -1., -2., -3.,
                -4., -5., -6.,
                Double.NaN, -8., -9.).isNaN());
        assertTrue(new Matrix3(
                -1., -2., -3.,
                -4., -5., -6.,
                -8., Double.NaN, -9.).isNaN());
        assertTrue(new Matrix3(
                -1., -2., -3.,
                -4., -5., -6.,
                -8., -9., Double.NaN).isNaN());
    }
View Full Code Here


                -8., -9., Double.NaN).isNaN());
    }

    @Test
    public void testDeterminan() {
        Matrix3 m = new Matrix3(
                1., 4., -7.,
                2., -5., 8.,
                3., 6., 9.);
        assertEquals(-258., m.determinant());
        assertMatrixEquals(new double[]{
                    1., 4., -7.,
                    2., -5., 8.,
                    3., 6., 9.}, m);
        assertEquals(1., Matrix3.identity().determinant());
        assertEquals(8., Matrix3.scaleMatrix(2.).determinant());
        assertEquals(0., new Matrix3().determinant());
    }
View Full Code Here

        assertEquals(0., new Matrix3().determinant());
    }

    @Test
    public void testFNorm() {
        Matrix3 m = new Matrix3(
                1., 4., -7.,
                2., -5., 8.,
                3., 6., 9.);
        assertEquals(16.881943016134134, m.fnorm());
        assertMatrixEquals(new double[]{
                    1., 4., -7.,
                    2., -5., 8.,
                    3., 6., 9.}, m);
        assertEquals(1.7320508075688772, Matrix3.identity().fnorm());
        assertEquals(3.4641016151377544, Matrix3.scaleMatrix(2.).fnorm());
        assertEquals(0., new Matrix3().fnorm());
    }
View Full Code Here

        assertEquals(0., new Matrix3().fnorm());
    }

    @Test
    public void testInverse01() {
        Matrix3 m = new Matrix3(
                1., 4., -7.,
                2., -5., 8.,
                3., 6., 9.);
        Matrix3 r = m.inverse();
        assertNotSame(r, m);
        assertMatrixEquals(new double[]{
                    1., 4., -7.,
                    2., -5., 8.,
                    3., 6., 9.}, m);
        Matrix3 i = r.assignMultiply(m);
        assertMatrixEquals(new double[]{
                    1., 0., 0.,
                    0., 1., 0.,
                    0., 0., 1.}, i, 1E-15);
    }
View Full Code Here

                    0., 0., 1.}, i, 1E-15);
    }

    @Test
    public void testInverse02() {
        Matrix3 m = new Matrix3(
                1., 0., 0.,
                0., 1., 0.,
                0., 0., 1.);
        Matrix3 r = m.inverse();
        assertMatrixEquals(new double[]{
                    1., 0., 0.,
                    0., 1., 0.,
                    0., 0., 1.}, r, 1E-15);
    }
View Full Code Here

                    0., 0., 1.}, r, 1E-15);
    }

    @Test
    public void testAssignInverse02() {
        Matrix3 m = new Matrix3(
                1., 4., -7.,
                2., -5., 8.,
                3., 6., 9.);
        Matrix3 r = m.assignInverse();
        assertSame(r, m);
        Matrix3 i = r.assignMultiply(new Matrix3(
                1., 4., -7.,
                2., -5., 8.,
                3., 6., 9.));
        assertMatrixEquals(new double[]{
                    1., 0., 0.,
View Full Code Here

    }

    @Test
    public void testToArray() {

        final Matrix3 m = new Matrix3(
                1., 2., 3.,
                4., 5., 6.,
                7., 8., 9.);
        final double[] d = m.toArray();
        final double[] d2 = m.toArray();
        assertNotSame(d, d2);
        assertMatrixEquals(new double[]{
                    1., 2., 3.,
                    4., 5., 6.,
                    7., 8., 9.}, m);
View Full Code Here

    @Test
    public void testToString() {
        assertEquals("[1.0, 2.0, 3.0]\n"
                + "[5.0, 6.0, 7.0]\n"
                + "[9.0, 10.0, 11.0]", new Matrix3(
                1., 2., 3.,
                5., 6., 7.,
                9., 10, 11).toString());
    }
View Full Code Here

    final Vector3 direction = v.normalize();
//    final Vector3 midpoint = a.add(b).multiply(0.5);
    final Vector3 midpoint = a.add(b).add(v.multiply(spb-spa)).multiply(0.5); // account for sphere sweeping
   
    // contact space basis
    final Matrix3 M = GramSchmidt.run(direction);

    // make sure the normal direction is in the z-component
    final Matrix3 B = new Matrix3(M.column(1),M.column(2),M.column(0));

    // since B is orthogonal its inverse equals its transpose
    final Matrix3 Binv = B.transpose();
   
    // create a result handler for the intersection algorithm
    final ORourke.ResultHandler handler = new ORourke.ResultHandler() {
      public final void intersection(final Vector3 p, final Vector3 q) {       
        final ContactPoint cp = new ContactPoint();

        cp.b1 = ga.getBody();
        cp.b2 = gb.getBody();
       
        cp.normal.assign(direction);
        cp.point.assign( B.multiply(new Vector3(p.x,p.y,0)).add(midpoint) );
       
        // distance along the z axis in contact space
        cp.distance = (p.z-q.z)-spb-spa;  // take into account sphere sweeping

        // if contact is within the envelope size
        if (cp.distance < envelope ) {
          cp.depth = shell-cp.distance;
          cp.envelope = envelope;
          cp.restitution = restitution;
          cp.friction = friction;
          contacts.add(cp);
        }
      }
    };
   
   
    // apply transform to all points
    for (Vector3 p: faceA) {
      p.assign( Binv.multiply(p.sub(midpoint)));
    }
    for (Vector3 p: faceB) {
      p.assign( Binv.multiply(p.sub(midpoint)));
    }
   
    // run 2d intersection
    ORourke.run(faceA, faceB, handler);
   
View Full Code Here

      ConvexHull hull = (ConvexHull)g;
      int n = hull.getNumberOfVertices();
      double points[] = new double[n*3];
      int i = 0; Iterator<Vector3> iter = hull.getVertices();

      Matrix3 T = new Matrix3();
      Vector3 t = new Vector3();
      g.getLocalTransform(T, t);
 
      while(iter.hasNext()){
        Vector3 v = new Vector3(iter.next());
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.