improved consistency between Vector3D and RealMatrix API (multiply -> scalarMultiply)
improved javadoc git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@627998 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
79325e1f4e
commit
7f5355a3ea
|
@ -232,16 +232,16 @@ public class Vector3D
|
||||||
return new Vector3D(x - factor * v.x, y - factor * v.y, z - factor * v.z);
|
return new Vector3D(x - factor * v.x, y - factor * v.y, z - factor * v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Normalize the instance.
|
/** Get a normalized vector aligned with the instance.
|
||||||
* @return a new normalized vector
|
* @return a new normalized vector
|
||||||
* @exception ArithmeticException if the norm is null
|
* @exception ArithmeticException if the norm is zero
|
||||||
*/
|
*/
|
||||||
public Vector3D normalize() {
|
public Vector3D normalize() {
|
||||||
double s = getNorm();
|
double s = getNorm();
|
||||||
if (s == 0) {
|
if (s == 0) {
|
||||||
throw new ArithmeticException("null norm");
|
throw new ArithmeticException("cannot normalize a zero norm vector");
|
||||||
}
|
}
|
||||||
return multiply(1 / s);
|
return scalarMultiply(1 / s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get a vector orthogonal to the instance.
|
/** Get a vector orthogonal to the instance.
|
||||||
|
@ -323,7 +323,7 @@ public class Vector3D
|
||||||
* @param a scalar
|
* @param a scalar
|
||||||
* @return a new vector
|
* @return a new vector
|
||||||
*/
|
*/
|
||||||
public Vector3D multiply(double a) {
|
public Vector3D scalarMultiply(double a) {
|
||||||
return new Vector3D(a * x, a * y, a * z);
|
return new Vector3D(a * x, a * y, a * z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,6 +357,7 @@ public class Vector3D
|
||||||
private final double z;
|
private final double z;
|
||||||
|
|
||||||
/** Serializable version identifier */
|
/** Serializable version identifier */
|
||||||
private static final long serialVersionUID = 7318440192750283659L;
|
private static final long serialVersionUID = -5721105387745193385L;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class RotationTest
|
||||||
Vector3D u = new Vector3D(3, 2, 1);
|
Vector3D u = new Vector3D(3, 2, 1);
|
||||||
Vector3D v = new Vector3D(-4, 2, 2);
|
Vector3D v = new Vector3D(-4, 2, 2);
|
||||||
Rotation r = new Rotation(u, v);
|
Rotation r = new Rotation(u, v);
|
||||||
checkVector(r.applyTo(u.multiply(v.getNorm())), v.multiply(u.getNorm()));
|
checkVector(r.applyTo(u.scalarMultiply(v.getNorm())), v.scalarMultiply(u.getNorm()));
|
||||||
|
|
||||||
checkAngle(new Rotation(u, u.negate()).getAngle(), Math.PI);
|
checkAngle(new Rotation(u, u.negate()).getAngle(), Math.PI);
|
||||||
|
|
||||||
|
|
|
@ -84,10 +84,10 @@ public class Vector3DTest
|
||||||
|
|
||||||
public void testScalarProduct() {
|
public void testScalarProduct() {
|
||||||
Vector3D v = new Vector3D(1, 2, 3);
|
Vector3D v = new Vector3D(1, 2, 3);
|
||||||
v = v.multiply(3);
|
v = v.scalarMultiply(3);
|
||||||
checkVector(v, 3, 6, 9);
|
checkVector(v, 3, 6, 9);
|
||||||
|
|
||||||
checkVector(v.multiply(0.5), 1.5, 3, 4.5);
|
checkVector(v.scalarMultiply(0.5), 1.5, 3, 4.5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class Vector3DTest
|
||||||
|
|
||||||
Vector3D k = v1.normalize();
|
Vector3D k = v1.normalize();
|
||||||
Vector3D i = k.orthogonal();
|
Vector3D i = k.orthogonal();
|
||||||
Vector3D v2 = k.multiply(Math.cos(1.2)).add(i.multiply(Math.sin(1.2)));
|
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);
|
assertTrue(Math.abs(Vector3D.angle(v1, v2) - 1.2) < 1.0e-12);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue