Package org.apache.commons.math.geometry

Examples of org.apache.commons.math.geometry.Vector3D


    checkVector(v.scalarMultiply(0.5), 1.5, 3, 4.5);

  }

  public void testVectorialProducts() {
    Vector3D v1 = new Vector3D(2, 1, -4);
    Vector3D v2 = new Vector3D(3, 1, -1);

    assertTrue(Math.abs(Vector3D.dotProduct(v1, v2) - 11) < 1.0e-12);

    Vector3D v3 = Vector3D.crossProduct(v1, v2);
    checkVector(v3, 3, -10, -1);

    assertTrue(Math.abs(Vector3D.dotProduct(v1, v3)) < 1.0e-12);
    assertTrue(Math.abs(Vector3D.dotProduct(v2, v3)) < 1.0e-12);
View Full Code Here


    assertEquals(Math.PI / 2, Vector3D.PLUS_J.getAlpha(), 1.0e-10);
    assertEquals(0,           Vector3D.PLUS_J.getDelta(), 1.0e-10);
    assertEquals(0,           Vector3D.PLUS_K.getAlpha(), 1.0e-10);
    assertEquals(Math.PI / 2, Vector3D.PLUS_K.getDelta(), 1.0e-10);

    Vector3D u = new Vector3D(-1, 1, -1);
    assertEquals(3 * Math.PI /4, u.getAlpha(), 1.0e-10);
    assertEquals(-1.0 / Math.sqrt(3), Math.sin(u.getDelta()), 1.0e-10);

  }
View Full Code Here

    assertEquals(-1.0 / Math.sqrt(3), Math.sin(u.getDelta()), 1.0e-10);

  }

  public void testAngularSeparation() {
    Vector3D v1 = new Vector3D(2, -1, 4);

    Vector3D  k = v1.normalize();
    Vector3D  i = k.orthogonal();
    Vector3D v2 = k.scalarMultiply(Math.cos(1.2)).add(i.scalarMultiply(Math.sin(1.2)));

    assertTrue(Math.abs(Vector3D.angle(v1, v2) - 1.2) < 1.0e-12);

  }
