MATH-459
Removed usage of "o.a.c.m.MathRuntimeException". git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1056554 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f35ac8ee99
commit
258918de6b
|
@ -19,7 +19,7 @@ package org.apache.commons.math.geometry;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.apache.commons.math.MathRuntimeException;
|
import org.apache.commons.math.exception.MathArithmeticException;
|
||||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||||
import org.apache.commons.math.util.MathUtils;
|
import org.apache.commons.math.util.MathUtils;
|
||||||
import org.apache.commons.math.util.FastMath;
|
import org.apache.commons.math.util.FastMath;
|
||||||
|
@ -30,10 +30,7 @@ import org.apache.commons.math.util.FastMath;
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
* @since 1.2
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
|
public class Vector3D implements Serializable {
|
||||||
public class Vector3D
|
|
||||||
implements Serializable {
|
|
||||||
|
|
||||||
/** Null vector (coordinates: 0, 0, 0). */
|
/** Null vector (coordinates: 0, 0, 0). */
|
||||||
public static final Vector3D ZERO = new Vector3D(0, 0, 0);
|
public static final Vector3D ZERO = new Vector3D(0, 0, 0);
|
||||||
|
|
||||||
|
@ -285,7 +282,7 @@ public class Vector3D
|
||||||
public Vector3D normalize() {
|
public Vector3D normalize() {
|
||||||
double s = getNorm();
|
double s = getNorm();
|
||||||
if (s == 0) {
|
if (s == 0) {
|
||||||
throw MathRuntimeException.createArithmeticException(LocalizedFormats.CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR);
|
throw new MathArithmeticException(LocalizedFormats.CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR);
|
||||||
}
|
}
|
||||||
return scalarMultiply(1 / s);
|
return scalarMultiply(1 / s);
|
||||||
}
|
}
|
||||||
|
@ -309,7 +306,7 @@ public class Vector3D
|
||||||
|
|
||||||
double threshold = 0.6 * getNorm();
|
double threshold = 0.6 * getNorm();
|
||||||
if (threshold == 0) {
|
if (threshold == 0) {
|
||||||
throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_NORM);
|
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((x >= -threshold) && (x <= threshold)) {
|
if ((x >= -threshold) && (x <= threshold)) {
|
||||||
|
@ -339,7 +336,7 @@ public class Vector3D
|
||||||
|
|
||||||
double normProduct = v1.getNorm() * v2.getNorm();
|
double normProduct = v1.getNorm() * v2.getNorm();
|
||||||
if (normProduct == 0) {
|
if (normProduct == 0) {
|
||||||
throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_NORM);
|
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
|
||||||
}
|
}
|
||||||
|
|
||||||
double dot = dotProduct(v1, v2);
|
double dot = dotProduct(v1, v2);
|
||||||
|
|
|
@ -19,208 +19,213 @@ package org.apache.commons.math.geometry;
|
||||||
|
|
||||||
import org.apache.commons.math.geometry.Vector3D;
|
import org.apache.commons.math.geometry.Vector3D;
|
||||||
import org.apache.commons.math.util.FastMath;
|
import org.apache.commons.math.util.FastMath;
|
||||||
|
import org.apache.commons.math.exception.MathArithmeticException;
|
||||||
|
|
||||||
import junit.framework.*;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Vector3DTest
|
public class Vector3DTest {
|
||||||
extends TestCase {
|
@Test
|
||||||
|
public void testConstructors() {
|
||||||
public Vector3DTest(String name) {
|
double r = FastMath.sqrt(2) /2;
|
||||||
super(name);
|
checkVector(new Vector3D(2, new Vector3D(FastMath.PI / 3, -FastMath.PI / 4)),
|
||||||
}
|
r, r * FastMath.sqrt(3), -2 * r);
|
||||||
|
checkVector(new Vector3D(2, Vector3D.PLUS_I,
|
||||||
public void testConstructors() {
|
-3, Vector3D.MINUS_K),
|
||||||
double r = FastMath.sqrt(2) /2;
|
2, 0, 3);
|
||||||
checkVector(new Vector3D(2, new Vector3D(FastMath.PI / 3, -FastMath.PI / 4)),
|
checkVector(new Vector3D(2, Vector3D.PLUS_I,
|
||||||
r, r * FastMath.sqrt(3), -2 * r);
|
5, Vector3D.PLUS_J,
|
||||||
checkVector(new Vector3D(2, Vector3D.PLUS_I,
|
-3, Vector3D.MINUS_K),
|
||||||
-3, Vector3D.MINUS_K),
|
2, 5, 3);
|
||||||
2, 0, 3);
|
checkVector(new Vector3D(2, Vector3D.PLUS_I,
|
||||||
checkVector(new Vector3D(2, Vector3D.PLUS_I,
|
5, Vector3D.PLUS_J,
|
||||||
5, Vector3D.PLUS_J,
|
5, Vector3D.MINUS_J,
|
||||||
-3, Vector3D.MINUS_K),
|
-3, Vector3D.MINUS_K),
|
||||||
2, 5, 3);
|
2, 0, 3);
|
||||||
checkVector(new Vector3D(2, Vector3D.PLUS_I,
|
|
||||||
5, Vector3D.PLUS_J,
|
|
||||||
5, Vector3D.MINUS_J,
|
|
||||||
-3, Vector3D.MINUS_K),
|
|
||||||
2, 0, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testCoordinates() {
|
|
||||||
Vector3D v = new Vector3D(1, 2, 3);
|
|
||||||
assertTrue(FastMath.abs(v.getX() - 1) < 1.0e-12);
|
|
||||||
assertTrue(FastMath.abs(v.getY() - 2) < 1.0e-12);
|
|
||||||
assertTrue(FastMath.abs(v.getZ() - 3) < 1.0e-12);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNorm1() {
|
|
||||||
assertEquals(0.0, Vector3D.ZERO.getNorm1());
|
|
||||||
assertEquals(6.0, new Vector3D(1, -2, 3).getNorm1(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNorm() {
|
|
||||||
assertEquals(0.0, Vector3D.ZERO.getNorm());
|
|
||||||
assertEquals(FastMath.sqrt(14), new Vector3D(1, 2, 3).getNorm(), 1.0e-12);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNormInf() {
|
@Test
|
||||||
assertEquals(0.0, Vector3D.ZERO.getNormInf());
|
public void testCoordinates() {
|
||||||
assertEquals(3.0, new Vector3D(1, -2, 3).getNormInf(), 0);
|
Vector3D v = new Vector3D(1, 2, 3);
|
||||||
|
Assert.assertTrue(FastMath.abs(v.getX() - 1) < 1.0e-12);
|
||||||
|
Assert.assertTrue(FastMath.abs(v.getY() - 2) < 1.0e-12);
|
||||||
|
Assert.assertTrue(FastMath.abs(v.getZ() - 3) < 1.0e-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDistance1() {
|
@Test
|
||||||
Vector3D v1 = new Vector3D(1, -2, 3);
|
public void testNorm1() {
|
||||||
Vector3D v2 = new Vector3D(-4, 2, 0);
|
Assert.assertEquals(0.0, Vector3D.ZERO.getNorm1(), 0);
|
||||||
assertEquals(0.0, Vector3D.distance1(Vector3D.MINUS_I, Vector3D.MINUS_I), 0);
|
Assert.assertEquals(6.0, new Vector3D(1, -2, 3).getNorm1(), 0);
|
||||||
assertEquals(12.0, Vector3D.distance1(v1, v2), 1.0e-12);
|
|
||||||
assertEquals(v1.subtract(v2).getNorm1(), Vector3D.distance1(v1, v2), 1.0e-12);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDistance() {
|
|
||||||
Vector3D v1 = new Vector3D(1, -2, 3);
|
|
||||||
Vector3D v2 = new Vector3D(-4, 2, 0);
|
|
||||||
assertEquals(0.0, Vector3D.distance(Vector3D.MINUS_I, Vector3D.MINUS_I), 0);
|
|
||||||
assertEquals(FastMath.sqrt(50), Vector3D.distance(v1, v2), 1.0e-12);
|
|
||||||
assertEquals(v1.subtract(v2).getNorm(), Vector3D.distance(v1, v2), 1.0e-12);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDistanceSq() {
|
|
||||||
Vector3D v1 = new Vector3D(1, -2, 3);
|
|
||||||
Vector3D v2 = new Vector3D(-4, 2, 0);
|
|
||||||
assertEquals(0.0, Vector3D.distanceSq(Vector3D.MINUS_I, Vector3D.MINUS_I), 0);
|
|
||||||
assertEquals(50.0, Vector3D.distanceSq(v1, v2), 1.0e-12);
|
|
||||||
assertEquals(Vector3D.distance(v1, v2) * Vector3D.distance(v1, v2),
|
|
||||||
Vector3D.distanceSq(v1, v2), 1.0e-12);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDistanceInf() {
|
|
||||||
Vector3D v1 = new Vector3D(1, -2, 3);
|
|
||||||
Vector3D v2 = new Vector3D(-4, 2, 0);
|
|
||||||
assertEquals(0.0, Vector3D.distanceInf(Vector3D.MINUS_I, Vector3D.MINUS_I), 0);
|
|
||||||
assertEquals(5.0, Vector3D.distanceInf(v1, v2), 1.0e-12);
|
|
||||||
assertEquals(v1.subtract(v2).getNormInf(), Vector3D.distanceInf(v1, v2), 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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAdd() {
|
|
||||||
Vector3D v1 = new Vector3D(1, 2, 3);
|
|
||||||
Vector3D v2 = new Vector3D(-3, -2, -1);
|
|
||||||
v1 = v1.add(v2);
|
|
||||||
checkVector(v1, -2, 0, 2);
|
|
||||||
|
|
||||||
checkVector(v2.add(v1), -5, -2, 1);
|
|
||||||
checkVector(v2.add(3, v1), -9, -2, 5);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testScalarProduct() {
|
|
||||||
Vector3D v = new Vector3D(1, 2, 3);
|
|
||||||
v = v.scalarMultiply(3);
|
|
||||||
checkVector(v, 3, 6, 9);
|
|
||||||
|
|
||||||
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(FastMath.abs(Vector3D.dotProduct(v1, v2) - 11) < 1.0e-12);
|
|
||||||
|
|
||||||
Vector3D v3 = Vector3D.crossProduct(v1, v2);
|
|
||||||
checkVector(v3, 3, -10, -1);
|
|
||||||
|
|
||||||
assertTrue(FastMath.abs(Vector3D.dotProduct(v1, v3)) < 1.0e-12);
|
|
||||||
assertTrue(FastMath.abs(Vector3D.dotProduct(v2, v3)) < 1.0e-12);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAngular() {
|
|
||||||
|
|
||||||
assertEquals(0, Vector3D.PLUS_I.getAlpha(), 1.0e-10);
|
|
||||||
assertEquals(0, Vector3D.PLUS_I.getDelta(), 1.0e-10);
|
|
||||||
assertEquals(FastMath.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(FastMath.PI / 2, Vector3D.PLUS_K.getDelta(), 1.0e-10);
|
|
||||||
|
|
||||||
Vector3D u = new Vector3D(-1, 1, -1);
|
|
||||||
assertEquals(3 * FastMath.PI /4, u.getAlpha(), 1.0e-10);
|
|
||||||
assertEquals(-1.0 / FastMath.sqrt(3), FastMath.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(FastMath.cos(1.2)).add(i.scalarMultiply(FastMath.sin(1.2)));
|
|
||||||
|
|
||||||
assertTrue(FastMath.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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNorm() {
|
||||||
|
Assert.assertEquals(0.0, Vector3D.ZERO.getNorm(), 0);
|
||||||
|
Assert.assertEquals(FastMath.sqrt(14), new Vector3D(1, 2, 3).getNorm(), 1.0e-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNormInf() {
|
||||||
|
Assert.assertEquals(0.0, Vector3D.ZERO.getNormInf(), 0);
|
||||||
|
Assert.assertEquals(3.0, new Vector3D(1, -2, 3).getNormInf(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDistance1() {
|
||||||
|
Vector3D v1 = new Vector3D(1, -2, 3);
|
||||||
|
Vector3D v2 = new Vector3D(-4, 2, 0);
|
||||||
|
Assert.assertEquals(0.0, Vector3D.distance1(Vector3D.MINUS_I, Vector3D.MINUS_I), 0);
|
||||||
|
Assert.assertEquals(12.0, Vector3D.distance1(v1, v2), 1.0e-12);
|
||||||
|
Assert.assertEquals(v1.subtract(v2).getNorm1(), Vector3D.distance1(v1, v2), 1.0e-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDistance() {
|
||||||
|
Vector3D v1 = new Vector3D(1, -2, 3);
|
||||||
|
Vector3D v2 = new Vector3D(-4, 2, 0);
|
||||||
|
Assert.assertEquals(0.0, Vector3D.distance(Vector3D.MINUS_I, Vector3D.MINUS_I), 0);
|
||||||
|
Assert.assertEquals(FastMath.sqrt(50), Vector3D.distance(v1, v2), 1.0e-12);
|
||||||
|
Assert.assertEquals(v1.subtract(v2).getNorm(), Vector3D.distance(v1, v2), 1.0e-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDistanceSq() {
|
||||||
|
Vector3D v1 = new Vector3D(1, -2, 3);
|
||||||
|
Vector3D v2 = new Vector3D(-4, 2, 0);
|
||||||
|
Assert.assertEquals(0.0, Vector3D.distanceSq(Vector3D.MINUS_I, Vector3D.MINUS_I), 0);
|
||||||
|
Assert.assertEquals(50.0, Vector3D.distanceSq(v1, v2), 1.0e-12);
|
||||||
|
Assert.assertEquals(Vector3D.distance(v1, v2) * Vector3D.distance(v1, v2),
|
||||||
|
Vector3D.distanceSq(v1, v2), 1.0e-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOrthogonal() {
|
@Test
|
||||||
Vector3D v1 = new Vector3D(0.1, 2.5, 1.3);
|
public void testDistanceInf() {
|
||||||
assertEquals(0.0, Vector3D.dotProduct(v1, v1.orthogonal()), 1.0e-12);
|
Vector3D v1 = new Vector3D(1, -2, 3);
|
||||||
Vector3D v2 = new Vector3D(2.3, -0.003, 7.6);
|
Vector3D v2 = new Vector3D(-4, 2, 0);
|
||||||
assertEquals(0.0, Vector3D.dotProduct(v2, v2.orthogonal()), 1.0e-12);
|
Assert.assertEquals(0.0, Vector3D.distanceInf(Vector3D.MINUS_I, Vector3D.MINUS_I), 0);
|
||||||
Vector3D v3 = new Vector3D(-1.7, 1.4, 0.2);
|
Assert.assertEquals(5.0, Vector3D.distanceInf(v1, v2), 1.0e-12);
|
||||||
assertEquals(0.0, Vector3D.dotProduct(v3, v3.orthogonal()), 1.0e-12);
|
Assert.assertEquals(v1.subtract(v2).getNormInf(), Vector3D.distanceInf(v1, v2), 1.0e-12);
|
||||||
try {
|
}
|
||||||
new Vector3D(0, 0, 0).orthogonal();
|
|
||||||
fail("an exception should have been thrown");
|
@Test
|
||||||
} catch (ArithmeticException ae) {
|
public void testSubtract() {
|
||||||
// expected behavior
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdd() {
|
||||||
|
Vector3D v1 = new Vector3D(1, 2, 3);
|
||||||
|
Vector3D v2 = new Vector3D(-3, -2, -1);
|
||||||
|
v1 = v1.add(v2);
|
||||||
|
checkVector(v1, -2, 0, 2);
|
||||||
|
|
||||||
|
checkVector(v2.add(v1), -5, -2, 1);
|
||||||
|
checkVector(v2.add(3, v1), -9, -2, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testScalarProduct() {
|
||||||
|
Vector3D v = new Vector3D(1, 2, 3);
|
||||||
|
v = v.scalarMultiply(3);
|
||||||
|
checkVector(v, 3, 6, 9);
|
||||||
|
|
||||||
|
checkVector(v.scalarMultiply(0.5), 1.5, 3, 4.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVectorialProducts() {
|
||||||
|
Vector3D v1 = new Vector3D(2, 1, -4);
|
||||||
|
Vector3D v2 = new Vector3D(3, 1, -1);
|
||||||
|
|
||||||
|
Assert.assertTrue(FastMath.abs(Vector3D.dotProduct(v1, v2) - 11) < 1.0e-12);
|
||||||
|
|
||||||
|
Vector3D v3 = Vector3D.crossProduct(v1, v2);
|
||||||
|
checkVector(v3, 3, -10, -1);
|
||||||
|
|
||||||
|
Assert.assertTrue(FastMath.abs(Vector3D.dotProduct(v1, v3)) < 1.0e-12);
|
||||||
|
Assert.assertTrue(FastMath.abs(Vector3D.dotProduct(v2, v3)) < 1.0e-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAngular() {
|
||||||
|
Assert.assertEquals(0, Vector3D.PLUS_I.getAlpha(), 1.0e-10);
|
||||||
|
Assert.assertEquals(0, Vector3D.PLUS_I.getDelta(), 1.0e-10);
|
||||||
|
Assert.assertEquals(FastMath.PI / 2, Vector3D.PLUS_J.getAlpha(), 1.0e-10);
|
||||||
|
Assert.assertEquals(0, Vector3D.PLUS_J.getDelta(), 1.0e-10);
|
||||||
|
Assert.assertEquals(0, Vector3D.PLUS_K.getAlpha(), 1.0e-10);
|
||||||
|
Assert.assertEquals(FastMath.PI / 2, Vector3D.PLUS_K.getDelta(), 1.0e-10);
|
||||||
|
|
||||||
|
Vector3D u = new Vector3D(-1, 1, -1);
|
||||||
|
Assert.assertEquals(3 * FastMath.PI /4, u.getAlpha(), 1.0e-10);
|
||||||
|
Assert.assertEquals(-1.0 / FastMath.sqrt(3), FastMath.sin(u.getDelta()), 1.0e-10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAngularSeparation() {
|
||||||
|
Vector3D v1 = new Vector3D(2, -1, 4);
|
||||||
|
|
||||||
|
Vector3D k = v1.normalize();
|
||||||
|
Vector3D i = k.orthogonal();
|
||||||
|
Vector3D v2 = k.scalarMultiply(FastMath.cos(1.2)).add(i.scalarMultiply(FastMath.sin(1.2)));
|
||||||
|
|
||||||
|
Assert.assertTrue(FastMath.abs(Vector3D.angle(v1, v2) - 1.2) < 1.0e-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAngle() {
|
@Test
|
||||||
assertEquals(0.22572612855273393616,
|
public void testNormalize() {
|
||||||
Vector3D.angle(new Vector3D(1, 2, 3), new Vector3D(4, 5, 6)),
|
Assert.assertEquals(1.0, new Vector3D(5, -4, 2).normalize().getNorm(), 1.0e-12);
|
||||||
1.0e-12);
|
try {
|
||||||
assertEquals(7.98595620686106654517199e-8,
|
Vector3D.ZERO.normalize();
|
||||||
Vector3D.angle(new Vector3D(1, 2, 3), new Vector3D(2, 4, 6.000001)),
|
Assert.fail("an exception should have been thrown");
|
||||||
1.0e-12);
|
} catch (MathArithmeticException ae) {
|
||||||
assertEquals(3.14159257373023116985197793156,
|
// expected behavior
|
||||||
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) {
|
|
||||||
// expected behavior
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkVector(Vector3D v, double x, double y, double z) {
|
@Test
|
||||||
assertEquals(x, v.getX(), 1.0e-12);
|
public void testOrthogonal() {
|
||||||
assertEquals(y, v.getY(), 1.0e-12);
|
Vector3D v1 = new Vector3D(0.1, 2.5, 1.3);
|
||||||
assertEquals(z, v.getZ(), 1.0e-12);
|
Assert.assertEquals(0.0, Vector3D.dotProduct(v1, v1.orthogonal()), 1.0e-12);
|
||||||
}
|
Vector3D v2 = new Vector3D(2.3, -0.003, 7.6);
|
||||||
|
Assert.assertEquals(0.0, Vector3D.dotProduct(v2, v2.orthogonal()), 1.0e-12);
|
||||||
|
Vector3D v3 = new Vector3D(-1.7, 1.4, 0.2);
|
||||||
|
Assert.assertEquals(0.0, Vector3D.dotProduct(v3, v3.orthogonal()), 1.0e-12);
|
||||||
|
try {
|
||||||
|
new Vector3D(0, 0, 0).orthogonal();
|
||||||
|
Assert.fail("an exception should have been thrown");
|
||||||
|
} catch (MathArithmeticException ae) {
|
||||||
|
// expected behavior
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAngle() {
|
||||||
|
Assert.assertEquals(0.22572612855273393616,
|
||||||
|
Vector3D.angle(new Vector3D(1, 2, 3), new Vector3D(4, 5, 6)),
|
||||||
|
1.0e-12);
|
||||||
|
Assert.assertEquals(7.98595620686106654517199e-8,
|
||||||
|
Vector3D.angle(new Vector3D(1, 2, 3), new Vector3D(2, 4, 6.000001)),
|
||||||
|
1.0e-12);
|
||||||
|
Assert.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);
|
||||||
|
Assert.fail("an exception should have been thrown");
|
||||||
|
} catch (MathArithmeticException ae) {
|
||||||
|
// expected behavior
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkVector(Vector3D v, double x, double y, double z) {
|
||||||
|
Assert.assertEquals(x, v.getX(), 1.0e-12);
|
||||||
|
Assert.assertEquals(y, v.getY(), 1.0e-12);
|
||||||
|
Assert.assertEquals(z, v.getZ(), 1.0e-12);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue