Package org.apache.commons.math.geometry

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


  }

  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.plusI), Vector3D.plusK);
    checkVector(r.applyTo(Vector3D.plusJ), Vector3D.minusI);

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

    double sqrt = Math.sqrt(2) / 2;
    r = new Rotation(Vector3D.plusI,  Vector3D.plusJ,
                     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);

    checkRotation(new Rotation(u1, u2, u1, u2), 1, 0, 0, 0);

    try {
        new Rotation(u1, u2, new Vector3D(), v2);
        fail("an exception should have been thrown");
    } catch (IllegalArgumentException e) {
      // expected behavior
    } catch (Exception e) {
        fail("unexpected exception");
View Full Code Here


        }
      }
    }

    checkVector(r.applyTo(Vector3D.plusI),
                new Vector3D(m3[0][0], m3[1][0], m3[2][0]));
    checkVector(r.applyTo(Vector3D.plusJ),
                new Vector3D(m3[0][1], m3[1][1], m3[2][1]));
    checkVector(r.applyTo(Vector3D.plusK),
                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

  }

  public void testQuaternion() {

    Rotation r1 = new Rotation(new Vector3D(2, -3, 5), 1.7);
    double n = 23.5;
    Rotation r2 = new Rotation(n * r1.getQ0(), n * r1.getQ1(),
                               n * r1.getQ2(), n * r1.getQ3(),
                               true);
    for (double x = -0.9; x < 0.9; x += 0.2) {
      for (double y = -0.9; y < 0.9; y += 0.2) {
        for (double z = -0.9; z < 0.9; z += 0.2) {
          Vector3D u = new Vector3D(x, y, z);
          checkVector(r2.applyTo(u), r1.applyTo(u));
        }
      }
    }

View Full Code Here

  }

  public void testCompose() {

    Rotation r1 = new Rotation(new Vector3D(2, -3, 5), 1.7);
    Rotation r2 = new Rotation(new Vector3D(-1, 3, 2), 0.3);
    Rotation r3 = r2.applyTo(r1);

    for (double x = -0.9; x < 0.9; x += 0.2) {
      for (double y = -0.9; y < 0.9; y += 0.2) {
        for (double z = -0.9; z < 0.9; z += 0.2) {
          Vector3D u = new Vector3D(x, y, z);
          checkVector(r2.applyTo(r1.applyTo(u)), r3.applyTo(u));
        }
      }
    }
View Full Code Here

  }

  public void testComposeInverse() {

    Rotation r1 = new Rotation(new Vector3D(2, -3, 5), 1.7);
    Rotation r2 = new Rotation(new Vector3D(-1, 3, 2), 0.3);
    Rotation r3 = r2.applyInverseTo(r1);

    for (double x = -0.9; x < 0.9; x += 0.2) {
      for (double y = -0.9; y < 0.9; y += 0.2) {
        for (double z = -0.9; z < 0.9; z += 0.2) {
          Vector3D u = new Vector3D(x, y, z);
          checkVector(r2.applyInverseTo(r1.applyTo(u)), r3.applyTo(u));
        }
      }
    }
View Full Code Here

  }

  public void testApplyInverseTo() {

    Rotation r = new Rotation(new Vector3D(2, -3, 5), 1.7);
    for (double lambda = 0; lambda < 6.2; lambda += 0.2) {
      for (double phi = -1.55; phi < 1.55; phi += 0.2) {
          Vector3D u = new Vector3D(Math.cos(lambda) * Math.cos(phi),
                                    Math.sin(lambda) * Math.cos(phi),
                                    Math.sin(phi));
          r.applyInverseTo(r.applyTo(u));
          checkVector(u, r.applyInverseTo(r.applyTo(u)));
          checkVector(u, r.applyTo(r.applyInverseTo(u)));
      }
    }

    r = new Rotation();
    for (double lambda = 0; lambda < 6.2; lambda += 0.2) {
      for (double phi = -1.55; phi < 1.55; phi += 0.2) {
          Vector3D u = new Vector3D(Math.cos(lambda) * Math.cos(phi),
                                    Math.sin(lambda) * Math.cos(phi),
                                    Math.sin(phi));
          checkVector(u, r.applyInverseTo(r.applyTo(u)));
          checkVector(u, r.applyTo(r.applyInverseTo(u)));
      }
    }

    r = new Rotation(Vector3D.plusK, Math.PI);
    for (double lambda = 0; lambda < 6.2; lambda += 0.2) {
      for (double phi = -1.55; phi < 1.55; phi += 0.2) {
          Vector3D u = new Vector3D(Math.cos(lambda) * Math.cos(phi),
                                    Math.sin(lambda) * Math.cos(phi),
                                    Math.sin(phi));
          checkVector(u, r.applyInverseTo(r.applyTo(u)));
          checkVector(u, r.applyTo(r.applyInverseTo(u)));
      }
View Full Code Here

    super(name);
  }

  public void testConstructors() {
      double r = Math.sqrt(2) /2;
      checkVector(new Vector3D(2, new Vector3D(Math.PI / 3, -Math.PI / 4)),
                  r, r * Math.sqrt(3), -2 * r);
      checkVector(new Vector3D(2, Vector3D.plusI,
                              -3, Vector3D.minusK),
                  2, 0, 3);
      checkVector(new Vector3D(2, Vector3D.plusI,
                               5, Vector3D.plusJ,
                              -3, Vector3D.minusK),
                  2, 5, 3);
      checkVector(new Vector3D(2, Vector3D.plusI,
                               5, Vector3D.plusJ,
                               5, Vector3D.minusJ,
                               -3, Vector3D.minusK),
                  2, 0, 3);
  }
View Full Code Here

                               -3, Vector3D.minusK),
                  2, 0, 3);
  }

  public void testCoordinates() {
    Vector3D v = new Vector3D(1, 2, 3);
    assertTrue(Math.abs(v.getX() - 1) < 1.0e-12);
    assertTrue(Math.abs(v.getY() - 2) < 1.0e-12);
    assertTrue(Math.abs(v.getZ() - 3) < 1.0e-12);
  }
View Full Code Here

    assertTrue(Math.abs(v.getY() - 2) < 1.0e-12);
    assertTrue(Math.abs(v.getZ() - 3) < 1.0e-12);
  }
 
  public void testNorm() {
    assertTrue(Math.abs(new Vector3D().getNorm()) < 1.0e-12);
    assertTrue(Math.abs(new Vector3D(1, 2, 3).getNorm() - Math.sqrt(14))
               < 1.0e-12);
  }
View Full Code Here

               < 1.0e-12);
  }

  public void testSubtract() {

    Vector3D v1 = new Vector3D(1, 2, 3);
    Vector3D v2 = new Vector3D(-3, -2, -1);
    v1 = v1.subtract(v2);
    checkVector(v1, 4, 4, 4);

    checkVector(v2.subtract(v1), -7, -6, -5);
    checkVector(v2.subtract(3, v1), -15, -14, -13);

  }
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.