View Full Code Here

    assertTrue(Math.abs(Vector3D.angle(v1, v2) - 1.2) < 1.0e-12);

  }

  public void testNormalize() {
    assertEquals(1.0, new Vector3D(5, -4, 2).normalize().getNorm(), 1.0e-12);
    try {
        Vector3D.ZERO.normalize();
        fail("an exception should have been thrown");
    } catch (ArithmeticException ae) {
        // expected behavior
View Full Code Here

        fail("wrong exception caught: " + e.getMessage());
    }
  }

  public void testOrthogonal() {
      Vector3D v1 = new Vector3D(0.1, 2.5, 1.3);
      assertEquals(0.0, Vector3D.dotProduct(v1, v1.orthogonal()), 1.0e-12);
      Vector3D v2 = new Vector3D(2.3, -0.003, 7.6);
      assertEquals(0.0, Vector3D.dotProduct(v2, v2.orthogonal()), 1.0e-12);
      Vector3D v3 = new Vector3D(-1.7, 1.4, 0.2);
      assertEquals(0.0, Vector3D.dotProduct(v3, v3.orthogonal()), 1.0e-12);
      try {
          new Vector3D(0, 0, 0).orthogonal();
          fail("an exception should have been thrown");
      } catch (ArithmeticException ae) {
          // expected behavior
      } catch (Exception e) {
          fail("wrong exception caught: " + e.getMessage());
View Full Code Here

      }
  }

  public void testAngle() {
     assertEquals(0.22572612855273393616,
                  Vector3D.angle(new Vector3D(1, 2, 3), new Vector3D(4, 5, 6)),
                  1.0e-12);
     assertEquals(7.98595620686106654517199e-8,
                  Vector3D.angle(new Vector3D(1, 2, 3), new Vector3D(2, 4, 6.000001)),
                  1.0e-12);
     assertEquals(3.14159257373023116985197793156,
                  Vector3D.angle(new Vector3D(1, 2, 3), new Vector3D(-2, -4, -6.000001)),
                  1.0e-12);
     try {
         Vector3D.angle(Vector3D.ZERO, Vector3D.PLUS_I);
         fail("an exception should have been thrown");
     } catch (ArithmeticException ae) {
View Full Code Here

  }

  public void testAxisAngle() {

    Rotation r = new Rotation(new Vector3D(10, 10, 10), 2 * Math.PI / 3);
    checkVector(r.applyTo(Vector3D.PLUS_I), Vector3D.PLUS_J);
    checkVector(r.applyTo(Vector3D.PLUS_J), Vector3D.PLUS_K);
    checkVector(r.applyTo(Vector3D.PLUS_K), Vector3D.PLUS_I);
    double s = 1 / Math.sqrt(3);
    checkVector(r.getAxis(), new Vector3D(s, s, s));
    checkAngle(r.getAngle(), 2 * Math.PI / 3);

    try {
      new Rotation(new Vector3D(0, 0, 0), 2 * Math.PI / 3);
      fail("an exception should have been thrown");
    } catch (ArithmeticException e) {
    } catch (Exception e) {
      fail("unexpected exception");
    }

    r = new Rotation(Vector3D.PLUS_K, 1.5 * Math.PI);
    checkVector(r.getAxis(), new Vector3D(0, 0, -1));
    checkAngle(r.getAngle(), 0.5 * Math.PI);

    r = new Rotation(Vector3D.PLUS_J, Math.PI);
    checkVector(r.getAxis(), Vector3D.PLUS_J);
    checkAngle(r.getAngle(), Math.PI);
View Full Code Here

    assertEquals(-1, Vector3D.dotProduct(r.getAxis(), reverted.getAxis()), 1.0e-12);
  }

  public void testVectorOnePair() {

    Vector3D u = new Vector3D(3, 2, 1);
    Vector3D v = new Vector3D(-4, 2, 2);
    Rotation r = new Rotation(u, v);
    checkVector(r.applyTo(u.scalarMultiply(v.getNorm())), v.scalarMultiply(u.getNorm()));

    checkAngle(new Rotation(u, u.negate()).getAngle(), Math.PI);

    try {
        new Rotation(u, Vector3D.ZERO);
View Full Code Here

  }

  public void testVectorTwoPairs() {

    Vector3D u1 = new Vector3D(3, 0, 0);
    Vector3D u2 = new Vector3D(0, 5, 0);
    Vector3D v1 = new Vector3D(0, 0, 2);
    Vector3D v2 = new Vector3D(-2, 0, 2);
    Rotation r = new Rotation(u1, u2, v1, v2);
    checkVector(r.applyTo(Vector3D.PLUS_I), Vector3D.PLUS_K);
    checkVector(r.applyTo(Vector3D.PLUS_J), Vector3D.MINUS_I);

    r = new Rotation(u1, u2, u1.negate(), u2.negate());
    Vector3D axis = r.getAxis();
    if (Vector3D.dotProduct(axis, Vector3D.PLUS_K) > 0) {
      checkVector(axis, Vector3D.PLUS_K);
    } else {
      checkVector(axis, Vector3D.MINUS_K);
    }
    checkAngle(r.getAngle(), Math.PI);

    double sqrt = Math.sqrt(2) / 2;
    r = new Rotation(Vector3D.PLUS_I,  Vector3D.PLUS_J,
                     new Vector3D(0.5, 0.5,  sqrt),
                     new Vector3D(0.5, 0.5, -sqrt));
    checkRotation(r, sqrt, 0.5, 0.5, 0);

    r = new Rotation(u1, u2, u1, Vector3D.crossProduct(u1, u2));
    checkRotation(r, sqrt, -sqrt, 0, 0);
View Full Code Here

        }
      }
    }

    checkVector(r.applyTo(Vector3D.PLUS_I),
                new Vector3D(m3[0][0], m3[1][0], m3[2][0]));
    checkVector(r.applyTo(Vector3D.PLUS_J),
                new Vector3D(m3[0][1], m3[1][1], m3[2][1]));
    checkVector(r.applyTo(Vector3D.PLUS_K),
                new Vector3D(m3[0][2], m3[1][2], m3[2][2]));

    double[][] m4 = { { 1.00.00.0 },
                      { 0.0, -1.00.0 },
                      { 0.00.0, -1.0 } };
    r = new Rotation(m4, 1.0e-7);
View Full Code Here

TOP

Related Classes of org.apache.commons.math.geometry.Vector3D

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.