You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2017/05/12 21:32:29 UTC
[20/31] [math] MATH-1284: Replace/rename Coordinate?D classes (nee
Vector?D) as Cartesian?D classes as per discussion. When there are existing
overridden methods accepting Vector and Point,
add a disambiguating method accepting
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java
index ff8f17e..63e7017 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java
@@ -48,8 +48,8 @@ import org.apache.commons.math4.util.MathArrays;
* <p>Focus is oriented on what a rotation <em>do</em> rather than on its
* underlying representation. Once it has been built, and regardless of its
* internal representation, a rotation is an <em>operator</em> which basically
- * transforms three dimensional {@link Coordinates3D vectors} into other three
- * dimensional {@link Coordinates3D vectors}. Depending on the application, the
+ * transforms three dimensional {@link Cartesian3D vectors} into other three
+ * dimensional {@link Cartesian3D vectors}. Depending on the application, the
* meaning of these vectors may vary and the semantics of the rotation also.</p>
* <p>For example in an spacecraft attitude simulation tool, users will often
* consider the vectors are fixed (say the Earth direction for example) and the
@@ -88,7 +88,7 @@ import org.apache.commons.math4.util.MathArrays;
*
* <p>Rotations are guaranteed to be immutable objects.</p>
*
- * @see Coordinates3D
+ * @see Cartesian3D
* @see RotationOrder
* @since 1.2
*/
@@ -162,7 +162,7 @@ public class Rotation implements Serializable {
* @deprecated as of 3.6, replaced with {@link #Rotation(Vector3D, double, RotationConvention)}
*/
@Deprecated
- public Rotation(Coordinates3D axis, double angle) throws MathIllegalArgumentException {
+ public Rotation(Cartesian3D axis, double angle) throws MathIllegalArgumentException {
this(axis, angle, RotationConvention.VECTOR_OPERATOR);
}
@@ -173,7 +173,7 @@ public class Rotation implements Serializable {
* @exception MathIllegalArgumentException if the axis norm is zero
* @since 3.6
*/
- public Rotation(final Coordinates3D axis, final double angle, final RotationConvention convention)
+ public Rotation(final Cartesian3D axis, final double angle, final RotationConvention convention)
throws MathIllegalArgumentException {
double norm = axis.getNorm();
@@ -272,18 +272,18 @@ public class Rotation implements Serializable {
* @exception MathArithmeticException if the norm of one of the vectors is zero,
* or if one of the pair is degenerated (i.e. the vectors of the pair are collinear)
*/
- public Rotation(Coordinates3D u1, Coordinates3D u2, Coordinates3D v1, Coordinates3D v2)
+ public Rotation(Cartesian3D u1, Cartesian3D u2, Cartesian3D v1, Cartesian3D v2)
throws MathArithmeticException {
// build orthonormalized base from u1, u2
// this fails when vectors are null or collinear, which is forbidden to define a rotation
- final Coordinates3D u3 = u1.crossProduct(u2).normalize();
+ final Cartesian3D u3 = u1.crossProduct(u2).normalize();
u2 = u3.crossProduct(u1).normalize();
u1 = u1.normalize();
// build an orthonormalized base from v1, v2
// this fails when vectors are null or collinear, which is forbidden to define a rotation
- final Coordinates3D v3 = v1.crossProduct(v2).normalize();
+ final Cartesian3D v3 = v1.crossProduct(v2).normalize();
v2 = v3.crossProduct(v1).normalize();
v1 = v1.normalize();
@@ -327,7 +327,7 @@ public class Rotation implements Serializable {
* @param v desired image of u by the rotation
* @exception MathArithmeticException if the norm of one of the vectors is zero
*/
- public Rotation(Coordinates3D u, Coordinates3D v) throws MathArithmeticException {
+ public Rotation(Cartesian3D u, Cartesian3D v) throws MathArithmeticException {
double normProduct = u.getNorm() * v.getNorm();
if (normProduct == 0) {
@@ -339,7 +339,7 @@ public class Rotation implements Serializable {
if (dot < ((2.0e-15 - 1.0) * normProduct)) {
// special case u = -v: we select a PI angle rotation around
// an arbitrary vector orthogonal to u
- Coordinates3D w = u.orthogonal();
+ Cartesian3D w = u.orthogonal();
q0 = 0.0;
q1 = -w.getX();
q2 = -w.getY();
@@ -349,7 +349,7 @@ public class Rotation implements Serializable {
// the shortest possible rotation: axis orthogonal to this plane
q0 = FastMath.sqrt(0.5 * (1.0 + dot / normProduct));
double coeff = 1.0 / (2.0 * q0 * normProduct);
- Coordinates3D q = v.crossProduct(u);
+ Cartesian3D q = v.crossProduct(u);
q1 = coeff * q.getX();
q2 = coeff * q.getY();
q3 = coeff * q.getZ();
@@ -522,7 +522,7 @@ public class Rotation implements Serializable {
* @deprecated as of 3.6, replaced with {@link #getAxis(RotationConvention)}
*/
@Deprecated
- public Coordinates3D getAxis() {
+ public Cartesian3D getAxis() {
return getAxis(RotationConvention.VECTOR_OPERATOR);
}
@@ -537,18 +537,18 @@ public class Rotation implements Serializable {
* @see #Rotation(Vector3D, double, RotationConvention)
* @since 3.6
*/
- public Coordinates3D getAxis(final RotationConvention convention) {
+ public Cartesian3D getAxis(final RotationConvention convention) {
final double squaredSine = q1 * q1 + q2 * q2 + q3 * q3;
if (squaredSine == 0) {
- return convention == RotationConvention.VECTOR_OPERATOR ? Coordinates3D.PLUS_I : Coordinates3D.MINUS_I;
+ return convention == RotationConvention.VECTOR_OPERATOR ? Cartesian3D.PLUS_I : Cartesian3D.MINUS_I;
} else {
final double sgn = convention == RotationConvention.VECTOR_OPERATOR ? +1 : -1;
if (q0 < 0) {
final double inverse = sgn / FastMath.sqrt(squaredSine);
- return new Coordinates3D(q1 * inverse, q2 * inverse, q3 * inverse);
+ return new Cartesian3D(q1 * inverse, q2 * inverse, q3 * inverse);
}
final double inverse = -sgn / FastMath.sqrt(squaredSine);
- return new Coordinates3D(q1 * inverse, q2 * inverse, q3 * inverse);
+ return new Cartesian3D(q1 * inverse, q2 * inverse, q3 * inverse);
}
}
@@ -633,8 +633,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusI) coordinates are :
// cos (psi) cos (theta), -sin (psi) cos (theta), sin (theta)
// and we can choose to have theta in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_K);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_I);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_K);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_I);
if ((v2.getZ() < -0.9999999999) || (v2.getZ() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -651,8 +651,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusI) coordinates are :
// cos (theta) cos (psi), -sin (psi), sin (theta) cos (psi)
// and we can choose to have psi in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_J);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_I);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_J);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_I);
if ((v2.getY() < -0.9999999999) || (v2.getY() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -669,8 +669,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusJ) coordinates are :
// sin (psi) cos (phi), cos (psi) cos (phi), -sin (phi)
// and we can choose to have phi in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_K);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_J);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_K);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_J);
if ((v2.getZ() < -0.9999999999) || (v2.getZ() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -687,8 +687,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusJ) coordinates are :
// sin (psi), cos (phi) cos (psi), -sin (phi) cos (psi)
// and we can choose to have psi in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_I);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_J);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_I);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_J);
if ((v2.getX() < -0.9999999999) || (v2.getX() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -705,8 +705,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusK) coordinates are :
// -sin (theta) cos (phi), sin (phi), cos (theta) cos (phi)
// and we can choose to have phi in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_J);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_K);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_J);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_K);
if ((v2.getY() < -0.9999999999) || (v2.getY() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -723,8 +723,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusK) coordinates are :
// -sin (theta), sin (phi) cos (theta), cos (phi) cos (theta)
// and we can choose to have theta in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_I);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_K);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_I);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_K);
if ((v2.getX() < -0.9999999999) || (v2.getX() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -741,8 +741,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusI) coordinates are :
// cos (theta), sin (theta) sin (phi2), sin (theta) cos (phi2)
// and we can choose to have theta in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_I);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_I);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_I);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_I);
if ((v2.getX() < -0.9999999999) || (v2.getX() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -759,8 +759,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusI) coordinates are :
// cos (psi), -sin (psi) cos (phi2), sin (psi) sin (phi2)
// and we can choose to have psi in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_I);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_I);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_I);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_I);
if ((v2.getX() < -0.9999999999) || (v2.getX() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -777,8 +777,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusJ) coordinates are :
// sin (phi) sin (theta2), cos (phi), -sin (phi) cos (theta2)
// and we can choose to have phi in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_J);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_J);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_J);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_J);
if ((v2.getY() < -0.9999999999) || (v2.getY() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -795,8 +795,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusJ) coordinates are :
// sin (psi) cos (theta2), cos (psi), sin (psi) sin (theta2)
// and we can choose to have psi in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_J);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_J);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_J);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_J);
if ((v2.getY() < -0.9999999999) || (v2.getY() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -813,8 +813,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusK) coordinates are :
// sin (phi) sin (psi2), sin (phi) cos (psi2), cos (phi)
// and we can choose to have phi in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_K);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_K);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_K);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_K);
if ((v2.getZ() < -0.9999999999) || (v2.getZ() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -831,8 +831,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusK) coordinates are :
// -sin (theta) cos (psi2), sin (theta) sin (psi2), cos (theta)
// and we can choose to have theta in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_K);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_K);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_K);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_K);
if ((v2.getZ() < -0.9999999999) || (v2.getZ() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -851,8 +851,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusK) coordinates are :
// sin (theta), -sin (phi) cos (theta), cos (phi) cos (theta)
// and we can choose to have theta in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_I);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_K);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_I);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_K);
if ((v2.getX() < -0.9999999999) || (v2.getX() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -869,8 +869,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusJ) coordinates are :
// -sin (psi), cos (phi) cos (psi), sin (phi) cos (psi)
// and we can choose to have psi in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_I);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_J);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_I);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_J);
if ((v2.getX() < -0.9999999999) || (v2.getX() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -887,8 +887,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusK) coordinates are :
// sin (theta) cos (phi), -sin (phi), cos (theta) cos (phi)
// and we can choose to have phi in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_J);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_K);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_J);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_K);
if ((v2.getY() < -0.9999999999) || (v2.getY() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -905,8 +905,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusI) coordinates are :
// cos (theta) cos (psi), sin (psi), -sin (theta) cos (psi)
// and we can choose to have psi in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_J);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_I);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_J);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_I);
if ((v2.getY() < -0.9999999999) || (v2.getY() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -923,8 +923,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusJ) coordinates are :
// -sin (psi) cos (phi), cos (psi) cos (phi), sin (phi)
// and we can choose to have phi in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_K);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_J);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_K);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_J);
if ((v2.getZ() < -0.9999999999) || (v2.getZ() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -941,8 +941,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusI) coordinates are :
// cos (psi) cos (theta), sin (psi) cos (theta), -sin (theta)
// and we can choose to have theta in the interval [-PI/2 ; +PI/2]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_K);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_I);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_K);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_I);
if ((v2.getZ() < -0.9999999999) || (v2.getZ() > 0.9999999999)) {
throw new CardanEulerSingularityException(true);
}
@@ -959,8 +959,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusI) coordinates are :
// cos (theta), sin (theta) sin (phi1), -sin (theta) cos (phi1)
// and we can choose to have theta in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_I);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_I);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_I);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_I);
if ((v2.getX() < -0.9999999999) || (v2.getX() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -977,8 +977,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusI) coordinates are :
// cos (psi), sin (psi) cos (phi1), sin (psi) sin (phi1)
// and we can choose to have psi in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_I);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_I);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_I);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_I);
if ((v2.getX() < -0.9999999999) || (v2.getX() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -995,8 +995,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusJ) coordinates are :
// sin (theta1) sin (phi), cos (phi), cos (theta1) sin (phi)
// and we can choose to have phi in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_J);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_J);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_J);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_J);
if ((v2.getY() < -0.9999999999) || (v2.getY() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -1013,8 +1013,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusJ) coordinates are :
// -cos (theta1) sin (psi), cos (psi), sin (theta1) sin (psi)
// and we can choose to have psi in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_J);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_J);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_J);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_J);
if ((v2.getY() < -0.9999999999) || (v2.getY() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -1031,8 +1031,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusK) coordinates are :
// sin (psi1) sin (phi), -cos (psi1) sin (phi), cos (phi)
// and we can choose to have phi in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_K);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_K);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_K);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_K);
if ((v2.getZ() < -0.9999999999) || (v2.getZ() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -1049,8 +1049,8 @@ public class Rotation implements Serializable {
// (-r) (Vector3D.plusK) coordinates are :
// cos (psi1) sin (theta), sin (psi1) sin (theta), cos (theta)
// and we can choose to have theta in the interval [0 ; PI]
- Coordinates3D v1 = applyTo(Coordinates3D.PLUS_K);
- Coordinates3D v2 = applyInverseTo(Coordinates3D.PLUS_K);
+ Cartesian3D v1 = applyTo(Cartesian3D.PLUS_K);
+ Cartesian3D v2 = applyInverseTo(Cartesian3D.PLUS_K);
if ((v2.getZ() < -0.9999999999) || (v2.getZ() > 0.9999999999)) {
throw new CardanEulerSingularityException(false);
}
@@ -1108,7 +1108,7 @@ public class Rotation implements Serializable {
* @param u vector to apply the rotation to
* @return a new vector which is the image of u by the rotation
*/
- public Coordinates3D applyTo(Coordinates3D u) {
+ public Cartesian3D applyTo(Cartesian3D u) {
double x = u.getX();
double y = u.getY();
@@ -1116,7 +1116,7 @@ public class Rotation implements Serializable {
double s = q1 * x + q2 * y + q3 * z;
- return new Coordinates3D(2 * (q0 * (x * q0 - (q2 * z - q3 * y)) + s * q1) - x,
+ return new Cartesian3D(2 * (q0 * (x * q0 - (q2 * z - q3 * y)) + s * q1) - x,
2 * (q0 * (y * q0 - (q3 * x - q1 * z)) + s * q2) - y,
2 * (q0 * (z * q0 - (q1 * y - q2 * x)) + s * q3) - z);
@@ -1145,7 +1145,7 @@ public class Rotation implements Serializable {
* @param u vector to apply the inverse of the rotation to
* @return a new vector which such that u is its image by the rotation
*/
- public Coordinates3D applyInverseTo(Coordinates3D u) {
+ public Cartesian3D applyInverseTo(Cartesian3D u) {
double x = u.getX();
double y = u.getY();
@@ -1154,7 +1154,7 @@ public class Rotation implements Serializable {
double s = q1 * x + q2 * y + q3 * z;
double m0 = -q0;
- return new Coordinates3D(2 * (m0 * (x * m0 - (q2 * z - q3 * y)) + s * q1) - x,
+ return new Cartesian3D(2 * (m0 * (x * m0 - (q2 * z - q3 * y)) + s * q1) - x,
2 * (m0 * (y * m0 - (q3 * x - q1 * z)) + s * q2) - y,
2 * (m0 * (z * m0 - (q1 * y - q2 * x)) + s * q3) - z);
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/RotationOrder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/RotationOrder.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/RotationOrder.java
index 0eec6d0..020de0e 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/RotationOrder.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/RotationOrder.java
@@ -35,96 +35,96 @@ public final class RotationOrder {
* around Z
*/
public static final RotationOrder XYZ =
- new RotationOrder("XYZ", Coordinates3D.PLUS_I, Coordinates3D.PLUS_J, Coordinates3D.PLUS_K);
+ new RotationOrder("XYZ", Cartesian3D.PLUS_I, Cartesian3D.PLUS_J, Cartesian3D.PLUS_K);
/** Set of Cardan angles.
* this ordered set of rotations is around X, then around Z, then
* around Y
*/
public static final RotationOrder XZY =
- new RotationOrder("XZY", Coordinates3D.PLUS_I, Coordinates3D.PLUS_K, Coordinates3D.PLUS_J);
+ new RotationOrder("XZY", Cartesian3D.PLUS_I, Cartesian3D.PLUS_K, Cartesian3D.PLUS_J);
/** Set of Cardan angles.
* this ordered set of rotations is around Y, then around X, then
* around Z
*/
public static final RotationOrder YXZ =
- new RotationOrder("YXZ", Coordinates3D.PLUS_J, Coordinates3D.PLUS_I, Coordinates3D.PLUS_K);
+ new RotationOrder("YXZ", Cartesian3D.PLUS_J, Cartesian3D.PLUS_I, Cartesian3D.PLUS_K);
/** Set of Cardan angles.
* this ordered set of rotations is around Y, then around Z, then
* around X
*/
public static final RotationOrder YZX =
- new RotationOrder("YZX", Coordinates3D.PLUS_J, Coordinates3D.PLUS_K, Coordinates3D.PLUS_I);
+ new RotationOrder("YZX", Cartesian3D.PLUS_J, Cartesian3D.PLUS_K, Cartesian3D.PLUS_I);
/** Set of Cardan angles.
* this ordered set of rotations is around Z, then around X, then
* around Y
*/
public static final RotationOrder ZXY =
- new RotationOrder("ZXY", Coordinates3D.PLUS_K, Coordinates3D.PLUS_I, Coordinates3D.PLUS_J);
+ new RotationOrder("ZXY", Cartesian3D.PLUS_K, Cartesian3D.PLUS_I, Cartesian3D.PLUS_J);
/** Set of Cardan angles.
* this ordered set of rotations is around Z, then around Y, then
* around X
*/
public static final RotationOrder ZYX =
- new RotationOrder("ZYX", Coordinates3D.PLUS_K, Coordinates3D.PLUS_J, Coordinates3D.PLUS_I);
+ new RotationOrder("ZYX", Cartesian3D.PLUS_K, Cartesian3D.PLUS_J, Cartesian3D.PLUS_I);
/** Set of Euler angles.
* this ordered set of rotations is around X, then around Y, then
* around X
*/
public static final RotationOrder XYX =
- new RotationOrder("XYX", Coordinates3D.PLUS_I, Coordinates3D.PLUS_J, Coordinates3D.PLUS_I);
+ new RotationOrder("XYX", Cartesian3D.PLUS_I, Cartesian3D.PLUS_J, Cartesian3D.PLUS_I);
/** Set of Euler angles.
* this ordered set of rotations is around X, then around Z, then
* around X
*/
public static final RotationOrder XZX =
- new RotationOrder("XZX", Coordinates3D.PLUS_I, Coordinates3D.PLUS_K, Coordinates3D.PLUS_I);
+ new RotationOrder("XZX", Cartesian3D.PLUS_I, Cartesian3D.PLUS_K, Cartesian3D.PLUS_I);
/** Set of Euler angles.
* this ordered set of rotations is around Y, then around X, then
* around Y
*/
public static final RotationOrder YXY =
- new RotationOrder("YXY", Coordinates3D.PLUS_J, Coordinates3D.PLUS_I, Coordinates3D.PLUS_J);
+ new RotationOrder("YXY", Cartesian3D.PLUS_J, Cartesian3D.PLUS_I, Cartesian3D.PLUS_J);
/** Set of Euler angles.
* this ordered set of rotations is around Y, then around Z, then
* around Y
*/
public static final RotationOrder YZY =
- new RotationOrder("YZY", Coordinates3D.PLUS_J, Coordinates3D.PLUS_K, Coordinates3D.PLUS_J);
+ new RotationOrder("YZY", Cartesian3D.PLUS_J, Cartesian3D.PLUS_K, Cartesian3D.PLUS_J);
/** Set of Euler angles.
* this ordered set of rotations is around Z, then around X, then
* around Z
*/
public static final RotationOrder ZXZ =
- new RotationOrder("ZXZ", Coordinates3D.PLUS_K, Coordinates3D.PLUS_I, Coordinates3D.PLUS_K);
+ new RotationOrder("ZXZ", Cartesian3D.PLUS_K, Cartesian3D.PLUS_I, Cartesian3D.PLUS_K);
/** Set of Euler angles.
* this ordered set of rotations is around Z, then around Y, then
* around Z
*/
public static final RotationOrder ZYZ =
- new RotationOrder("ZYZ", Coordinates3D.PLUS_K, Coordinates3D.PLUS_J, Coordinates3D.PLUS_K);
+ new RotationOrder("ZYZ", Cartesian3D.PLUS_K, Cartesian3D.PLUS_J, Cartesian3D.PLUS_K);
/** Name of the rotations order. */
private final String name;
/** Axis of the first rotation. */
- private final Coordinates3D a1;
+ private final Cartesian3D a1;
/** Axis of the second rotation. */
- private final Coordinates3D a2;
+ private final Cartesian3D a2;
/** Axis of the third rotation. */
- private final Coordinates3D a3;
+ private final Cartesian3D a3;
/** Private constructor.
* This is a utility class that cannot be instantiated by the user,
@@ -135,7 +135,7 @@ public final class RotationOrder {
* @param a3 axis of the third rotation
*/
private RotationOrder(final String name,
- final Coordinates3D a1, final Coordinates3D a2, final Coordinates3D a3) {
+ final Cartesian3D a1, final Cartesian3D a2, final Cartesian3D a3) {
this.name = name;
this.a1 = a1;
this.a2 = a2;
@@ -153,21 +153,21 @@ public final class RotationOrder {
/** Get the axis of the first rotation.
* @return axis of the first rotation
*/
- public Coordinates3D getA1() {
+ public Cartesian3D getA1() {
return a1;
}
/** Get the axis of the second rotation.
* @return axis of the second rotation
*/
- public Coordinates3D getA2() {
+ public Cartesian3D getA2() {
return a2;
}
/** Get the axis of the second rotation.
* @return axis of the second rotation
*/
- public Coordinates3D getA3() {
+ public Cartesian3D getA3() {
return a3;
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Segment.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Segment.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Segment.java
index bf7e81f..6ced496 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Segment.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Segment.java
@@ -23,10 +23,10 @@ package org.apache.commons.math4.geometry.euclidean.threed;
public class Segment {
/** Start point of the segment. */
- private final Coordinates3D start;
+ private final Cartesian3D start;
/** End point of the segments. */
- private final Coordinates3D end;
+ private final Cartesian3D end;
/** Line containing the segment. */
private final Line line;
@@ -36,7 +36,7 @@ public class Segment {
* @param end end point of the segment
* @param line line containing the segment
*/
- public Segment(final Coordinates3D start, final Coordinates3D end, final Line line) {
+ public Segment(final Cartesian3D start, final Cartesian3D end, final Line line) {
this.start = start;
this.end = end;
this.line = line;
@@ -45,14 +45,14 @@ public class Segment {
/** Get the start point of the segment.
* @return start point of the segment
*/
- public Coordinates3D getStart() {
+ public Cartesian3D getStart() {
return start;
}
/** Get the end point of the segment.
* @return end point of the segment
*/
- public Coordinates3D getEnd() {
+ public Cartesian3D getEnd() {
return end;
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGenerator.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGenerator.java
index 08163dd..8ed5a6a 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGenerator.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGenerator.java
@@ -24,38 +24,38 @@ import org.apache.commons.math4.geometry.enclosing.EnclosingBall;
import org.apache.commons.math4.geometry.enclosing.SupportBallGenerator;
import org.apache.commons.math4.geometry.euclidean.twod.DiskGenerator;
import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D;
-import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D;
+import org.apache.commons.math4.geometry.euclidean.twod.Cartesian2D;
import org.apache.commons.math4.util.FastMath;
/** Class generating an enclosing ball from its support points.
* @since 3.3
*/
-public class SphereGenerator implements SupportBallGenerator<Euclidean3D, Coordinates3D> {
+public class SphereGenerator implements SupportBallGenerator<Euclidean3D, Cartesian3D> {
/** {@inheritDoc} */
@Override
- public EnclosingBall<Euclidean3D, Coordinates3D> ballOnSupport(final List<Coordinates3D> support) {
+ public EnclosingBall<Euclidean3D, Cartesian3D> ballOnSupport(final List<Cartesian3D> support) {
if (support.size() < 1) {
- return new EnclosingBall<>(Coordinates3D.ZERO, Double.NEGATIVE_INFINITY);
+ return new EnclosingBall<>(Cartesian3D.ZERO, Double.NEGATIVE_INFINITY);
} else {
- final Coordinates3D vA = support.get(0);
+ final Cartesian3D vA = support.get(0);
if (support.size() < 2) {
return new EnclosingBall<>(vA, 0, vA);
} else {
- final Coordinates3D vB = support.get(1);
+ final Cartesian3D vB = support.get(1);
if (support.size() < 3) {
- return new EnclosingBall<>(new Coordinates3D(0.5, vA, 0.5, vB),
+ return new EnclosingBall<>(new Cartesian3D(0.5, vA, 0.5, vB),
0.5 * vA.distance(vB),
vA, vB);
} else {
- final Coordinates3D vC = support.get(2);
+ final Cartesian3D vC = support.get(2);
if (support.size() < 4) {
// delegate to 2D disk generator
final Plane p = new Plane(vA, vB, vC,
1.0e-10 * (vA.getNorm1() + vB.getNorm1() + vC.getNorm1()));
- final EnclosingBall<Euclidean2D, Coordinates2D> disk =
+ final EnclosingBall<Euclidean2D, Cartesian2D> disk =
new DiskGenerator().ballOnSupport(Arrays.asList(p.toSubSpace(vA),
p.toSubSpace(vB),
p.toSubSpace(vC)));
@@ -65,7 +65,7 @@ public class SphereGenerator implements SupportBallGenerator<Euclidean3D, Coordi
disk.getRadius(), vA, vB, vC);
} else {
- final Coordinates3D vD = support.get(3);
+ final Cartesian3D vD = support.get(3);
// a sphere is 3D can be defined as:
// (1) (x - x_0)^2 + (y - y_0)^2 + (z - z_0)^2 = r^2
// which can be written:
@@ -118,7 +118,7 @@ public class SphereGenerator implements SupportBallGenerator<Euclidean3D, Coordi
final BigFraction dy = c3[0].subtract(centerY);
final BigFraction dz = c4[0].subtract(centerZ);
final BigFraction r2 = dx.multiply(dx).add(dy.multiply(dy)).add(dz.multiply(dz));
- return new EnclosingBall<>(new Coordinates3D(centerX.doubleValue(),
+ return new EnclosingBall<>(new Cartesian3D(centerX.doubleValue(),
centerY.doubleValue(),
centerZ.doubleValue()),
FastMath.sqrt(r2.doubleValue()),
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SphericalCoordinates.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SphericalCoordinates.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SphericalCoordinates.java
index aa4582a..b82ec20 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SphericalCoordinates.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SphericalCoordinates.java
@@ -55,7 +55,7 @@ public class SphericalCoordinates implements Serializable {
private static final long serialVersionUID = 20130206L;
/** Cartesian coordinates. */
- private final Coordinates3D v;
+ private final Cartesian3D v;
/** Radius. */
private final double r;
@@ -81,7 +81,7 @@ public class SphericalCoordinates implements Serializable {
/** Build a spherical coordinates transformer from Cartesian coordinates.
* @param v Cartesian coordinates
*/
- public SphericalCoordinates(final Coordinates3D v) {
+ public SphericalCoordinates(final Cartesian3D v) {
// Cartesian coordinates
this.v = v;
@@ -111,7 +111,7 @@ public class SphericalCoordinates implements Serializable {
this.phi = phi;
// Cartesian coordinates
- this.v = new Coordinates3D(r * cosTheta * sinPhi,
+ this.v = new Cartesian3D(r * cosTheta * sinPhi,
r * sinTheta * sinPhi,
r * cosPhi);
@@ -120,7 +120,7 @@ public class SphericalCoordinates implements Serializable {
/** Get the Cartesian coordinates.
* @return Cartesian coordinates
*/
- public Coordinates3D getCartesian() {
+ public Cartesian3D getCartesian() {
return v;
}
@@ -387,7 +387,7 @@ public class SphericalCoordinates implements Serializable {
* @return replacement {@link SphericalCoordinates}
*/
private Object readResolve() {
- return new SphericalCoordinates(new Coordinates3D(x, y, z));
+ return new SphericalCoordinates(new Cartesian3D(x, y, z));
}
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SubLine.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SubLine.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SubLine.java
index 1dc0361..8eab249 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SubLine.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SubLine.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.geometry.Point;
import org.apache.commons.math4.geometry.euclidean.oned.Euclidean1D;
import org.apache.commons.math4.geometry.euclidean.oned.Interval;
import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet;
-import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D;
+import org.apache.commons.math4.geometry.euclidean.oned.Cartesian1D;
import org.apache.commons.math4.geometry.partitioning.Region.Location;
/** This class represents a subset of a {@link Line}.
@@ -54,7 +54,7 @@ public class SubLine {
* @exception MathIllegalArgumentException if the points are equal
* @since 3.3
*/
- public SubLine(final Coordinates3D start, final Coordinates3D end, final double tolerance)
+ public SubLine(final Cartesian3D start, final Cartesian3D end, final double tolerance)
throws MathIllegalArgumentException {
this(new Line(start, end, tolerance), buildIntervalSet(start, end, tolerance));
}
@@ -88,8 +88,8 @@ public class SubLine {
final List<Segment> segments = new ArrayList<>(list.size());
for (final Interval interval : list) {
- final Coordinates3D start = line.toSpace((Point<Euclidean1D>) new Coordinates1D(interval.getInf()));
- final Coordinates3D end = line.toSpace((Point<Euclidean1D>) new Coordinates1D(interval.getSup()));
+ final Cartesian3D start = line.toSpace(new Cartesian1D(interval.getInf()));
+ final Cartesian3D end = line.toSpace(new Cartesian1D(interval.getSup()));
segments.add(new Segment(start, end, line));
}
@@ -111,10 +111,10 @@ public class SubLine {
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
- public Coordinates3D intersection(final SubLine subLine, final boolean includeEndPoints) {
+ public Cartesian3D intersection(final SubLine subLine, final boolean includeEndPoints) {
// compute the intersection on infinite line
- Coordinates3D v1D = line.intersection(subLine.line);
+ Cartesian3D v1D = line.intersection(subLine.line);
if (v1D == null) {
return null;
}
@@ -140,7 +140,7 @@ public class SubLine {
* @param tolerance tolerance below which points are considered identical
* @exception MathIllegalArgumentException if the points are equal
*/
- private static IntervalsSet buildIntervalSet(final Coordinates3D start, final Coordinates3D end, final double tolerance)
+ private static IntervalsSet buildIntervalSet(final Cartesian3D start, final Cartesian3D end, final double tolerance)
throws MathIllegalArgumentException {
final Line line = new Line(start, end, tolerance);
return new IntervalsSet(line.toSubSpace((Point<Euclidean3D>) start).getX(),
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SubPlane.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SubPlane.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SubPlane.java
index bb2de1b..adc6860 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SubPlane.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/SubPlane.java
@@ -16,12 +16,10 @@
*/
package org.apache.commons.math4.geometry.euclidean.threed;
-import org.apache.commons.math4.geometry.Point;
-import org.apache.commons.math4.geometry.euclidean.oned.Euclidean1D;
-import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D;
+import org.apache.commons.math4.geometry.euclidean.oned.Cartesian1D;
import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D;
import org.apache.commons.math4.geometry.euclidean.twod.PolygonsSet;
-import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D;
+import org.apache.commons.math4.geometry.euclidean.twod.Cartesian2D;
import org.apache.commons.math4.geometry.partitioning.AbstractSubHyperplane;
import org.apache.commons.math4.geometry.partitioning.BSPTree;
import org.apache.commons.math4.geometry.partitioning.Hyperplane;
@@ -76,11 +74,11 @@ public class SubPlane extends AbstractSubHyperplane<Euclidean3D, Euclidean2D> {
}
// the hyperplanes do intersect
- Coordinates2D p = thisPlane.toSubSpace((Point<Euclidean3D>) inter.toSpace((Point<Euclidean1D>) Coordinates1D.ZERO));
- Coordinates2D q = thisPlane.toSubSpace((Point<Euclidean3D>) inter.toSpace((Point<Euclidean1D>) Coordinates1D.ONE));
- Coordinates3D crossP = Coordinates3D.crossProduct(inter.getDirection(), thisPlane.getNormal());
+ Cartesian2D p = thisPlane.toSubSpace(inter.toSpace(Cartesian1D.ZERO));
+ Cartesian2D q = thisPlane.toSubSpace(inter.toSpace(Cartesian1D.ONE));
+ Cartesian3D crossP = Cartesian3D.crossProduct(inter.getDirection(), thisPlane.getNormal());
if (crossP.dotProduct(otherPlane.getNormal()) < 0) {
- final Coordinates2D tmp = p;
+ final Cartesian2D tmp = p;
p = q;
q = tmp;
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java
index fd6cce9..dc2c0f9 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java
@@ -104,7 +104,7 @@ public class Vector3DFormat extends VectorFormat<Euclidean3D> {
}
/**
- * Formats a {@link Coordinates3D} object to produce a string.
+ * Formats a {@link Cartesian3D} object to produce a string.
* @param vector the object to format.
* @param toAppendTo where the text is to be appended
* @param pos On input: an alignment field, if desired. On output: the
@@ -114,42 +114,42 @@ public class Vector3DFormat extends VectorFormat<Euclidean3D> {
@Override
public StringBuffer format(final Vector<Euclidean3D> vector, final StringBuffer toAppendTo,
final FieldPosition pos) {
- final Coordinates3D v3 = (Coordinates3D) vector;
+ final Cartesian3D v3 = (Cartesian3D) vector;
return format(toAppendTo, pos, v3.getX(), v3.getY(), v3.getZ());
}
/**
- * Parses a string to produce a {@link Coordinates3D} object.
+ * Parses a string to produce a {@link Cartesian3D} object.
* @param source the string to parse
- * @return the parsed {@link Coordinates3D} object.
+ * @return the parsed {@link Cartesian3D} object.
* @throws MathParseException if the beginning of the specified string
* cannot be parsed.
*/
@Override
- public Coordinates3D parse(final String source) throws MathParseException {
+ public Cartesian3D parse(final String source) throws MathParseException {
ParsePosition parsePosition = new ParsePosition(0);
- Coordinates3D result = parse(source, parsePosition);
+ Cartesian3D result = parse(source, parsePosition);
if (parsePosition.getIndex() == 0) {
throw new MathParseException(source,
parsePosition.getErrorIndex(),
- Coordinates3D.class);
+ Cartesian3D.class);
}
return result;
}
/**
- * Parses a string to produce a {@link Coordinates3D} object.
+ * Parses a string to produce a {@link Cartesian3D} object.
* @param source the string to parse
* @param pos input/ouput parsing parameter.
- * @return the parsed {@link Coordinates3D} object.
+ * @return the parsed {@link Cartesian3D} object.
*/
@Override
- public Coordinates3D parse(final String source, final ParsePosition pos) {
+ public Cartesian3D parse(final String source, final ParsePosition pos) {
final double[] coordinates = parseCoordinates(3, source, pos);
if (coordinates == null) {
return null;
}
- return new Coordinates3D(coordinates[0], coordinates[1], coordinates[2]);
+ return new Cartesian3D(coordinates[0], coordinates[1], coordinates[2]);
}
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java
new file mode 100644
index 0000000..0272322
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java
@@ -0,0 +1,492 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math4.geometry.euclidean.twod;
+
+import java.text.NumberFormat;
+
+import org.apache.commons.math4.exception.DimensionMismatchException;
+import org.apache.commons.math4.exception.MathArithmeticException;
+import org.apache.commons.math4.exception.util.LocalizedFormats;
+import org.apache.commons.math4.geometry.Point;
+import org.apache.commons.math4.geometry.Space;
+import org.apache.commons.math4.geometry.Vector;
+import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.util.MathArrays;
+import org.apache.commons.math4.util.MathUtils;
+
+/** This class represents a 2D point or a 2D vector.
+ * <p>An instance of Cartesian2D represents the point with the corresponding
+ * coordinates.</p>
+ * <p>An instance of Cartesian2D also represents the vector which begins at
+ * the origin and ends at the point corresponding to the coordinates.</p>
+ * <p>Instances of this class are guaranteed to be immutable.</p>
+ * @since 4.0
+ */
+public class Cartesian2D implements Point<Euclidean2D>, Vector<Euclidean2D> {
+
+ /** Origin (coordinates: 0, 0). */
+ public static final Cartesian2D ZERO = new Cartesian2D(0, 0);
+
+ // CHECKSTYLE: stop ConstantName
+ /** A vector with all coordinates set to NaN. */
+ public static final Cartesian2D NaN = new Cartesian2D(Double.NaN, Double.NaN);
+ // CHECKSTYLE: resume ConstantName
+
+ /** A vector with all coordinates set to positive infinity. */
+ public static final Cartesian2D POSITIVE_INFINITY =
+ new Cartesian2D(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
+
+ /** A vector with all coordinates set to negative infinity. */
+ public static final Cartesian2D NEGATIVE_INFINITY =
+ new Cartesian2D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
+
+ /** Serializable UID. */
+ private static final long serialVersionUID = 266938651998679754L;
+
+ /** Abscissa. */
+ private final double x;
+
+ /** Ordinate. */
+ private final double y;
+
+ /** Simple constructor.
+ * Build a vector from its coordinates
+ * @param x abscissa
+ * @param y ordinate
+ * @see #getX()
+ * @see #getY()
+ */
+ public Cartesian2D(double x, double y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ /** Simple constructor.
+ * Build a vector from its coordinates
+ * @param v coordinates array
+ * @exception DimensionMismatchException if array does not have 2 elements
+ * @see #toArray()
+ */
+ public Cartesian2D(double[] v) throws DimensionMismatchException {
+ if (v.length != 2) {
+ throw new DimensionMismatchException(v.length, 2);
+ }
+ this.x = v[0];
+ this.y = v[1];
+ }
+
+ /** Multiplicative constructor
+ * Build a vector from another one and a scale factor.
+ * The vector built will be a * u
+ * @param a scale factor
+ * @param u base (unscaled) vector
+ */
+ public Cartesian2D(double a, Cartesian2D u) {
+ this.x = a * u.x;
+ this.y = a * u.y;
+ }
+
+ /** Linear constructor
+ * Build a vector from two other ones and corresponding scale factors.
+ * The vector built will be a1 * u1 + a2 * u2
+ * @param a1 first scale factor
+ * @param u1 first base (unscaled) vector
+ * @param a2 second scale factor
+ * @param u2 second base (unscaled) vector
+ */
+ public Cartesian2D(double a1, Cartesian2D u1, double a2, Cartesian2D u2) {
+ this.x = a1 * u1.x + a2 * u2.x;
+ this.y = a1 * u1.y + a2 * u2.y;
+ }
+
+ /** Linear constructor
+ * Build a vector from three other ones and corresponding scale factors.
+ * The vector built will be a1 * u1 + a2 * u2 + a3 * u3
+ * @param a1 first scale factor
+ * @param u1 first base (unscaled) vector
+ * @param a2 second scale factor
+ * @param u2 second base (unscaled) vector
+ * @param a3 third scale factor
+ * @param u3 third base (unscaled) vector
+ */
+ public Cartesian2D(double a1, Cartesian2D u1, double a2, Cartesian2D u2,
+ double a3, Cartesian2D u3) {
+ this.x = a1 * u1.x + a2 * u2.x + a3 * u3.x;
+ this.y = a1 * u1.y + a2 * u2.y + a3 * u3.y;
+ }
+
+ /** Linear constructor
+ * Build a vector from four other ones and corresponding scale factors.
+ * The vector built will be a1 * u1 + a2 * u2 + a3 * u3 + a4 * u4
+ * @param a1 first scale factor
+ * @param u1 first base (unscaled) vector
+ * @param a2 second scale factor
+ * @param u2 second base (unscaled) vector
+ * @param a3 third scale factor
+ * @param u3 third base (unscaled) vector
+ * @param a4 fourth scale factor
+ * @param u4 fourth base (unscaled) vector
+ */
+ public Cartesian2D(double a1, Cartesian2D u1, double a2, Cartesian2D u2,
+ double a3, Cartesian2D u3, double a4, Cartesian2D u4) {
+ this.x = a1 * u1.x + a2 * u2.x + a3 * u3.x + a4 * u4.x;
+ this.y = a1 * u1.y + a2 * u2.y + a3 * u3.y + a4 * u4.y;
+ }
+
+ /** Get the abscissa of the vector.
+ * @return abscissa of the vector
+ * @see #Vector2D(double, double)
+ */
+ public double getX() {
+ return x;
+ }
+
+ /** Get the ordinate of the vector.
+ * @return ordinate of the vector
+ * @see #Vector2D(double, double)
+ */
+ public double getY() {
+ return y;
+ }
+
+ /** Get the vector coordinates as a dimension 2 array.
+ * @return vector coordinates
+ * @see #Vector2D(double[])
+ */
+ public double[] toArray() {
+ return new double[] { x, y };
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Space getSpace() {
+ return Euclidean2D.getInstance();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Cartesian2D getZero() {
+ return ZERO;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public double getNorm1() {
+ return FastMath.abs(x) + FastMath.abs(y);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public double getNorm() {
+ return FastMath.sqrt (x * x + y * y);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public double getNormSq() {
+ return x * x + y * y;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public double getNormInf() {
+ return FastMath.max(FastMath.abs(x), FastMath.abs(y));
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Cartesian2D add(Vector<Euclidean2D> v) {
+ Cartesian2D v2 = (Cartesian2D) v;
+ return new Cartesian2D(x + v2.getX(), y + v2.getY());
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Cartesian2D add(double factor, Vector<Euclidean2D> v) {
+ Cartesian2D v2 = (Cartesian2D) v;
+ return new Cartesian2D(x + factor * v2.getX(), y + factor * v2.getY());
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Cartesian2D subtract(Vector<Euclidean2D> p) {
+ Cartesian2D p3 = (Cartesian2D) p;
+ return new Cartesian2D(x - p3.x, y - p3.y);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Cartesian2D subtract(double factor, Vector<Euclidean2D> v) {
+ Cartesian2D v2 = (Cartesian2D) v;
+ return new Cartesian2D(x - factor * v2.getX(), y - factor * v2.getY());
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Cartesian2D normalize() throws MathArithmeticException {
+ double s = getNorm();
+ if (s == 0) {
+ throw new MathArithmeticException(LocalizedFormats.CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR);
+ }
+ return scalarMultiply(1 / s);
+ }
+
+ /** Compute the angular separation between two vectors.
+ * <p>This method computes the angular separation between two
+ * vectors using the dot product for well separated vectors and the
+ * cross product for almost aligned vectors. This allows to have a
+ * good accuracy in all cases, even for vectors very close to each
+ * other.</p>
+ * @param v1 first vector
+ * @param v2 second vector
+ * @return angular separation between v1 and v2
+ * @exception MathArithmeticException if either vector has a null norm
+ */
+ public static double angle(Cartesian2D v1, Cartesian2D v2) throws MathArithmeticException {
+
+ double normProduct = v1.getNorm() * v2.getNorm();
+ if (normProduct == 0) {
+ throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
+ }
+
+ double dot = v1.dotProduct(v2);
+ double threshold = normProduct * 0.9999;
+ if ((dot < -threshold) || (dot > threshold)) {
+ // the vectors are almost aligned, compute using the sine
+ final double n = FastMath.abs(MathArrays.linearCombination(v1.x, v2.y, -v1.y, v2.x));
+ if (dot >= 0) {
+ return FastMath.asin(n / normProduct);
+ }
+ return FastMath.PI - FastMath.asin(n / normProduct);
+ }
+
+ // the vectors are sufficiently separated to use the cosine
+ return FastMath.acos(dot / normProduct);
+
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Cartesian2D negate() {
+ return new Cartesian2D(-x, -y);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Cartesian2D scalarMultiply(double a) {
+ return new Cartesian2D(a * x, a * y);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isNaN() {
+ return Double.isNaN(x) || Double.isNaN(y);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isInfinite() {
+ return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y));
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public double distance1(Vector<Euclidean2D> p) {
+ Cartesian2D p3 = (Cartesian2D) p;
+ final double dx = FastMath.abs(p3.x - x);
+ final double dy = FastMath.abs(p3.y - y);
+ return dx + dy;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public double distance(Point<Euclidean2D> p) {
+ return distance((Cartesian2D) p);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public double distance(Vector<Euclidean2D> v) {
+ return distance((Cartesian2D) v);
+ }
+
+ /** Compute the distance between the instance and other coordinates.
+ * @param c other coordinates
+ * @return the distance between the instance and c
+ */
+ public double distance(Cartesian2D c) {
+ final double dx = c.x - x;
+ final double dy = c.y - y;
+ return FastMath.sqrt(dx * dx + dy * dy);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public double distanceInf(Vector<Euclidean2D> p) {
+ Cartesian2D p3 = (Cartesian2D) p;
+ final double dx = FastMath.abs(p3.x - x);
+ final double dy = FastMath.abs(p3.y - y);
+ return FastMath.max(dx, dy);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public double distanceSq(Vector<Euclidean2D> p) {
+ Cartesian2D p3 = (Cartesian2D) p;
+ final double dx = p3.x - x;
+ final double dy = p3.y - y;
+ return dx * dx + dy * dy;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public double dotProduct(final Vector<Euclidean2D> v) {
+ final Cartesian2D v2 = (Cartesian2D) v;
+ return MathArrays.linearCombination(x, v2.x, y, v2.y);
+ }
+
+ /**
+ * Compute the cross-product of the instance and the given vector.
+ * <p>
+ * The cross product can be used to determine the location of a point
+ * with regard to the line formed by (p1, p2) and is calculated as:
+ * \[
+ * P = (x_2 - x_1)(y_3 - y_1) - (y_2 - y_1)(x_3 - x_1)
+ * \]
+ * with \(p3 = (x_3, y_3)\) being this instance.
+ * <p>
+ * If the result is 0, the points are collinear, i.e. lie on a single straight line L;
+ * if it is positive, this point lies to the left, otherwise to the right of the line
+ * formed by (p1, p2).
+ *
+ * @param p1 first point of the line
+ * @param p2 second point of the line
+ * @return the cross-product
+ *
+ * @see <a href="http://en.wikipedia.org/wiki/Cross_product">Cross product (Wikipedia)</a>
+ */
+ public double crossProduct(final Cartesian2D p1, final Cartesian2D p2) {
+ final double x1 = p2.getX() - p1.getX();
+ final double y1 = getY() - p1.getY();
+ final double x2 = getX() - p1.getX();
+ final double y2 = p2.getY() - p1.getY();
+ return MathArrays.linearCombination(x1, y1, -x2, y2);
+ }
+
+ /** Compute the distance between two points according to the L<sub>2</sub> norm.
+ * <p>Calling this method is equivalent to calling:
+ * <code>p1.subtract(p2).getNorm()</code> except that no intermediate
+ * vector is built</p>
+ * @param p1 first point
+ * @param p2 second point
+ * @return the distance between p1 and p2 according to the L<sub>2</sub> norm
+ */
+ public static double distance(Cartesian2D p1, Cartesian2D p2) {
+ return p1.distance(p2);
+ }
+
+ /** Compute the distance between two points according to the L<sub>∞</sub> norm.
+ * <p>Calling this method is equivalent to calling:
+ * <code>p1.subtract(p2).getNormInf()</code> except that no intermediate
+ * vector is built</p>
+ * @param p1 first point
+ * @param p2 second point
+ * @return the distance between p1 and p2 according to the L<sub>∞</sub> norm
+ */
+ public static double distanceInf(Cartesian2D p1, Cartesian2D p2) {
+ return p1.distanceInf(p2);
+ }
+
+ /** Compute the square of the distance between two points.
+ * <p>Calling this method is equivalent to calling:
+ * <code>p1.subtract(p2).getNormSq()</code> except that no intermediate
+ * vector is built</p>
+ * @param p1 first point
+ * @param p2 second point
+ * @return the square of the distance between p1 and p2
+ */
+ public static double distanceSq(Cartesian2D p1, Cartesian2D p2) {
+ return p1.distanceSq(p2);
+ }
+
+ /**
+ * Test for the equality of two 2D instances.
+ * <p>
+ * If all coordinates of two 2D vectors are exactly the same, and none are
+ * <code>Double.NaN</code>, the two 2D instances are considered to be equal.
+ * </p>
+ * <p>
+ * <code>NaN</code> coordinates are considered to affect globally the vector
+ * and be equals to each other - i.e, if either (or all) coordinates of the
+ * 2D vector are equal to <code>Double.NaN</code>, the 2D vector is equal to
+ * {@link #NaN}.
+ * </p>
+ *
+ * @param other Object to test for equality to this
+ * @return true if two 2D Cartesian objects are equal, false if
+ * object is null, not an instance of Cartesian2D, or
+ * not equal to this Cartesian2D instance
+ *
+ */
+ @Override
+ public boolean equals(Object other) {
+
+ if (this == other) {
+ return true;
+ }
+
+ if (other instanceof Cartesian2D) {
+ final Cartesian2D rhs = (Cartesian2D)other;
+ if (rhs.isNaN()) {
+ return this.isNaN();
+ }
+
+ return (x == rhs.x) && (y == rhs.y);
+ }
+ return false;
+ }
+
+ /**
+ * Get a hashCode for the 2D coordinates.
+ * <p>
+ * All NaN values have the same hash code.</p>
+ *
+ * @return a hash code value for this object
+ */
+ @Override
+ public int hashCode() {
+ if (isNaN()) {
+ return 542;
+ }
+ return 122 * (76 * MathUtils.hash(x) + MathUtils.hash(y));
+ }
+
+ /** Get a string representation of this vector.
+ * @return a string representation of this vector
+ */
+ @Override
+ public String toString() {
+ return Vector2DFormat.getInstance().format(this);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString(final NumberFormat format) {
+ return new Vector2DFormat(format).format(this);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Coordinates2D.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Coordinates2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Coordinates2D.java
deleted file mode 100644
index e68342e..0000000
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Coordinates2D.java
+++ /dev/null
@@ -1,492 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.geometry.euclidean.twod;
-
-import java.text.NumberFormat;
-
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.MathArithmeticException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.geometry.Point;
-import org.apache.commons.math4.geometry.Space;
-import org.apache.commons.math4.geometry.Vector;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
-import org.apache.commons.math4.util.MathUtils;
-
-/** This class represents a 2D point or a 2D vector.
- * <p>An instance of Coordinates2D represents the point with the corresponding
- * coordinates.</p>
- * <p>An instance of Coordinates2D also represents the vector which begins at
- * the origin and ends at the point corresponding to the coordinates.</p>
- * <p>Instances of this class are guaranteed to be immutable.</p>
- * @since 4.0
- */
-public class Coordinates2D implements Point<Euclidean2D>, Vector<Euclidean2D> {
-
- /** Origin (coordinates: 0, 0). */
- public static final Coordinates2D ZERO = new Coordinates2D(0, 0);
-
- // CHECKSTYLE: stop ConstantName
- /** A vector with all coordinates set to NaN. */
- public static final Coordinates2D NaN = new Coordinates2D(Double.NaN, Double.NaN);
- // CHECKSTYLE: resume ConstantName
-
- /** A vector with all coordinates set to positive infinity. */
- public static final Coordinates2D POSITIVE_INFINITY =
- new Coordinates2D(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
-
- /** A vector with all coordinates set to negative infinity. */
- public static final Coordinates2D NEGATIVE_INFINITY =
- new Coordinates2D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
-
- /** Serializable UID. */
- private static final long serialVersionUID = 266938651998679754L;
-
- /** Abscissa. */
- private final double x;
-
- /** Ordinate. */
- private final double y;
-
- /** Simple constructor.
- * Build a vector from its coordinates
- * @param x abscissa
- * @param y ordinate
- * @see #getX()
- * @see #getY()
- */
- public Coordinates2D(double x, double y) {
- this.x = x;
- this.y = y;
- }
-
- /** Simple constructor.
- * Build a vector from its coordinates
- * @param v coordinates array
- * @exception DimensionMismatchException if array does not have 2 elements
- * @see #toArray()
- */
- public Coordinates2D(double[] v) throws DimensionMismatchException {
- if (v.length != 2) {
- throw new DimensionMismatchException(v.length, 2);
- }
- this.x = v[0];
- this.y = v[1];
- }
-
- /** Multiplicative constructor
- * Build a vector from another one and a scale factor.
- * The vector built will be a * u
- * @param a scale factor
- * @param u base (unscaled) vector
- */
- public Coordinates2D(double a, Coordinates2D u) {
- this.x = a * u.x;
- this.y = a * u.y;
- }
-
- /** Linear constructor
- * Build a vector from two other ones and corresponding scale factors.
- * The vector built will be a1 * u1 + a2 * u2
- * @param a1 first scale factor
- * @param u1 first base (unscaled) vector
- * @param a2 second scale factor
- * @param u2 second base (unscaled) vector
- */
- public Coordinates2D(double a1, Coordinates2D u1, double a2, Coordinates2D u2) {
- this.x = a1 * u1.x + a2 * u2.x;
- this.y = a1 * u1.y + a2 * u2.y;
- }
-
- /** Linear constructor
- * Build a vector from three other ones and corresponding scale factors.
- * The vector built will be a1 * u1 + a2 * u2 + a3 * u3
- * @param a1 first scale factor
- * @param u1 first base (unscaled) vector
- * @param a2 second scale factor
- * @param u2 second base (unscaled) vector
- * @param a3 third scale factor
- * @param u3 third base (unscaled) vector
- */
- public Coordinates2D(double a1, Coordinates2D u1, double a2, Coordinates2D u2,
- double a3, Coordinates2D u3) {
- this.x = a1 * u1.x + a2 * u2.x + a3 * u3.x;
- this.y = a1 * u1.y + a2 * u2.y + a3 * u3.y;
- }
-
- /** Linear constructor
- * Build a vector from four other ones and corresponding scale factors.
- * The vector built will be a1 * u1 + a2 * u2 + a3 * u3 + a4 * u4
- * @param a1 first scale factor
- * @param u1 first base (unscaled) vector
- * @param a2 second scale factor
- * @param u2 second base (unscaled) vector
- * @param a3 third scale factor
- * @param u3 third base (unscaled) vector
- * @param a4 fourth scale factor
- * @param u4 fourth base (unscaled) vector
- */
- public Coordinates2D(double a1, Coordinates2D u1, double a2, Coordinates2D u2,
- double a3, Coordinates2D u3, double a4, Coordinates2D u4) {
- this.x = a1 * u1.x + a2 * u2.x + a3 * u3.x + a4 * u4.x;
- this.y = a1 * u1.y + a2 * u2.y + a3 * u3.y + a4 * u4.y;
- }
-
- /** Get the abscissa of the vector.
- * @return abscissa of the vector
- * @see #Vector2D(double, double)
- */
- public double getX() {
- return x;
- }
-
- /** Get the ordinate of the vector.
- * @return ordinate of the vector
- * @see #Vector2D(double, double)
- */
- public double getY() {
- return y;
- }
-
- /** Get the vector coordinates as a dimension 2 array.
- * @return vector coordinates
- * @see #Vector2D(double[])
- */
- public double[] toArray() {
- return new double[] { x, y };
- }
-
- /** {@inheritDoc} */
- @Override
- public Space getSpace() {
- return Euclidean2D.getInstance();
- }
-
- /** {@inheritDoc} */
- @Override
- public Coordinates2D getZero() {
- return ZERO;
- }
-
- /** {@inheritDoc} */
- @Override
- public double getNorm1() {
- return FastMath.abs(x) + FastMath.abs(y);
- }
-
- /** {@inheritDoc} */
- @Override
- public double getNorm() {
- return FastMath.sqrt (x * x + y * y);
- }
-
- /** {@inheritDoc} */
- @Override
- public double getNormSq() {
- return x * x + y * y;
- }
-
- /** {@inheritDoc} */
- @Override
- public double getNormInf() {
- return FastMath.max(FastMath.abs(x), FastMath.abs(y));
- }
-
- /** {@inheritDoc} */
- @Override
- public Coordinates2D add(Vector<Euclidean2D> v) {
- Coordinates2D v2 = (Coordinates2D) v;
- return new Coordinates2D(x + v2.getX(), y + v2.getY());
- }
-
- /** {@inheritDoc} */
- @Override
- public Coordinates2D add(double factor, Vector<Euclidean2D> v) {
- Coordinates2D v2 = (Coordinates2D) v;
- return new Coordinates2D(x + factor * v2.getX(), y + factor * v2.getY());
- }
-
- /** {@inheritDoc} */
- @Override
- public Coordinates2D subtract(Vector<Euclidean2D> p) {
- Coordinates2D p3 = (Coordinates2D) p;
- return new Coordinates2D(x - p3.x, y - p3.y);
- }
-
- /** {@inheritDoc} */
- @Override
- public Coordinates2D subtract(double factor, Vector<Euclidean2D> v) {
- Coordinates2D v2 = (Coordinates2D) v;
- return new Coordinates2D(x - factor * v2.getX(), y - factor * v2.getY());
- }
-
- /** {@inheritDoc} */
- @Override
- public Coordinates2D normalize() throws MathArithmeticException {
- double s = getNorm();
- if (s == 0) {
- throw new MathArithmeticException(LocalizedFormats.CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR);
- }
- return scalarMultiply(1 / s);
- }
-
- /** Compute the angular separation between two vectors.
- * <p>This method computes the angular separation between two
- * vectors using the dot product for well separated vectors and the
- * cross product for almost aligned vectors. This allows to have a
- * good accuracy in all cases, even for vectors very close to each
- * other.</p>
- * @param v1 first vector
- * @param v2 second vector
- * @return angular separation between v1 and v2
- * @exception MathArithmeticException if either vector has a null norm
- */
- public static double angle(Coordinates2D v1, Coordinates2D v2) throws MathArithmeticException {
-
- double normProduct = v1.getNorm() * v2.getNorm();
- if (normProduct == 0) {
- throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
- }
-
- double dot = v1.dotProduct(v2);
- double threshold = normProduct * 0.9999;
- if ((dot < -threshold) || (dot > threshold)) {
- // the vectors are almost aligned, compute using the sine
- final double n = FastMath.abs(MathArrays.linearCombination(v1.x, v2.y, -v1.y, v2.x));
- if (dot >= 0) {
- return FastMath.asin(n / normProduct);
- }
- return FastMath.PI - FastMath.asin(n / normProduct);
- }
-
- // the vectors are sufficiently separated to use the cosine
- return FastMath.acos(dot / normProduct);
-
- }
-
- /** {@inheritDoc} */
- @Override
- public Coordinates2D negate() {
- return new Coordinates2D(-x, -y);
- }
-
- /** {@inheritDoc} */
- @Override
- public Coordinates2D scalarMultiply(double a) {
- return new Coordinates2D(a * x, a * y);
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isNaN() {
- return Double.isNaN(x) || Double.isNaN(y);
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isInfinite() {
- return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y));
- }
-
- /** {@inheritDoc} */
- @Override
- public double distance1(Vector<Euclidean2D> p) {
- Coordinates2D p3 = (Coordinates2D) p;
- final double dx = FastMath.abs(p3.x - x);
- final double dy = FastMath.abs(p3.y - y);
- return dx + dy;
- }
-
- /** {@inheritDoc} */
- @Override
- public double distance(Point<Euclidean2D> p) {
- return distance((Coordinates2D) p);
- }
-
- /** {@inheritDoc} */
- @Override
- public double distance(Vector<Euclidean2D> v) {
- return distance((Coordinates2D) v);
- }
-
- /** Compute the distance between the instance and other coordinates.
- * @param c other coordinates
- * @return the distance between the instance and c
- */
- public double distance(Coordinates2D c) {
- final double dx = c.x - x;
- final double dy = c.y - y;
- return FastMath.sqrt(dx * dx + dy * dy);
- }
-
- /** {@inheritDoc} */
- @Override
- public double distanceInf(Vector<Euclidean2D> p) {
- Coordinates2D p3 = (Coordinates2D) p;
- final double dx = FastMath.abs(p3.x - x);
- final double dy = FastMath.abs(p3.y - y);
- return FastMath.max(dx, dy);
- }
-
- /** {@inheritDoc} */
- @Override
- public double distanceSq(Vector<Euclidean2D> p) {
- Coordinates2D p3 = (Coordinates2D) p;
- final double dx = p3.x - x;
- final double dy = p3.y - y;
- return dx * dx + dy * dy;
- }
-
- /** {@inheritDoc} */
- @Override
- public double dotProduct(final Vector<Euclidean2D> v) {
- final Coordinates2D v2 = (Coordinates2D) v;
- return MathArrays.linearCombination(x, v2.x, y, v2.y);
- }
-
- /**
- * Compute the cross-product of the instance and the given points.
- * <p>
- * The cross product can be used to determine the location of a point
- * with regard to the line formed by (p1, p2) and is calculated as:
- * \[
- * P = (x_2 - x_1)(y_3 - y_1) - (y_2 - y_1)(x_3 - x_1)
- * \]
- * with \(p3 = (x_3, y_3)\) being this instance.
- * <p>
- * If the result is 0, the points are collinear, i.e. lie on a single straight line L;
- * if it is positive, this point lies to the left, otherwise to the right of the line
- * formed by (p1, p2).
- *
- * @param p1 first point of the line
- * @param p2 second point of the line
- * @return the cross-product
- *
- * @see <a href="http://en.wikipedia.org/wiki/Cross_product">Cross product (Wikipedia)</a>
- */
- public double crossProduct(final Coordinates2D p1, final Coordinates2D p2) {
- final double x1 = p2.getX() - p1.getX();
- final double y1 = getY() - p1.getY();
- final double x2 = getX() - p1.getX();
- final double y2 = p2.getY() - p1.getY();
- return MathArrays.linearCombination(x1, y1, -x2, y2);
- }
-
- /** Compute the distance between two vectors according to the L<sub>2</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>p1.subtract(p2).getNorm()</code> except that no intermediate
- * vector is built</p>
- * @param p1 first vector
- * @param p2 second vector
- * @return the distance between p1 and p2 according to the L<sub>2</sub> norm
- */
- public static double distance(Coordinates2D p1, Coordinates2D p2) {
- return p1.distance(p2);
- }
-
- /** Compute the distance between two vectors according to the L<sub>∞</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>p1.subtract(p2).getNormInf()</code> except that no intermediate
- * vector is built</p>
- * @param p1 first vector
- * @param p2 second vector
- * @return the distance between p1 and p2 according to the L<sub>∞</sub> norm
- */
- public static double distanceInf(Coordinates2D p1, Coordinates2D p2) {
- return p1.distanceInf(p2);
- }
-
- /** Compute the square of the distance between two vectors.
- * <p>Calling this method is equivalent to calling:
- * <code>p1.subtract(p2).getNormSq()</code> except that no intermediate
- * vector is built</p>
- * @param p1 first vector
- * @param p2 second vector
- * @return the square of the distance between p1 and p2
- */
- public static double distanceSq(Coordinates2D p1, Coordinates2D p2) {
- return p1.distanceSq(p2);
- }
-
- /**
- * Test for the equality of two 2D vectors.
- * <p>
- * If all coordinates of two 2D vectors are exactly the same, and none are
- * <code>Double.NaN</code>, the two 2D vectors are considered to be equal.
- * </p>
- * <p>
- * <code>NaN</code> coordinates are considered to affect globally the vector
- * and be equals to each other - i.e, if either (or all) coordinates of the
- * 2D vector are equal to <code>Double.NaN</code>, the 2D vector is equal to
- * {@link #NaN}.
- * </p>
- *
- * @param other Object to test for equality to this
- * @return true if two 2D vector objects are equal, false if
- * object is null, not an instance of Vector2D, or
- * not equal to this Vector2D instance
- *
- */
- @Override
- public boolean equals(Object other) {
-
- if (this == other) {
- return true;
- }
-
- if (other instanceof Coordinates2D) {
- final Coordinates2D rhs = (Coordinates2D)other;
- if (rhs.isNaN()) {
- return this.isNaN();
- }
-
- return (x == rhs.x) && (y == rhs.y);
- }
- return false;
- }
-
- /**
- * Get a hashCode for the 2D vector.
- * <p>
- * All NaN values have the same hash code.</p>
- *
- * @return a hash code value for this object
- */
- @Override
- public int hashCode() {
- if (isNaN()) {
- return 542;
- }
- return 122 * (76 * MathUtils.hash(x) + MathUtils.hash(y));
- }
-
- /** Get a string representation of this vector.
- * @return a string representation of this vector
- */
- @Override
- public String toString() {
- return Vector2DFormat.getInstance().format(this);
- }
-
- /** {@inheritDoc} */
- @Override
- public String toString(final NumberFormat format) {
- return new Vector2DFormat(format).format(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java
index 7ac90d4..ba2b7cc 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java
@@ -26,26 +26,26 @@ import org.apache.commons.math4.util.FastMath;
/** Class generating an enclosing ball from its support points.
* @since 3.3
*/
-public class DiskGenerator implements SupportBallGenerator<Euclidean2D, Coordinates2D> {
+public class DiskGenerator implements SupportBallGenerator<Euclidean2D, Cartesian2D> {
/** {@inheritDoc} */
@Override
- public EnclosingBall<Euclidean2D, Coordinates2D> ballOnSupport(final List<Coordinates2D> support) {
+ public EnclosingBall<Euclidean2D, Cartesian2D> ballOnSupport(final List<Cartesian2D> support) {
if (support.size() < 1) {
- return new EnclosingBall<>(Coordinates2D.ZERO, Double.NEGATIVE_INFINITY);
+ return new EnclosingBall<>(Cartesian2D.ZERO, Double.NEGATIVE_INFINITY);
} else {
- final Coordinates2D vA = support.get(0);
+ final Cartesian2D vA = support.get(0);
if (support.size() < 2) {
return new EnclosingBall<>(vA, 0, vA);
} else {
- final Coordinates2D vB = support.get(1);
+ final Cartesian2D vB = support.get(1);
if (support.size() < 3) {
- return new EnclosingBall<>(new Coordinates2D(0.5, vA, 0.5, vB),
+ return new EnclosingBall<>(new Cartesian2D(0.5, vA, 0.5, vB),
0.5 * vA.distance(vB),
vA, vB);
} else {
- final Coordinates2D vC = support.get(2);
+ final Cartesian2D vC = support.get(2);
// a disk is 2D can be defined as:
// (1) (x - x_0)^2 + (y - y_0)^2 = r^2
// which can be written:
@@ -86,7 +86,7 @@ public class DiskGenerator implements SupportBallGenerator<Euclidean2D, Coordina
final BigFraction dx = c2[0].subtract(centerX);
final BigFraction dy = c3[0].subtract(centerY);
final BigFraction r2 = dx.multiply(dx).add(dy.multiply(dy));
- return new EnclosingBall<>(new Coordinates2D(centerX.doubleValue(),
+ return new EnclosingBall<>(new Cartesian2D(centerX.doubleValue(),
centerY.doubleValue()),
FastMath.sqrt(r2.doubleValue()),
vA, vB, vC);