MATH-1554: Remove package "o.a.c.math4.geometry".
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 59dde50..1b4ce81 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -54,6 +54,9 @@
</release>
<release version="4.0" date="XXXX-XX-XX" description="">
+ <action dev="erans" type="update" issue="MATH-1554">
+ Remove package "o.a.c.math4.geometry".
+ </action>
<action dev="erans" type="fix" issue="MATH-1549" due-to="Mohammad Rezaei">
"SimplexTableau": Internally "scale down" the problem definition when the
constraints are defined with large numbers, in order to avoid spurious
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/CardanEulerSingularityException.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/CardanEulerSingularityException.java
deleted file mode 100644
index ad9c33e..0000000
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/CardanEulerSingularityException.java
+++ /dev/null
@@ -1,44 +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.threed;
-
-import org.apache.commons.math4.exception.MathIllegalStateException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-
-/** This class represents exceptions thrown while extractiong Cardan
- * or Euler angles from a rotation.
-
- * @since 1.2
- */
-public class CardanEulerSingularityException
- extends MathIllegalStateException {
-
- /** Serializable version identifier */
- private static final long serialVersionUID = -1360952845582206770L;
-
- /**
- * Simple constructor.
- * build an exception with a default message.
- * @param isCardan if true, the rotation is related to Cardan angles,
- * if false it is related to EulerAngles
- */
- public CardanEulerSingularityException(boolean isCardan) {
- super(isCardan ? LocalizedFormats.CARDAN_ANGLES_SINGULARITY : LocalizedFormats.EULER_ANGLES_SINGULARITY);
- }
-
-}
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java
deleted file mode 100644
index e671acf..0000000
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java
+++ /dev/null
@@ -1,1670 +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.threed;
-
-import java.io.Serializable;
-
-import org.apache.commons.numbers.quaternion.Quaternion;
-import org.apache.commons.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.geometry.euclidean.threed.rotation.QuaternionRotation;
-import org.apache.commons.math4.Field;
-import org.apache.commons.math4.RealFieldElement;
-import org.apache.commons.math4.exception.MathArithmeticException;
-import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
-
-/**
- * Implementation of rotation using {@link RealFieldElement}.
- * <p>Instance of this class are guaranteed to be immutable.</p>
- *
- * @param <T> the type of the field elements
- * @see FieldVector3D
- * @see RotationOrder
- * @since 3.2
- */
-
-public class FieldRotation<T extends RealFieldElement<T>> implements Serializable {
-
- /** Serializable version identifier */
- private static final long serialVersionUID = 20130224l;
-
- /** Scalar coordinate of the quaternion. */
- private final T q0;
-
- /** First coordinate of the vectorial part of the quaternion. */
- private final T q1;
-
- /** Second coordinate of the vectorial part of the quaternion. */
- private final T q2;
-
- /** Third coordinate of the vectorial part of the quaternion. */
- private final T q3;
-
- /** Build a rotation from the quaternion coordinates.
- * <p>A rotation can be built from a <em>normalized</em> quaternion,
- * i.e. a quaternion for which q<sub>0</sub><sup>2</sup> +
- * q<sub>1</sub><sup>2</sup> + q<sub>2</sub><sup>2</sup> +
- * q<sub>3</sub><sup>2</sup> = 1. If the quaternion is not normalized,
- * the constructor can normalize it in a preprocessing step.</p>
- * <p>Note that some conventions put the scalar part of the quaternion
- * as the 4<sup>th</sup> component and the vector part as the first three
- * components. This is <em>not</em> our convention. We put the scalar part
- * as the first component.</p>
- * @param q0 scalar part of the quaternion
- * @param q1 first coordinate of the vectorial part of the quaternion
- * @param q2 second coordinate of the vectorial part of the quaternion
- * @param q3 third coordinate of the vectorial part of the quaternion
- * @param needsNormalization if true, the coordinates are considered
- * not to be normalized, a normalization preprocessing step is performed
- * before using them
- */
- public FieldRotation(final T q0, final T q1, final T q2, final T q3, final boolean needsNormalization) {
-
- if (needsNormalization) {
- // normalization preprocessing
- final T inv =
- q0.multiply(q0).add(q1.multiply(q1)).add(q2.multiply(q2)).add(q3.multiply(q3)).sqrt().reciprocal();
- this.q0 = inv.multiply(q0);
- this.q1 = inv.multiply(q1);
- this.q2 = inv.multiply(q2);
- this.q3 = inv.multiply(q3);
- } else {
- this.q0 = q0;
- this.q1 = q1;
- this.q2 = q2;
- this.q3 = q3;
- }
-
- }
-
- /** Build a rotation from an axis and an angle.
- * <p>We use the convention that angles are oriented according to
- * the effect of the rotation on vectors around the axis. That means
- * that if (i, j, k) is a direct frame and if we first provide +k as
- * the axis and π/2 as the angle to this constructor, and then
- * {@link #applyTo(FieldVector3D) apply} the instance to +i, we will get
- * +j.</p>
- * <p>Another way to represent our convention is to say that a rotation
- * of angle θ about the unit vector (x, y, z) is the same as the
- * rotation build from quaternion components { cos(-θ/2),
- * x * sin(-θ/2), y * sin(-θ/2), z * sin(-θ/2) }.
- * Note the minus sign on the angle!</p>
- * <p>On the one hand this convention is consistent with a vectorial
- * perspective (moving vectors in fixed frames), on the other hand it
- * is different from conventions with a frame perspective (fixed vectors
- * viewed from different frames) like the ones used for example in spacecraft
- * attitude community or in the graphics community.</p>
- * @param axis axis around which to rotate
- * @param angle rotation angle.
- * @exception MathIllegalArgumentException if the axis norm is zero
- * @deprecated as of 3.6, replaced with {@link
- * #FieldRotation(FieldVector3D, RealFieldElement, RotationConvention)}
- */
- @Deprecated
- public FieldRotation(final FieldVector3D<T> axis, final T angle)
- throws MathIllegalArgumentException {
- this(axis, angle, RotationConvention.VECTOR_OPERATOR);
- }
-
- /** Build a rotation from an axis and an angle.
- * <p>We use the convention that angles are oriented according to
- * the effect of the rotation on vectors around the axis. That means
- * that if (i, j, k) is a direct frame and if we first provide +k as
- * the axis and π/2 as the angle to this constructor, and then
- * {@link #applyTo(FieldVector3D) apply} the instance to +i, we will get
- * +j.</p>
- * <p>Another way to represent our convention is to say that a rotation
- * of angle θ about the unit vector (x, y, z) is the same as the
- * rotation build from quaternion components { cos(-θ/2),
- * x * sin(-θ/2), y * sin(-θ/2), z * sin(-θ/2) }.
- * Note the minus sign on the angle!</p>
- * <p>On the one hand this convention is consistent with a vectorial
- * perspective (moving vectors in fixed frames), on the other hand it
- * is different from conventions with a frame perspective (fixed vectors
- * viewed from different frames) like the ones used for example in spacecraft
- * attitude community or in the graphics community.</p>
- * @param axis axis around which to rotate
- * @param angle rotation angle.
- * @param convention convention to use for the semantics of the angle
- * @exception MathIllegalArgumentException if the axis norm is zero
- * @since 3.6
- */
- public FieldRotation(final FieldVector3D<T> axis, final T angle, final RotationConvention convention)
- throws MathIllegalArgumentException {
-
- final T norm = axis.getNorm();
- if (norm.getReal() == 0) {
- throw new MathIllegalArgumentException(LocalizedFormats.ZERO_NORM_FOR_ROTATION_AXIS);
- }
-
- final T halfAngle = angle.multiply(convention == RotationConvention.VECTOR_OPERATOR ? -0.5 : 0.5);
- final T coeff = halfAngle.sin().divide(norm);
-
- q0 = halfAngle.cos();
- q1 = coeff.multiply(axis.getX());
- q2 = coeff.multiply(axis.getY());
- q3 = coeff.multiply(axis.getZ());
-
- }
-
- /** Build a rotation from a 3X3 matrix.
-
- * <p>Rotation matrices are orthogonal matrices, i.e. unit matrices
- * (which are matrices for which m.m<sup>T</sup> = I) with real
- * coefficients. The module of the determinant of unit matrices is
- * 1, among the orthogonal 3X3 matrices, only the ones having a
- * positive determinant (+1) are rotation matrices.</p>
-
- * <p>When a rotation is defined by a matrix with truncated values
- * (typically when it is extracted from a technical sheet where only
- * four to five significant digits are available), the matrix is not
- * orthogonal anymore. This constructor handles this case
- * transparently by using a copy of the given matrix and applying a
- * correction to the copy in order to perfect its orthogonality. If
- * the Frobenius norm of the correction needed is above the given
- * threshold, then the matrix is considered to be too far from a
- * true rotation matrix and an exception is thrown.<p>
-
- * @param m rotation matrix
- * @param threshold convergence threshold for the iterative
- * orthogonality correction (convergence is reached when the
- * difference between two steps of the Frobenius norm of the
- * correction is below this threshold)
-
- * @exception NotARotationMatrixException if the matrix is not a 3X3
- * matrix, or if it cannot be transformed into an orthogonal matrix
- * with the given threshold, or if the determinant of the resulting
- * orthogonal matrix is negative
-
- */
- public FieldRotation(final T[][] m, final double threshold)
- throws NotARotationMatrixException {
-
- // dimension check
- if ((m.length != 3) || (m[0].length != 3) ||
- (m[1].length != 3) || (m[2].length != 3)) {
- throw new NotARotationMatrixException(
- LocalizedFormats.ROTATION_MATRIX_DIMENSIONS,
- m.length, m[0].length);
- }
-
- // compute a "close" orthogonal matrix
- final T[][] ort = orthogonalizeMatrix(m, threshold);
-
- // check the sign of the determinant
- final T d0 = ort[1][1].multiply(ort[2][2]).subtract(ort[2][1].multiply(ort[1][2]));
- final T d1 = ort[0][1].multiply(ort[2][2]).subtract(ort[2][1].multiply(ort[0][2]));
- final T d2 = ort[0][1].multiply(ort[1][2]).subtract(ort[1][1].multiply(ort[0][2]));
- final T det =
- ort[0][0].multiply(d0).subtract(ort[1][0].multiply(d1)).add(ort[2][0].multiply(d2));
- if (det.getReal() < 0.0) {
- throw new NotARotationMatrixException(
- LocalizedFormats.CLOSEST_ORTHOGONAL_MATRIX_HAS_NEGATIVE_DETERMINANT,
- det);
- }
-
- final T[] quat = mat2quat(ort);
- q0 = quat[0];
- q1 = quat[1];
- q2 = quat[2];
- q3 = quat[3];
-
- }
-
- /** Build the rotation that transforms a pair of vectors into another pair.
-
- * <p>Except for possible scale factors, if the instance were applied to
- * the pair (u<sub>1</sub>, u<sub>2</sub>) it will produce the pair
- * (v<sub>1</sub>, v<sub>2</sub>).</p>
-
- * <p>If the angular separation between u<sub>1</sub> and u<sub>2</sub> is
- * not the same as the angular separation between v<sub>1</sub> and
- * v<sub>2</sub>, then a corrected v'<sub>2</sub> will be used rather than
- * v<sub>2</sub>, the corrected vector will be in the (±v<sub>1</sub>,
- * +v<sub>2</sub>) half-plane.</p>
-
- * @param u1 first vector of the origin pair
- * @param u2 second vector of the origin pair
- * @param v1 desired image of u1 by the rotation
- * @param v2 desired image of u2 by the rotation
- * @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 FieldRotation(FieldVector3D<T> u1, FieldVector3D<T> u2, FieldVector3D<T> v1, FieldVector3D<T> 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 FieldVector3D<T> u3 = FieldVector3D.crossProduct(u1, u2).normalize();
- u2 = FieldVector3D.crossProduct(u3, 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 FieldVector3D<T> v3 = FieldVector3D.crossProduct(v1, v2).normalize();
- v2 = FieldVector3D.crossProduct(v3, v1).normalize();
- v1 = v1.normalize();
-
- // buid a matrix transforming the first base into the second one
- final T[][] array = MathArrays.buildArray(u1.getX().getField(), 3, 3);
- array[0][0] = u1.getX().multiply(v1.getX()).add(u2.getX().multiply(v2.getX())).add(u3.getX().multiply(v3.getX()));
- array[0][1] = u1.getY().multiply(v1.getX()).add(u2.getY().multiply(v2.getX())).add(u3.getY().multiply(v3.getX()));
- array[0][2] = u1.getZ().multiply(v1.getX()).add(u2.getZ().multiply(v2.getX())).add(u3.getZ().multiply(v3.getX()));
- array[1][0] = u1.getX().multiply(v1.getY()).add(u2.getX().multiply(v2.getY())).add(u3.getX().multiply(v3.getY()));
- array[1][1] = u1.getY().multiply(v1.getY()).add(u2.getY().multiply(v2.getY())).add(u3.getY().multiply(v3.getY()));
- array[1][2] = u1.getZ().multiply(v1.getY()).add(u2.getZ().multiply(v2.getY())).add(u3.getZ().multiply(v3.getY()));
- array[2][0] = u1.getX().multiply(v1.getZ()).add(u2.getX().multiply(v2.getZ())).add(u3.getX().multiply(v3.getZ()));
- array[2][1] = u1.getY().multiply(v1.getZ()).add(u2.getY().multiply(v2.getZ())).add(u3.getY().multiply(v3.getZ()));
- array[2][2] = u1.getZ().multiply(v1.getZ()).add(u2.getZ().multiply(v2.getZ())).add(u3.getZ().multiply(v3.getZ()));
-
- T[] quat = mat2quat(array);
- q0 = quat[0];
- q1 = quat[1];
- q2 = quat[2];
- q3 = quat[3];
-
- }
-
- /** Build one of the rotations that transform one vector into another one.
-
- * <p>Except for a possible scale factor, if the instance were
- * applied to the vector u it will produce the vector v. There is an
- * infinite number of such rotations, this constructor choose the
- * one with the smallest associated angle (i.e. the one whose axis
- * is orthogonal to the (u, v) plane). If u and v are collinear, an
- * arbitrary rotation axis is chosen.</p>
-
- * @param u origin vector
- * @param v desired image of u by the rotation
- * @exception MathArithmeticException if the norm of one of the vectors is zero
- */
- public FieldRotation(final FieldVector3D<T> u, final FieldVector3D<T> v) throws MathArithmeticException {
-
- final T normProduct = u.getNorm().multiply(v.getNorm());
- if (normProduct.getReal() == 0) {
- throw new MathArithmeticException(LocalizedFormats.ZERO_NORM_FOR_ROTATION_DEFINING_VECTOR);
- }
-
- final T dot = FieldVector3D.dotProduct(u, v);
-
- if (dot.getReal() < ((2.0e-15 - 1.0) * normProduct.getReal())) {
- // special case u = -v: we select a PI angle rotation around
- // an arbitrary vector orthogonal to u
- final FieldVector3D<T> w = u.orthogonal();
- q0 = normProduct.getField().getZero();
- q1 = w.getX().negate();
- q2 = w.getY().negate();
- q3 = w.getZ().negate();
- } else {
- // general case: (u, v) defines a plane, we select
- // the shortest possible rotation: axis orthogonal to this plane
- q0 = dot.divide(normProduct).add(1.0).multiply(0.5).sqrt();
- final T coeff = q0.multiply(normProduct).multiply(2.0).reciprocal();
- final FieldVector3D<T> q = FieldVector3D.crossProduct(v, u);
- q1 = coeff.multiply(q.getX());
- q2 = coeff.multiply(q.getY());
- q3 = coeff.multiply(q.getZ());
- }
-
- }
-
- /** Build a rotation from three Cardan or Euler elementary rotations.
-
- * <p>Cardan rotations are three successive rotations around the
- * canonical axes X, Y and Z, each axis being used once. There are
- * 6 such sets of rotations (XYZ, XZY, YXZ, YZX, ZXY and ZYX). Euler
- * rotations are three successive rotations around the canonical
- * axes X, Y and Z, the first and last rotations being around the
- * same axis. There are 6 such sets of rotations (XYX, XZX, YXY,
- * YZY, ZXZ and ZYZ), the most popular one being ZXZ.</p>
- * <p>Beware that many people routinely use the term Euler angles even
- * for what really are Cardan angles (this confusion is especially
- * widespread in the aerospace business where Roll, Pitch and Yaw angles
- * are often wrongly tagged as Euler angles).</p>
-
- * @param order order of rotations to use
- * @param alpha1 angle of the first elementary rotation
- * @param alpha2 angle of the second elementary rotation
- * @param alpha3 angle of the third elementary rotation
- * @deprecated as of 3.6, replaced with {@link
- * #FieldRotation(RotationOrder, RotationConvention,
- * RealFieldElement, RealFieldElement, RealFieldElement)}
- */
- @Deprecated
- public FieldRotation(final RotationOrder order, final T alpha1, final T alpha2, final T alpha3) {
- this(order, RotationConvention.VECTOR_OPERATOR, alpha1, alpha2, alpha3);
- }
-
- /** Build a rotation from three Cardan or Euler elementary rotations.
-
- * <p>Cardan rotations are three successive rotations around the
- * canonical axes X, Y and Z, each axis being used once. There are
- * 6 such sets of rotations (XYZ, XZY, YXZ, YZX, ZXY and ZYX). Euler
- * rotations are three successive rotations around the canonical
- * axes X, Y and Z, the first and last rotations being around the
- * same axis. There are 6 such sets of rotations (XYX, XZX, YXY,
- * YZY, ZXZ and ZYZ), the most popular one being ZXZ.</p>
- * <p>Beware that many people routinely use the term Euler angles even
- * for what really are Cardan angles (this confusion is especially
- * widespread in the aerospace business where Roll, Pitch and Yaw angles
- * are often wrongly tagged as Euler angles).</p>
-
- * @param order order of rotations to compose, from left to right
- * (i.e. we will use {@code r1.compose(r2.compose(r3, convention), convention)})
- * @param convention convention to use for the semantics of the angle
- * @param alpha1 angle of the first elementary rotation
- * @param alpha2 angle of the second elementary rotation
- * @param alpha3 angle of the third elementary rotation
- * @since 3.6
- */
- public FieldRotation(final RotationOrder order, final RotationConvention convention,
- final T alpha1, final T alpha2, final T alpha3) {
- final T one = alpha1.getField().getOne();
- final FieldRotation<T> r1 = new FieldRotation<>(new FieldVector3D<>(one, order.getA1()), alpha1, convention);
- final FieldRotation<T> r2 = new FieldRotation<>(new FieldVector3D<>(one, order.getA2()), alpha2, convention);
- final FieldRotation<T> r3 = new FieldRotation<>(new FieldVector3D<>(one, order.getA3()), alpha3, convention);
- final FieldRotation<T> composed = r1.compose(r2.compose(r3, convention), convention);
- q0 = composed.q0;
- q1 = composed.q1;
- q2 = composed.q2;
- q3 = composed.q3;
- }
-
- /** Convert an orthogonal rotation matrix to a quaternion.
- * @param ort orthogonal rotation matrix
- * @return quaternion corresponding to the matrix
- */
- private T[] mat2quat(final T[][] ort) {
-
- final T[] quat = MathArrays.buildArray(ort[0][0].getField(), 4);
-
- // There are different ways to compute the quaternions elements
- // from the matrix. They all involve computing one element from
- // the diagonal of the matrix, and computing the three other ones
- // using a formula involving a division by the first element,
- // which unfortunately can be zero. Since the norm of the
- // quaternion is 1, we know at least one element has an absolute
- // value greater or equal to 0.5, so it is always possible to
- // select the right formula and avoid division by zero and even
- // numerical inaccuracy. Checking the elements in turn and using
- // the first one greater than 0.45 is safe (this leads to a simple
- // test since qi = 0.45 implies 4 qi^2 - 1 = -0.19)
- T s = ort[0][0].add(ort[1][1]).add(ort[2][2]);
- if (s.getReal() > -0.19) {
- // compute q0 and deduce q1, q2 and q3
- quat[0] = s.add(1.0).sqrt().multiply(0.5);
- T inv = quat[0].reciprocal().multiply(0.25);
- quat[1] = inv.multiply(ort[1][2].subtract(ort[2][1]));
- quat[2] = inv.multiply(ort[2][0].subtract(ort[0][2]));
- quat[3] = inv.multiply(ort[0][1].subtract(ort[1][0]));
- } else {
- s = ort[0][0].subtract(ort[1][1]).subtract(ort[2][2]);
- if (s.getReal() > -0.19) {
- // compute q1 and deduce q0, q2 and q3
- quat[1] = s.add(1.0).sqrt().multiply(0.5);
- T inv = quat[1].reciprocal().multiply(0.25);
- quat[0] = inv.multiply(ort[1][2].subtract(ort[2][1]));
- quat[2] = inv.multiply(ort[0][1].add(ort[1][0]));
- quat[3] = inv.multiply(ort[0][2].add(ort[2][0]));
- } else {
- s = ort[1][1].subtract(ort[0][0]).subtract(ort[2][2]);
- if (s.getReal() > -0.19) {
- // compute q2 and deduce q0, q1 and q3
- quat[2] = s.add(1.0).sqrt().multiply(0.5);
- T inv = quat[2].reciprocal().multiply(0.25);
- quat[0] = inv.multiply(ort[2][0].subtract(ort[0][2]));
- quat[1] = inv.multiply(ort[0][1].add(ort[1][0]));
- quat[3] = inv.multiply(ort[2][1].add(ort[1][2]));
- } else {
- // compute q3 and deduce q0, q1 and q2
- s = ort[2][2].subtract(ort[0][0]).subtract(ort[1][1]);
- quat[3] = s.add(1.0).sqrt().multiply(0.5);
- T inv = quat[3].reciprocal().multiply(0.25);
- quat[0] = inv.multiply(ort[0][1].subtract(ort[1][0]));
- quat[1] = inv.multiply(ort[0][2].add(ort[2][0]));
- quat[2] = inv.multiply(ort[2][1].add(ort[1][2]));
- }
- }
- }
-
- return quat;
-
- }
-
- /** Revert a rotation.
- * Build a rotation which reverse the effect of another
- * rotation. This means that if r(u) = v, then r.revert(v) = u. The
- * instance is not changed.
- * @return a new rotation whose effect is the reverse of the effect
- * of the instance
- */
- public FieldRotation<T> revert() {
- return new FieldRotation<>(q0.negate(), q1, q2, q3, false);
- }
-
- /** Get the scalar coordinate of the quaternion.
- * @return scalar coordinate of the quaternion
- */
- public T getQ0() {
- return q0;
- }
-
- /** Get the first coordinate of the vectorial part of the quaternion.
- * @return first coordinate of the vectorial part of the quaternion
- */
- public T getQ1() {
- return q1;
- }
-
- /** Get the second coordinate of the vectorial part of the quaternion.
- * @return second coordinate of the vectorial part of the quaternion
- */
- public T getQ2() {
- return q2;
- }
-
- /** Get the third coordinate of the vectorial part of the quaternion.
- * @return third coordinate of the vectorial part of the quaternion
- */
- public T getQ3() {
- return q3;
- }
-
- /** Get the normalized axis of the rotation.
- * @return normalized axis of the rotation
- * @see #FieldRotation(FieldVector3D, RealFieldElement)
- * @deprecated as of 3.6, replaced with {@link #getAxis(RotationConvention)}
- */
- @Deprecated
- public FieldVector3D<T> getAxis() {
- return getAxis(RotationConvention.VECTOR_OPERATOR);
- }
-
- /** Get the normalized axis of the rotation.
- * <p>
- * Note that as {@link #getAngle()} always returns an angle
- * between 0 and π, changing the convention changes the
- * direction of the axis, not the sign of the angle.
- * </p>
- * @param convention convention to use for the semantics of the angle
- * @return normalized axis of the rotation
- * @see #FieldRotation(FieldVector3D, RealFieldElement)
- * @since 3.6
- */
- public FieldVector3D<T> getAxis(final RotationConvention convention) {
- final T squaredSine = q1.multiply(q1).add(q2.multiply(q2)).add(q3.multiply(q3));
- if (squaredSine.getReal() == 0) {
- final Field<T> field = squaredSine.getField();
- return new FieldVector3D<>(convention == RotationConvention.VECTOR_OPERATOR ? field.getOne(): field.getOne().negate(),
- field.getZero(),
- field.getZero());
- } else {
- final double sgn = convention == RotationConvention.VECTOR_OPERATOR ? +1 : -1;
- if (q0.getReal() < 0) {
- T inverse = squaredSine.sqrt().reciprocal().multiply(sgn);
- return new FieldVector3D<>(q1.multiply(inverse), q2.multiply(inverse), q3.multiply(inverse));
- }
- final T inverse = squaredSine.sqrt().reciprocal().negate().multiply(sgn);
- return new FieldVector3D<>(q1.multiply(inverse), q2.multiply(inverse), q3.multiply(inverse));
- }
- }
-
- /** Get the angle of the rotation.
- * @return angle of the rotation (between 0 and π)
- * @see #FieldRotation(FieldVector3D, RealFieldElement)
- */
- public T getAngle() {
- if ((q0.getReal() < -0.1) || (q0.getReal() > 0.1)) {
- return q1.multiply(q1).add(q2.multiply(q2)).add(q3.multiply(q3)).sqrt().asin().multiply(2);
- } else if (q0.getReal() < 0) {
- return q0.negate().acos().multiply(2);
- }
- return q0.acos().multiply(2);
- }
-
- /** Get the Cardan or Euler angles corresponding to the instance.
-
- * <p>The equations show that each rotation can be defined by two
- * different values of the Cardan or Euler angles set. For example
- * if Cardan angles are used, the rotation defined by the angles
- * a<sub>1</sub>, a<sub>2</sub> and a<sub>3</sub> is the same as
- * the rotation defined by the angles π + a<sub>1</sub>, π
- * - a<sub>2</sub> and π + a<sub>3</sub>. This method implements
- * the following arbitrary choices:</p>
- * <ul>
- * <li>for Cardan angles, the chosen set is the one for which the
- * second angle is between -π/2 and π/2 (i.e its cosine is
- * positive),</li>
- * <li>for Euler angles, the chosen set is the one for which the
- * second angle is between 0 and π (i.e its sine is positive).</li>
- * </ul>
-
- * <p>Cardan and Euler angle have a very disappointing drawback: all
- * of them have singularities. This means that if the instance is
- * too close to the singularities corresponding to the given
- * rotation order, it will be impossible to retrieve the angles. For
- * Cardan angles, this is often called gimbal lock. There is
- * <em>nothing</em> to do to prevent this, it is an intrinsic problem
- * with Cardan and Euler representation (but not a problem with the
- * rotation itself, which is perfectly well defined). For Cardan
- * angles, singularities occur when the second angle is close to
- * -π/2 or +π/2, for Euler angle singularities occur when the
- * second angle is close to 0 or π, this implies that the identity
- * rotation is always singular for Euler angles!</p>
-
- * @param order rotation order to use
- * @return an array of three angles, in the order specified by the set
- * @exception CardanEulerSingularityException if the rotation is
- * singular with respect to the angles set specified
- * @deprecated as of 3.6, replaced with {@link #getAngles(RotationOrder, RotationConvention)}
- */
- @Deprecated
- public T[] getAngles(final RotationOrder order)
- throws CardanEulerSingularityException {
- return getAngles(order, RotationConvention.VECTOR_OPERATOR);
- }
-
- /** Get the Cardan or Euler angles corresponding to the instance.
-
- * <p>The equations show that each rotation can be defined by two
- * different values of the Cardan or Euler angles set. For example
- * if Cardan angles are used, the rotation defined by the angles
- * a<sub>1</sub>, a<sub>2</sub> and a<sub>3</sub> is the same as
- * the rotation defined by the angles π + a<sub>1</sub>, π
- * - a<sub>2</sub> and π + a<sub>3</sub>. This method implements
- * the following arbitrary choices:</p>
- * <ul>
- * <li>for Cardan angles, the chosen set is the one for which the
- * second angle is between -π/2 and π/2 (i.e its cosine is
- * positive),</li>
- * <li>for Euler angles, the chosen set is the one for which the
- * second angle is between 0 and π (i.e its sine is positive).</li>
- * </ul>
-
- * <p>Cardan and Euler angle have a very disappointing drawback: all
- * of them have singularities. This means that if the instance is
- * too close to the singularities corresponding to the given
- * rotation order, it will be impossible to retrieve the angles. For
- * Cardan angles, this is often called gimbal lock. There is
- * <em>nothing</em> to do to prevent this, it is an intrinsic problem
- * with Cardan and Euler representation (but not a problem with the
- * rotation itself, which is perfectly well defined). For Cardan
- * angles, singularities occur when the second angle is close to
- * -π/2 or +π/2, for Euler angle singularities occur when the
- * second angle is close to 0 or π, this implies that the identity
- * rotation is always singular for Euler angles!</p>
-
- * @param order rotation order to use
- * @param convention convention to use for the semantics of the angle
- * @return an array of three angles, in the order specified by the set
- * @exception CardanEulerSingularityException if the rotation is
- * singular with respect to the angles set specified
- * @since 3.6
- */
- public T[] getAngles(final RotationOrder order, RotationConvention convention)
- throws CardanEulerSingularityException {
-
- if (convention == RotationConvention.VECTOR_OPERATOR) {
- if (order == RotationOrder.XYZ) {
-
- // r (+K) coordinates are :
- // sin (theta), -cos (theta) sin (phi), cos (theta) cos (phi)
- // (-r) (+I) coordinates are :
- // cos (psi) cos (theta), -sin (psi) cos (theta), sin (theta)
- final // and we can choose to have theta in the interval [-PI/2 ; +PI/2]
- FieldVector3D<T> v1 = applyTo(vector(0, 0, 1));
- final FieldVector3D<T> v2 = applyInverseTo(vector(1, 0, 0));
- if ((v2.getZ().getReal() < -0.9999999999) || (v2.getZ().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v1.getY().negate().atan2(v1.getZ()),
- v2.getZ().asin(),
- v2.getY().negate().atan2(v2.getX()));
-
- } else if (order == RotationOrder.XZY) {
-
- // r (+J) coordinates are :
- // -sin (psi), cos (psi) cos (phi), cos (psi) sin (phi)
- // (-r) (+I) 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]
- final FieldVector3D<T> v1 = applyTo(vector(0, 1, 0));
- final FieldVector3D<T> v2 = applyInverseTo(vector(1, 0, 0));
- if ((v2.getY().getReal() < -0.9999999999) || (v2.getY().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v1.getZ().atan2(v1.getY()),
- v2.getY().asin().negate(),
- v2.getZ().atan2(v2.getX()));
-
- } else if (order == RotationOrder.YXZ) {
-
- // r (+K) coordinates are :
- // cos (phi) sin (theta), -sin (phi), cos (phi) cos (theta)
- // (-r) (+J) 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]
- final FieldVector3D<T> v1 = applyTo(vector(0, 0, 1));
- final FieldVector3D<T> v2 = applyInverseTo(vector(0, 1, 0));
- if ((v2.getZ().getReal() < -0.9999999999) || (v2.getZ().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v1.getX().atan2(v1.getZ()),
- v2.getZ().asin().negate(),
- v2.getX().atan2(v2.getY()));
-
- } else if (order == RotationOrder.YZX) {
-
- // r (+I) coordinates are :
- // cos (psi) cos (theta), sin (psi), -cos (psi) sin (theta)
- // (-r) (+J) 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]
- final FieldVector3D<T> v1 = applyTo(vector(1, 0, 0));
- final FieldVector3D<T> v2 = applyInverseTo(vector(0, 1, 0));
- if ((v2.getX().getReal() < -0.9999999999) || (v2.getX().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v1.getZ().negate().atan2(v1.getX()),
- v2.getX().asin(),
- v2.getZ().negate().atan2(v2.getY()));
-
- } else if (order == RotationOrder.ZXY) {
-
- // r (+J) coordinates are :
- // -cos (phi) sin (psi), cos (phi) cos (psi), sin (phi)
- // (-r) (+K) 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]
- final FieldVector3D<T> v1 = applyTo(vector(0, 1, 0));
- final FieldVector3D<T> v2 = applyInverseTo(vector(0, 0, 1));
- if ((v2.getY().getReal() < -0.9999999999) || (v2.getY().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v1.getX().negate().atan2(v1.getY()),
- v2.getY().asin(),
- v2.getX().negate().atan2(v2.getZ()));
-
- } else if (order == RotationOrder.ZYX) {
-
- // r (+I) coordinates are :
- // cos (theta) cos (psi), cos (theta) sin (psi), -sin (theta)
- // (-r) (+K) 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]
- final FieldVector3D<T> v1 = applyTo(vector(1, 0, 0));
- final FieldVector3D<T> v2 = applyInverseTo(vector(0, 0, 1));
- if ((v2.getX().getReal() < -0.9999999999) || (v2.getX().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v1.getY().atan2(v1.getX()),
- v2.getX().asin().negate(),
- v2.getY().atan2(v2.getZ()));
-
- } else if (order == RotationOrder.XYX) {
-
- // r (+I) coordinates are :
- // cos (theta), sin (phi1) sin (theta), -cos (phi1) sin (theta)
- // (-r) (+I) coordinates are :
- // cos (theta), sin (theta) sin (phi2), sin (theta) cos (phi2)
- // and we can choose to have theta in the interval [0 ; PI]
- final FieldVector3D<T> v1 = applyTo(vector(1, 0, 0));
- final FieldVector3D<T> v2 = applyInverseTo(vector(1, 0, 0));
- if ((v2.getX().getReal() < -0.9999999999) || (v2.getX().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v1.getY().atan2(v1.getZ().negate()),
- v2.getX().acos(),
- v2.getY().atan2(v2.getZ()));
-
- } else if (order == RotationOrder.XZX) {
-
- // r (+I) coordinates are :
- // cos (psi), cos (phi1) sin (psi), sin (phi1) sin (psi)
- // (-r) (+I) coordinates are :
- // cos (psi), -sin (psi) cos (phi2), sin (psi) sin (phi2)
- // and we can choose to have psi in the interval [0 ; PI]
- final FieldVector3D<T> v1 = applyTo(vector(1, 0, 0));
- final FieldVector3D<T> v2 = applyInverseTo(vector(1, 0, 0));
- if ((v2.getX().getReal() < -0.9999999999) || (v2.getX().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v1.getZ().atan2(v1.getY()),
- v2.getX().acos(),
- v2.getZ().atan2(v2.getY().negate()));
-
- } else if (order == RotationOrder.YXY) {
-
- // r (+J) coordinates are :
- // sin (theta1) sin (phi), cos (phi), cos (theta1) sin (phi)
- // (-r) (+J) coordinates are :
- // sin (phi) sin (theta2), cos (phi), -sin (phi) cos (theta2)
- // and we can choose to have phi in the interval [0 ; PI]
- final FieldVector3D<T> v1 = applyTo(vector(0, 1, 0));
- final FieldVector3D<T> v2 = applyInverseTo(vector(0, 1, 0));
- if ((v2.getY().getReal() < -0.9999999999) || (v2.getY().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v1.getX().atan2(v1.getZ()),
- v2.getY().acos(),
- v2.getX().atan2(v2.getZ().negate()));
-
- } else if (order == RotationOrder.YZY) {
-
- // r (+J) coordinates are :
- // -cos (theta1) sin (psi), cos (psi), sin (theta1) sin (psi)
- // (-r) (+J) coordinates are :
- // sin (psi) cos (theta2), cos (psi), sin (psi) sin (theta2)
- // and we can choose to have psi in the interval [0 ; PI]
- final FieldVector3D<T> v1 = applyTo(vector(0, 1, 0));
- final FieldVector3D<T> v2 = applyInverseTo(vector(0, 1, 0));
- if ((v2.getY().getReal() < -0.9999999999) || (v2.getY().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v1.getZ().atan2(v1.getX().negate()),
- v2.getY().acos(),
- v2.getZ().atan2(v2.getX()));
-
- } else if (order == RotationOrder.ZXZ) {
-
- // r (+K) coordinates are :
- // sin (psi1) sin (phi), -cos (psi1) sin (phi), cos (phi)
- // (-r) (+K) coordinates are :
- // sin (phi) sin (psi2), sin (phi) cos (psi2), cos (phi)
- // and we can choose to have phi in the interval [0 ; PI]
- final FieldVector3D<T> v1 = applyTo(vector(0, 0, 1));
- final FieldVector3D<T> v2 = applyInverseTo(vector(0, 0, 1));
- if ((v2.getZ().getReal() < -0.9999999999) || (v2.getZ().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v1.getX().atan2(v1.getY().negate()),
- v2.getZ().acos(),
- v2.getX().atan2(v2.getY()));
-
- } else { // last possibility is ZYZ
-
- // r (+K) coordinates are :
- // cos (psi1) sin (theta), sin (psi1) sin (theta), cos (theta)
- // (-r) (+K) coordinates are :
- // -sin (theta) cos (psi2), sin (theta) sin (psi2), cos (theta)
- // and we can choose to have theta in the interval [0 ; PI]
- final FieldVector3D<T> v1 = applyTo(vector(0, 0, 1));
- final FieldVector3D<T> v2 = applyInverseTo(vector(0, 0, 1));
- if ((v2.getZ().getReal() < -0.9999999999) || (v2.getZ().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v1.getY().atan2(v1.getX()),
- v2.getZ().acos(),
- v2.getY().atan2(v2.getX().negate()));
-
- }
- } else {
- if (order == RotationOrder.XYZ) {
-
- // r (Cartesian3D.plusI) coordinates are :
- // cos (theta) cos (psi), -cos (theta) sin (psi), sin (theta)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_X);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_Z);
- if ((v2.getX().getReal() < -0.9999999999) || (v2.getX().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v2.getY().negate().atan2(v2.getZ()),
- v2.getX().asin(),
- v1.getY().negate().atan2(v1.getX()));
-
- } else if (order == RotationOrder.XZY) {
-
- // r (Cartesian3D.plusI) coordinates are :
- // cos (psi) cos (theta), -sin (psi), cos (psi) sin (theta)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_X);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_Y);
- if ((v2.getX().getReal() < -0.9999999999) || (v2.getX().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v2.getZ().atan2(v2.getY()),
- v2.getX().asin().negate(),
- v1.getZ().atan2(v1.getX()));
-
- } else if (order == RotationOrder.YXZ) {
-
- // r (Cartesian3D.plusJ) coordinates are :
- // cos (phi) sin (psi), cos (phi) cos (psi), -sin (phi)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_Y);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_Z);
- if ((v2.getY().getReal() < -0.9999999999) || (v2.getY().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v2.getX().atan2(v2.getZ()),
- v2.getY().asin().negate(),
- v1.getX().atan2(v1.getY()));
-
- } else if (order == RotationOrder.YZX) {
-
- // r (Cartesian3D.plusJ) coordinates are :
- // sin (psi), cos (psi) cos (phi), -cos (psi) sin (phi)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_Y);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_X);
- if ((v2.getY().getReal() < -0.9999999999) || (v2.getY().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v2.getZ().negate().atan2(v2.getX()),
- v2.getY().asin(),
- v1.getZ().negate().atan2(v1.getY()));
-
- } else if (order == RotationOrder.ZXY) {
-
- // r (Cartesian3D.plusK) coordinates are :
- // -cos (phi) sin (theta), sin (phi), cos (phi) cos (theta)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_Z);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_Y);
- if ((v2.getZ().getReal() < -0.9999999999) || (v2.getZ().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v2.getX().negate().atan2(v2.getY()),
- v2.getZ().asin(),
- v1.getX().negate().atan2(v1.getZ()));
-
- } else if (order == RotationOrder.ZYX) {
-
- // r (Cartesian3D.plusK) coordinates are :
- // -sin (theta), cos (theta) sin (phi), cos (theta) cos (phi)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_Z);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_X);
- if ((v2.getZ().getReal() < -0.9999999999) || (v2.getZ().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(true);
- }
- return buildArray(v2.getY().atan2(v2.getX()),
- v2.getZ().asin().negate(),
- v1.getY().atan2(v1.getZ()));
-
- } else if (order == RotationOrder.XYX) {
-
- // r (Cartesian3D.plusI) coordinates are :
- // cos (theta), sin (phi2) sin (theta), cos (phi2) sin (theta)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_X);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_X);
- if ((v2.getX().getReal() < -0.9999999999) || (v2.getX().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v2.getY().atan2(v2.getZ().negate()),
- v2.getX().acos(),
- v1.getY().atan2(v1.getZ()));
-
- } else if (order == RotationOrder.XZX) {
-
- // r (Cartesian3D.plusI) coordinates are :
- // cos (psi), -cos (phi2) sin (psi), sin (phi2) sin (psi)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_X);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_X);
- if ((v2.getX().getReal() < -0.9999999999) || (v2.getX().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v2.getZ().atan2(v2.getY()),
- v2.getX().acos(),
- v1.getZ().atan2(v1.getY().negate()));
-
- } else if (order == RotationOrder.YXY) {
-
- // r (Cartesian3D.plusJ) coordinates are :
- // sin (phi) sin (theta2), cos (phi), -sin (phi) cos (theta2)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_Y);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_Y);
- if ((v2.getY().getReal() < -0.9999999999) || (v2.getY().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v2.getX().atan2(v2.getZ()),
- v2.getY().acos(),
- v1.getX().atan2(v1.getZ().negate()));
-
- } else if (order == RotationOrder.YZY) {
-
- // r (Cartesian3D.plusJ) coordinates are :
- // sin (psi) cos (theta2), cos (psi), sin (psi) sin (theta2)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_Y);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_Y);
- if ((v2.getY().getReal() < -0.9999999999) || (v2.getY().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v2.getZ().atan2(v2.getX().negate()),
- v2.getY().acos(),
- v1.getZ().atan2(v1.getX()));
-
- } else if (order == RotationOrder.ZXZ) {
-
- // r (Cartesian3D.plusK) coordinates are :
- // sin (phi) sin (psi2), sin (phi) cos (psi2), cos (phi)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_Z);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_Z);
- if ((v2.getZ().getReal() < -0.9999999999) || (v2.getZ().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v2.getX().atan2(v2.getY().negate()),
- v2.getZ().acos(),
- v1.getX().atan2(v1.getY()));
-
- } else { // last possibility is ZYZ
-
- // r (Cartesian3D.plusK) coordinates are :
- // -sin (theta) cos (psi2), sin (theta) sin (psi2), cos (theta)
- // (-r) (Cartesian3D.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]
- FieldVector3D<T> v1 = applyTo(Vector3D.Unit.PLUS_Z);
- FieldVector3D<T> v2 = applyInverseTo(Vector3D.Unit.PLUS_Z);
- if ((v2.getZ().getReal() < -0.9999999999) || (v2.getZ().getReal() > 0.9999999999)) {
- throw new CardanEulerSingularityException(false);
- }
- return buildArray(v2.getY().atan2(v2.getX()),
- v2.getZ().acos(),
- v1.getY().atan2(v1.getX().negate()));
-
- }
- }
-
- }
-
- /** Create a dimension 3 array.
- * @param a0 first array element
- * @param a1 second array element
- * @param a2 third array element
- * @return new array
- */
- private T[] buildArray(final T a0, final T a1, final T a2) {
- final T[] array = MathArrays.buildArray(a0.getField(), 3);
- array[0] = a0;
- array[1] = a1;
- array[2] = a2;
- return array;
- }
-
- /** Create a constant vector.
- * @param x abscissa
- * @param y ordinate
- * @param z height
- * @return a constant vector
- */
- private FieldVector3D<T> vector(final double x, final double y, final double z) {
- final T zero = q0.getField().getZero();
- return new FieldVector3D<>(zero.add(x), zero.add(y), zero.add(z));
- }
-
- /** Get the 3X3 matrix corresponding to the instance
- * @return the matrix corresponding to the instance
- */
- public T[][] getMatrix() {
-
- // products
- final T q0q0 = q0.multiply(q0);
- final T q0q1 = q0.multiply(q1);
- final T q0q2 = q0.multiply(q2);
- final T q0q3 = q0.multiply(q3);
- final T q1q1 = q1.multiply(q1);
- final T q1q2 = q1.multiply(q2);
- final T q1q3 = q1.multiply(q3);
- final T q2q2 = q2.multiply(q2);
- final T q2q3 = q2.multiply(q3);
- final T q3q3 = q3.multiply(q3);
-
- // create the matrix
- final T[][] m = MathArrays.buildArray(q0.getField(), 3, 3);
-
- m [0][0] = q0q0.add(q1q1).multiply(2).subtract(1);
- m [1][0] = q1q2.subtract(q0q3).multiply(2);
- m [2][0] = q1q3.add(q0q2).multiply(2);
-
- m [0][1] = q1q2.add(q0q3).multiply(2);
- m [1][1] = q0q0.add(q2q2).multiply(2).subtract(1);
- m [2][1] = q2q3.subtract(q0q1).multiply(2);
-
- m [0][2] = q1q3.subtract(q0q2).multiply(2);
- m [1][2] = q2q3.add(q0q1).multiply(2);
- m [2][2] = q0q0.add(q3q3).multiply(2).subtract(1);
-
- return m;
-
- }
-
- /** Convert to a constant vector without derivatives.
- * @return a constant vector
- */
- public QuaternionRotation toRotation() {
- return QuaternionRotation.of(q0.getReal(), q1.getReal(), q2.getReal(), q3.getReal());
- }
-
- /** Apply the rotation to a vector.
- * @param u vector to apply the rotation to
- * @return a new vector which is the image of u by the rotation
- */
- public FieldVector3D<T> applyTo(final FieldVector3D<T> u) {
-
- final T x = u.getX();
- final T y = u.getY();
- final T z = u.getZ();
-
- final T s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
-
- return new FieldVector3D<>(q0.multiply(x.multiply(q0).subtract(q2.multiply(z).subtract(q3.multiply(y)))).add(s.multiply(q1)).multiply(2).subtract(x),
- q0.multiply(y.multiply(q0).subtract(q3.multiply(x).subtract(q1.multiply(z)))).add(s.multiply(q2)).multiply(2).subtract(y),
- q0.multiply(z.multiply(q0).subtract(q1.multiply(y).subtract(q2.multiply(x)))).add(s.multiply(q3)).multiply(2).subtract(z));
-
- }
-
- /** Apply the rotation to a vector.
- * @param u vector to apply the rotation to
- * @return a new vector which is the image of u by the rotation
- */
- public FieldVector3D<T> applyTo(final Vector3D u) {
-
- final double x = u.getX();
- final double y = u.getY();
- final double z = u.getZ();
-
- final T s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
-
- return new FieldVector3D<>(q0.multiply(q0.multiply(x).subtract(q2.multiply(z).subtract(q3.multiply(y)))).add(s.multiply(q1)).multiply(2).subtract(x),
- q0.multiply(q0.multiply(y).subtract(q3.multiply(x).subtract(q1.multiply(z)))).add(s.multiply(q2)).multiply(2).subtract(y),
- q0.multiply(q0.multiply(z).subtract(q1.multiply(y).subtract(q2.multiply(x)))).add(s.multiply(q3)).multiply(2).subtract(z));
-
- }
-
- /** Apply the rotation to a vector stored in an array.
- * @param in an array with three items which stores vector to rotate
- * @param out an array with three items to put result to (it can be the same
- * array as in)
- */
- public void applyTo(final T[] in, final T[] out) {
-
- final T x = in[0];
- final T y = in[1];
- final T z = in[2];
-
- final T s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
-
- out[0] = q0.multiply(x.multiply(q0).subtract(q2.multiply(z).subtract(q3.multiply(y)))).add(s.multiply(q1)).multiply(2).subtract(x);
- out[1] = q0.multiply(y.multiply(q0).subtract(q3.multiply(x).subtract(q1.multiply(z)))).add(s.multiply(q2)).multiply(2).subtract(y);
- out[2] = q0.multiply(z.multiply(q0).subtract(q1.multiply(y).subtract(q2.multiply(x)))).add(s.multiply(q3)).multiply(2).subtract(z);
-
- }
-
- /** Apply the rotation to a vector stored in an array.
- * @param in an array with three items which stores vector to rotate
- * @param out an array with three items to put result to
- */
- public void applyTo(final double[] in, final T[] out) {
-
- final double x = in[0];
- final double y = in[1];
- final double z = in[2];
-
- final T s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
-
- out[0] = q0.multiply(q0.multiply(x).subtract(q2.multiply(z).subtract(q3.multiply(y)))).add(s.multiply(q1)).multiply(2).subtract(x);
- out[1] = q0.multiply(q0.multiply(y).subtract(q3.multiply(x).subtract(q1.multiply(z)))).add(s.multiply(q2)).multiply(2).subtract(y);
- out[2] = q0.multiply(q0.multiply(z).subtract(q1.multiply(y).subtract(q2.multiply(x)))).add(s.multiply(q3)).multiply(2).subtract(z);
-
- }
-
- /** Apply a rotation to a vector.
- * @param rot rotation to apply
- * @param u vector to apply the rotation to
- * @param <T> the type of the field elements
- * @return a new vector which is the image of u by the rotation
- */
- public static <T extends RealFieldElement<T>> FieldVector3D<T> applyTo(final QuaternionRotation rot, final FieldVector3D<T> u) {
- final Quaternion r = rot.getQuaternion();
- final T x = u.getX();
- final T y = u.getY();
- final T z = u.getZ();
-
- final T s = x.multiply(r.getX()).add(y.multiply(r.getY())).add(z.multiply(r.getZ()));
-
- return new FieldVector3D<>(x.multiply(r.getW()).subtract(z.multiply(r.getY()).subtract(y.multiply(r.getZ()))).multiply(r.getW()).add(s.multiply(r.getX())).multiply(2).subtract(x),
- y.multiply(r.getW()).subtract(x.multiply(r.getZ()).subtract(z.multiply(r.getX()))).multiply(r.getW()).add(s.multiply(r.getY())).multiply(2).subtract(y),
- z.multiply(r.getW()).subtract(y.multiply(r.getX()).subtract(x.multiply(r.getY()))).multiply(r.getW()).add(s.multiply(r.getZ())).multiply(2).subtract(z));
-
- }
-
- /** Apply the inverse of the rotation to a vector.
- * @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 FieldVector3D<T> applyInverseTo(final FieldVector3D<T> u) {
-
- final T x = u.getX();
- final T y = u.getY();
- final T z = u.getZ();
-
- final T s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
- final T m0 = q0.negate();
-
- return new FieldVector3D<>(m0.multiply(x.multiply(m0).subtract(q2.multiply(z).subtract(q3.multiply(y)))).add(s.multiply(q1)).multiply(2).subtract(x),
- m0.multiply(y.multiply(m0).subtract(q3.multiply(x).subtract(q1.multiply(z)))).add(s.multiply(q2)).multiply(2).subtract(y),
- m0.multiply(z.multiply(m0).subtract(q1.multiply(y).subtract(q2.multiply(x)))).add(s.multiply(q3)).multiply(2).subtract(z));
-
- }
-
- /** Apply the inverse of the rotation to a vector.
- * @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 FieldVector3D<T> applyInverseTo(final Vector3D u) {
-
- final double x = u.getX();
- final double y = u.getY();
- final double z = u.getZ();
-
- final T s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
- final T m0 = q0.negate();
-
- return new FieldVector3D<>(m0.multiply(m0.multiply(x).subtract(q2.multiply(z).subtract(q3.multiply(y)))).add(s.multiply(q1)).multiply(2).subtract(x),
- m0.multiply(m0.multiply(y).subtract(q3.multiply(x).subtract(q1.multiply(z)))).add(s.multiply(q2)).multiply(2).subtract(y),
- m0.multiply(m0.multiply(z).subtract(q1.multiply(y).subtract(q2.multiply(x)))).add(s.multiply(q3)).multiply(2).subtract(z));
-
- }
-
- /** Apply the inverse of the rotation to a vector stored in an array.
- * @param in an array with three items which stores vector to rotate
- * @param out an array with three items to put result to (it can be the same
- * array as in)
- */
- public void applyInverseTo(final T[] in, final T[] out) {
-
- final T x = in[0];
- final T y = in[1];
- final T z = in[2];
-
- final T s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
- final T m0 = q0.negate();
-
- out[0] = m0.multiply(x.multiply(m0).subtract(q2.multiply(z).subtract(q3.multiply(y)))).add(s.multiply(q1)).multiply(2).subtract(x);
- out[1] = m0.multiply(y.multiply(m0).subtract(q3.multiply(x).subtract(q1.multiply(z)))).add(s.multiply(q2)).multiply(2).subtract(y);
- out[2] = m0.multiply(z.multiply(m0).subtract(q1.multiply(y).subtract(q2.multiply(x)))).add(s.multiply(q3)).multiply(2).subtract(z);
-
- }
-
- /** Apply the inverse of the rotation to a vector stored in an array.
- * @param in an array with three items which stores vector to rotate
- * @param out an array with three items to put result to
- */
- public void applyInverseTo(final double[] in, final T[] out) {
-
- final double x = in[0];
- final double y = in[1];
- final double z = in[2];
-
- final T s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
- final T m0 = q0.negate();
-
- out[0] = m0.multiply(m0.multiply(x).subtract(q2.multiply(z).subtract(q3.multiply(y)))).add(s.multiply(q1)).multiply(2).subtract(x);
- out[1] = m0.multiply(m0.multiply(y).subtract(q3.multiply(x).subtract(q1.multiply(z)))).add(s.multiply(q2)).multiply(2).subtract(y);
- out[2] = m0.multiply(m0.multiply(z).subtract(q1.multiply(y).subtract(q2.multiply(x)))).add(s.multiply(q3)).multiply(2).subtract(z);
-
- }
-
- /** Apply the inverse of a rotation to a vector.
- * @param rot rotation to apply
- * @param u vector to apply the inverse of the rotation to
- * @param <T> the type of the field elements
- * @return a new vector which such that u is its image by the rotation
- */
- public static <T extends RealFieldElement<T>> FieldVector3D<T> applyInverseTo(final QuaternionRotation rot, final FieldVector3D<T> u) {
- final Quaternion r = rot.getQuaternion();
- final T x = u.getX();
- final T y = u.getY();
- final T z = u.getZ();
-
- final T s = x.multiply(r.getX()).add(y.multiply(r.getY())).add(z.multiply(r.getZ()));
- final double m0 = -r.getW();
-
- return new FieldVector3D<>(x.multiply(m0).subtract(z.multiply(r.getY()).subtract(y.multiply(r.getZ()))).multiply(m0).add(s.multiply(r.getX())).multiply(2).subtract(x),
- y.multiply(m0).subtract(x.multiply(r.getZ()).subtract(z.multiply(r.getX()))).multiply(m0).add(s.multiply(r.getY())).multiply(2).subtract(y),
- z.multiply(m0).subtract(y.multiply(r.getX()).subtract(x.multiply(r.getY()))).multiply(m0).add(s.multiply(r.getZ())).multiply(2).subtract(z));
-
- }
-
- /** Apply the instance to another rotation.
- * <p>
- * Calling this method is equivalent to call
- * {@link #compose(FieldRotation, RotationConvention)
- * compose(r, RotationConvention.VECTOR_OPERATOR)}.
- * </p>
- * @param r rotation to apply the rotation to
- * @return a new rotation which is the composition of r by the instance
- */
- public FieldRotation<T> applyTo(final FieldRotation<T> r) {
- return compose(r, RotationConvention.VECTOR_OPERATOR);
- }
-
- /** Compose the instance with another rotation.
- * <p>
- * If the semantics of the rotations composition corresponds to a
- * {@link RotationConvention#VECTOR_OPERATOR vector operator} convention,
- * applying the instance to a rotation is computing the composition
- * in an order compliant with the following rule : let {@code u} be any
- * vector and {@code v} its image by {@code r1} (i.e.
- * {@code r1.applyTo(u) = v}). Let {@code w} be the image of {@code v} by
- * rotation {@code r2} (i.e. {@code r2.applyTo(v) = w}). Then
- * {@code w = comp.applyTo(u)}, where
- * {@code comp = r2.compose(r1, RotationConvention.VECTOR_OPERATOR)}.
- * </p>
- * <p>
- * If the semantics of the rotations composition corresponds to a
- * {@link RotationConvention#FRAME_TRANSFORM frame transform} convention,
- * the application order will be reversed. So keeping the exact same
- * meaning of all {@code r1}, {@code r2}, {@code u}, {@code v}, {@code w}
- * and {@code comp} as above, {@code comp} could also be computed as
- * {@code comp = r1.compose(r2, RotationConvention.FRAME_TRANSFORM)}.
- * </p>
- * @param r rotation to apply the rotation to
- * @param convention convention to use for the semantics of the angle
- * @return a new rotation which is the composition of r by the instance
- */
- public FieldRotation<T> compose(final FieldRotation<T> r, final RotationConvention convention) {
- return convention == RotationConvention.VECTOR_OPERATOR ?
- composeInternal(r) : r.composeInternal(this);
- }
-
- /** Compose the instance with another rotation using vector operator convention.
- * @param r rotation to apply the rotation to
- * @return a new rotation which is the composition of r by the instance
- * using vector operator convention
- */
- private FieldRotation<T> composeInternal(final FieldRotation<T> r) {
- return new FieldRotation<>(r.q0.multiply(q0).subtract(r.q1.multiply(q1).add(r.q2.multiply(q2)).add(r.q3.multiply(q3))),
- r.q1.multiply(q0).add(r.q0.multiply(q1)).add(r.q2.multiply(q3).subtract(r.q3.multiply(q2))),
- r.q2.multiply(q0).add(r.q0.multiply(q2)).add(r.q3.multiply(q1).subtract(r.q1.multiply(q3))),
- r.q3.multiply(q0).add(r.q0.multiply(q3)).add(r.q1.multiply(q2).subtract(r.q2.multiply(q1))),
- false);
- }
-
- /** Apply the instance to another rotation.
- * <p>
- * Calling this method is equivalent to call
- * {@link #compose(QuaternionRotation, RotationConvention)
- * compose(r, RotationConvention.VECTOR_OPERATOR)}.
- * </p>
- * @param r rotation to apply the rotation to
- * @return a new rotation which is the composition of r by the instance
- */
- public FieldRotation<T> applyTo(final QuaternionRotation r) {
- return compose(r, RotationConvention.VECTOR_OPERATOR);
- }
-
- /** Compose the instance with another rotation.
- * <p>
- * If the semantics of the rotations composition corresponds to a
- * {@link RotationConvention#VECTOR_OPERATOR vector operator} convention,
- * applying the instance to a rotation is computing the composition
- * in an order compliant with the following rule : let {@code u} be any
- * vector and {@code v} its image by {@code r1} (i.e.
- * {@code r1.applyTo(u) = v}). Let {@code w} be the image of {@code v} by
- * rotation {@code r2} (i.e. {@code r2.applyTo(v) = w}). Then
- * {@code w = comp.applyTo(u)}, where
- * {@code comp = r2.compose(r1, RotationConvention.VECTOR_OPERATOR)}.
- * </p>
- * <p>
- * If the semantics of the rotations composition corresponds to a
- * {@link RotationConvention#FRAME_TRANSFORM frame transform} convention,
- * the application order will be reversed. So keeping the exact same
- * meaning of all {@code r1}, {@code r2}, {@code u}, {@code v}, {@code w}
- * and {@code comp} as above, {@code comp} could also be computed as
- * {@code comp = r1.compose(r2, RotationConvention.FRAME_TRANSFORM)}.
- * </p>
- * @param r rotation to apply the rotation to
- * @param convention convention to use for the semantics of the angle
- * @return a new rotation which is the composition of r by the instance
- */
- public FieldRotation<T> compose(final QuaternionRotation r, final RotationConvention convention) {
- return convention == RotationConvention.VECTOR_OPERATOR ?
- composeInternal(r) : applyTo(r, this);
- }
-
- /** Compose the instance with another rotation using vector operator convention.
- * @param rot rotation to apply the rotation to
- * @return a new rotation which is the composition of r by the instance
- * using vector operator convention
- */
- private FieldRotation<T> composeInternal(final QuaternionRotation rot) {
- final Quaternion r = rot.getQuaternion();
- return new FieldRotation<>(q0.multiply(r.getW()).subtract(q1.multiply(r.getX()).add(q2.multiply(r.getY())).add(q3.multiply(r.getZ()))),
- q0.multiply(r.getX()).add(q1.multiply(r.getW())).add(q3.multiply(r.getY()).subtract(q2.multiply(r.getZ()))),
- q0.multiply(r.getY()).add(q2.multiply(r.getW())).add(q1.multiply(r.getZ()).subtract(q3.multiply(r.getX()))),
- q0.multiply(r.getZ()).add(q3.multiply(r.getW())).add(q2.multiply(r.getX()).subtract(q1.multiply(r.getY()))),
- false);
- }
-
- /** Apply a rotation to another rotation.
- * Applying a rotation to another rotation is computing the composition
- * in an order compliant with the following rule : let u be any
- * vector and v its image by rInner (i.e. rInner.applyTo(u) = v), let w be the image
- * of v by rOuter (i.e. rOuter.applyTo(v) = w), then w = comp.applyTo(u),
- * where comp = applyTo(rOuter, rInner).
- * @param rot1 rotation to apply
- * @param rInner rotation to apply the rotation to
- * @param <T> the type of the field elements
- * @return a new rotation which is the composition of r by the instance
- */
- public static <T extends RealFieldElement<T>> FieldRotation<T> applyTo(final QuaternionRotation rot1, final FieldRotation<T> rInner) {
- final Quaternion r1 = rot1.getQuaternion();
- return new FieldRotation<>(rInner.q0.multiply(r1.getW()).subtract(rInner.q1.multiply(r1.getX()).add(rInner.q2.multiply(r1.getY())).add(rInner.q3.multiply(r1.getZ()))),
- rInner.q1.multiply(r1.getW()).add(rInner.q0.multiply(r1.getX())).add(rInner.q2.multiply(r1.getZ()).subtract(rInner.q3.multiply(r1.getY()))),
- rInner.q2.multiply(r1.getW()).add(rInner.q0.multiply(r1.getY())).add(rInner.q3.multiply(r1.getX()).subtract(rInner.q1.multiply(r1.getZ()))),
- rInner.q3.multiply(r1.getW()).add(rInner.q0.multiply(r1.getZ())).add(rInner.q1.multiply(r1.getY()).subtract(rInner.q2.multiply(r1.getX()))),
- false);
- }
-
- /** Apply the inverse of the instance to another rotation.
- * <p>
- * Calling this method is equivalent to call
- * {@link #composeInverse(FieldRotation, RotationConvention)
- * composeInverse(r, RotationConvention.VECTOR_OPERATOR)}.
- * </p>
- * @param r rotation to apply the rotation to
- * @return a new rotation which is the composition of r by the inverse
- * of the instance
- */
- public FieldRotation<T> applyInverseTo(final FieldRotation<T> r) {
- return composeInverse(r, RotationConvention.VECTOR_OPERATOR);
- }
-
- /** Compose the inverse of the instance with another rotation.
- * <p>
- * If the semantics of the rotations composition corresponds to a
- * {@link RotationConvention#VECTOR_OPERATOR vector operator} convention,
- * applying the inverse of the instance to a rotation is computing
- * the composition in an order compliant with the following rule :
- * let {@code u} be any vector and {@code v} its image by {@code r1}
- * (i.e. {@code r1.applyTo(u) = v}). Let {@code w} be the inverse image
- * of {@code v} by {@code r2} (i.e. {@code r2.applyInverseTo(v) = w}).
- * Then {@code w = comp.applyTo(u)}, where
- * {@code comp = r2.composeInverse(r1)}.
- * </p>
- * <p>
- * If the semantics of the rotations composition corresponds to a
- * {@link RotationConvention#FRAME_TRANSFORM frame transform} convention,
- * the application order will be reversed, which means it is the
- * <em>innermost</em> rotation that will be reversed. So keeping the exact same
- * meaning of all {@code r1}, {@code r2}, {@code u}, {@code v}, {@code w}
- * and {@code comp} as above, {@code comp} could also be computed as
- * {@code comp = r1.revert().composeInverse(r2.revert(), RotationConvention.FRAME_TRANSFORM)}.
- * </p>
- * @param r rotation to apply the rotation to
- * @param convention convention to use for the semantics of the angle
- * @return a new rotation which is the composition of r by the inverse
- * of the instance
- */
- public FieldRotation<T> composeInverse(final FieldRotation<T> r, final RotationConvention convention) {
- return convention == RotationConvention.VECTOR_OPERATOR ?
- composeInverseInternal(r) : r.composeInternal(revert());
- }
-
- /** Compose the inverse of the instance with another rotation
- * using vector operator convention.
- * @param r rotation to apply the rotation to
- * @return a new rotation which is the composition of r by the inverse
- * of the instance using vector operator convention
- */
- private FieldRotation<T> composeInverseInternal(FieldRotation<T> r) {
- return new FieldRotation<>(r.q0.multiply(q0).add(r.q1.multiply(q1).add(r.q2.multiply(q2)).add(r.q3.multiply(q3))).negate(),
- r.q0.multiply(q1).add(r.q2.multiply(q3).subtract(r.q3.multiply(q2))).subtract(r.q1.multiply(q0)),
- r.q0.multiply(q2).add(r.q3.multiply(q1).subtract(r.q1.multiply(q3))).subtract(r.q2.multiply(q0)),
- r.q0.multiply(q3).add(r.q1.multiply(q2).subtract(r.q2.multiply(q1))).subtract(r.q3.multiply(q0)),
- false);
- }
-
- /** Apply the inverse of the instance to another rotation.
- * <p>
- * Calling this method is equivalent to call
- * {@link #composeInverse(QuaternionRotation, RotationConvention)
- * composeInverse(r, RotationConvention.VECTOR_OPERATOR)}.
- * </p>
- * @param r rotation to apply the rotation to
- * @return a new rotation which is the composition of r by the inverse
- * of the instance
- */
- public FieldRotation<T> applyInverseTo(final QuaternionRotation r) {
- return composeInverse(r, RotationConvention.VECTOR_OPERATOR);
- }
-
- /** Compose the inverse of the instance with another rotation.
- * <p>
- * If the semantics of the rotations composition corresponds to a
- * {@link RotationConvention#VECTOR_OPERATOR vector operator} convention,
- * applying the inverse of the instance to a rotation is computing
- * the composition in an order compliant with the following rule :
- * let {@code u} be any vector and {@code v} its image by {@code r1}
- * (i.e. {@code r1.applyTo(u) = v}). Let {@code w} be the inverse image
- * of {@code v} by {@code r2} (i.e. {@code r2.applyInverseTo(v) = w}).
- * Then {@code w = comp.applyTo(u)}, where
- * {@code comp = r2.composeInverse(r1)}.
- * </p>
- * <p>
- * If the semantics of the rotations composition corresponds to a
- * {@link RotationConvention#FRAME_TRANSFORM frame transform} convention,
- * the application order will be reversed, which means it is the
- * <em>innermost</em> rotation that will be reversed. So keeping the exact same
- * meaning of all {@code r1}, {@code r2}, {@code u}, {@code v}, {@code w}
- * and {@code comp} as above, {@code comp} could also be computed as
- * {@code comp = r1.revert().composeInverse(r2.revert(), RotationConvention.FRAME_TRANSFORM)}.
- * </p>
- * @param r rotation to apply the rotation to
- * @param convention convention to use for the semantics of the angle
- * @return a new rotation which is the composition of r by the inverse
- * of the instance
- */
- public FieldRotation<T> composeInverse(final QuaternionRotation r, final RotationConvention convention) {
- return convention == RotationConvention.VECTOR_OPERATOR ?
- composeInverseInternal(r) : applyTo(r, revert());
- }
-
- /** Compose the inverse of the instance with another rotation
- * using vector operator convention.
- * @param rot rotation to apply the rotation to
- * @return a new rotation which is the composition of r by the inverse
- * of the instance using vector operator convention
- */
- private FieldRotation<T> composeInverseInternal(QuaternionRotation rot) {
- final Quaternion r = rot.getQuaternion();
- return new FieldRotation<>(q0.multiply(r.getW()).add(q1.multiply(r.getX()).add(q2.multiply(r.getY())).add(q3.multiply(r.getZ()))).negate(),
- q1.multiply(r.getW()).add(q3.multiply(r.getY()).subtract(q2.multiply(r.getZ()))).subtract(q0.multiply(r.getX())),
- q2.multiply(r.getW()).add(q1.multiply(r.getZ()).subtract(q3.multiply(r.getX()))).subtract(q0.multiply(r.getY())),
- q3.multiply(r.getW()).add(q2.multiply(r.getX()).subtract(q1.multiply(r.getY()))).subtract(q0.multiply(r.getZ())),
- false);
- }
-
- /** Apply the inverse of a rotation to another rotation.
- * Applying the inverse of a rotation to another rotation is computing
- * the composition in an order compliant with the following rule :
- * let u be any vector and v its image by rInner (i.e. rInner.applyTo(u) = v),
- * let w be the inverse image of v by rOuter
- * (i.e. rOuter.applyInverseTo(v) = w), then w = comp.applyTo(u), where
- * comp = applyInverseTo(rOuter, rInner).
- * @param rotOuter rotation to apply the rotation to
- * @param rInner rotation to apply the rotation to
- * @param <T> the type of the field elements
- * @return a new rotation which is the composition of r by the inverse
- * of the instance
- */
- public static <T extends RealFieldElement<T>> FieldRotation<T> applyInverseTo(final QuaternionRotation rotOuter, final FieldRotation<T> rInner) {
- final Quaternion rOuter = rotOuter.getQuaternion();
- return new FieldRotation<>(rInner.q0.multiply(rOuter.getW()).add(rInner.q1.multiply(rOuter.getX()).add(rInner.q2.multiply(rOuter.getY())).add(rInner.q3.multiply(rOuter.getZ()))).negate(),
- rInner.q0.multiply(rOuter.getX()).add(rInner.q2.multiply(rOuter.getZ()).subtract(rInner.q3.multiply(rOuter.getY()))).subtract(rInner.q1.multiply(rOuter.getW())),
- rInner.q0.multiply(rOuter.getY()).add(rInner.q3.multiply(rOuter.getX()).subtract(rInner.q1.multiply(rOuter.getZ()))).subtract(rInner.q2.multiply(rOuter.getW())),
- rInner.q0.multiply(rOuter.getZ()).add(rInner.q1.multiply(rOuter.getY()).subtract(rInner.q2.multiply(rOuter.getX()))).subtract(rInner.q3.multiply(rOuter.getW())),
- false);
- }
-
- /** Perfect orthogonality on a 3X3 matrix.
- * @param m initial matrix (not exactly orthogonal)
- * @param threshold convergence threshold for the iterative
- * orthogonality correction (convergence is reached when the
- * difference between two steps of the Frobenius norm of the
- * correction is below this threshold)
- * @return an orthogonal matrix close to m
- * @exception NotARotationMatrixException if the matrix cannot be
- * orthogonalized with the given threshold after 10 iterations
- */
- private T[][] orthogonalizeMatrix(final T[][] m, final double threshold)
- throws NotARotationMatrixException {
-
- T x00 = m[0][0];
- T x01 = m[0][1];
- T x02 = m[0][2];
- T x10 = m[1][0];
- T x11 = m[1][1];
- T x12 = m[1][2];
- T x20 = m[2][0];
- T x21 = m[2][1];
- T x22 = m[2][2];
- double fn = 0;
- double fn1;
-
- final T[][] o = MathArrays.buildArray(m[0][0].getField(), 3, 3);
-
- // iterative correction: Xn+1 = Xn - 0.5 * (Xn.Mt.Xn - M)
- int i = 0;
- while (++i < 11) {
-
- // Mt.Xn
- final T mx00 = m[0][0].multiply(x00).add(m[1][0].multiply(x10)).add(m[2][0].multiply(x20));
- final T mx10 = m[0][1].multiply(x00).add(m[1][1].multiply(x10)).add(m[2][1].multiply(x20));
- final T mx20 = m[0][2].multiply(x00).add(m[1][2].multiply(x10)).add(m[2][2].multiply(x20));
- final T mx01 = m[0][0].multiply(x01).add(m[1][0].multiply(x11)).add(m[2][0].multiply(x21));
- final T mx11 = m[0][1].multiply(x01).add(m[1][1].multiply(x11)).add(m[2][1].multiply(x21));
- final T mx21 = m[0][2].multiply(x01).add(m[1][2].multiply(x11)).add(m[2][2].multiply(x21));
- final T mx02 = m[0][0].multiply(x02).add(m[1][0].multiply(x12)).add(m[2][0].multiply(x22));
- final T mx12 = m[0][1].multiply(x02).add(m[1][1].multiply(x12)).add(m[2][1].multiply(x22));
- final T mx22 = m[0][2].multiply(x02).add(m[1][2].multiply(x12)).add(m[2][2].multiply(x22));
-
- // Xn+1
- o[0][0] = x00.subtract(x00.multiply(mx00).add(x01.multiply(mx10)).add(x02.multiply(mx20)).subtract(m[0][0]).multiply(0.5));
- o[0][1] = x01.subtract(x00.multiply(mx01).add(x01.multiply(mx11)).add(x02.multiply(mx21)).subtract(m[0][1]).multiply(0.5));
- o[0][2] = x02.subtract(x00.multiply(mx02).add(x01.multiply(mx12)).add(x02.multiply(mx22)).subtract(m[0][2]).multiply(0.5));
- o[1][0] = x10.subtract(x10.multiply(mx00).add(x11.multiply(mx10)).add(x12.multiply(mx20)).subtract(m[1][0]).multiply(0.5));
- o[1][1] = x11.subtract(x10.multiply(mx01).add(x11.multiply(mx11)).add(x12.multiply(mx21)).subtract(m[1][1]).multiply(0.5));
- o[1][2] = x12.subtract(x10.multiply(mx02).add(x11.multiply(mx12)).add(x12.multiply(mx22)).subtract(m[1][2]).multiply(0.5));
- o[2][0] = x20.subtract(x20.multiply(mx00).add(x21.multiply(mx10)).add(x22.multiply(mx20)).subtract(m[2][0]).multiply(0.5));
- o[2][1] = x21.subtract(x20.multiply(mx01).add(x21.multiply(mx11)).add(x22.multiply(mx21)).subtract(m[2][1]).multiply(0.5));
- o[2][2] = x22.subtract(x20.multiply(mx02).add(x21.multiply(mx12)).add(x22.multiply(mx22)).subtract(m[2][2]).multiply(0.5));
-
- // correction on each elements
- final double corr00 = o[0][0].getReal() - m[0][0].getReal();
- final double corr01 = o[0][1].getReal() - m[0][1].getReal();
- final double corr02 = o[0][2].getReal() - m[0][2].getReal();
- final double corr10 = o[1][0].getReal() - m[1][0].getReal();
- final double corr11 = o[1][1].getReal() - m[1][1].getReal();
- final double corr12 = o[1][2].getReal() - m[1][2].getReal();
- final double corr20 = o[2][0].getReal() - m[2][0].getReal();
- final double corr21 = o[2][1].getReal() - m[2][1].getReal();
- final double corr22 = o[2][2].getReal() - m[2][2].getReal();
-
- // Frobenius norm of the correction
- fn1 = corr00 * corr00 + corr01 * corr01 + corr02 * corr02 +
- corr10 * corr10 + corr11 * corr11 + corr12 * corr12 +
- corr20 * corr20 + corr21 * corr21 + corr22 * corr22;
-
- // convergence test
- if (FastMath.abs(fn1 - fn) <= threshold) {
- return o;
- }
-
- // prepare next iteration
- x00 = o[0][0];
- x01 = o[0][1];
- x02 = o[0][2];
- x10 = o[1][0];
- x11 = o[1][1];
- x12 = o[1][2];
- x20 = o[2][0];
- x21 = o[2][1];
- x22 = o[2][2];
- fn = fn1;
-
- }
-
- // the algorithm did not converge after 10 iterations
- throw new NotARotationMatrixException(LocalizedFormats.UNABLE_TO_ORTHOGONOLIZE_MATRIX,
- i - 1);
-
- }
-
- /** Compute the <i>distance</i> between two rotations.
- * <p>The <i>distance</i> is intended here as a way to check if two
- * rotations are almost similar (i.e. they transform vectors the same way)
- * or very different. It is mathematically defined as the angle of
- * the rotation r that prepended to one of the rotations gives the other
- * one:</p>
- * <div style="white-space: pre"><code>
- * r<sub>1</sub>(r) = r<sub>2</sub>
- * </code></div>
- * <p>This distance is an angle between 0 and π. Its value is the smallest
- * possible upper bound of the angle in radians between r<sub>1</sub>(v)
- * and r<sub>2</sub>(v) for all possible vectors v. This upper bound is
- * reached for some v. The distance is equal to 0 if and only if the two
- * rotations are identical.</p>
- * <p>Comparing two rotations should always be done using this value rather
- * than for example comparing the components of the quaternions. It is much
- * more stable, and has a geometric meaning. Also comparing quaternions
- * components is error prone since for example quaternions (0.36, 0.48, -0.48, -0.64)
- * and (-0.36, -0.48, 0.48, 0.64) represent exactly the same rotation despite
- * their components are different (they are exact opposites).</p>
- * @param r1 first rotation
- * @param r2 second rotation
- * @param <T> the type of the field elements
- * @return <i>distance</i> between r1 and r2
- */
- public static <T extends RealFieldElement<T>> T distance(final FieldRotation<T> r1, final FieldRotation<T> r2) {
- return r1.composeInverseInternal(r2).getAngle();
- }
-
-}
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java
deleted file mode 100644
index 5942ef5..0000000
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java
+++ /dev/null
@@ -1,1176 +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.threed;
-
-import java.io.Serializable;
-
-import org.apache.commons.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.math4.RealFieldElement;
-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.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
-
-/**
- * This class is a re-implementation of {@link Vector3D} using {@link RealFieldElement}.
- * <p>Instance of this class are guaranteed to be immutable.</p>
- * @param <T> the type of the field elements
- * @since 3.2
- */
-public class FieldVector3D<T extends RealFieldElement<T>> implements Serializable {
-
- /** Serializable version identifier. */
- private static final long serialVersionUID = 20130224L;
-
- /** Abscissa. */
- private final T x;
-
- /** Ordinate. */
- private final T y;
-
- /** Height. */
- private final T z;
-
- /** Simple constructor.
- * Build a vector from its coordinates
- * @param x abscissa
- * @param y ordinate
- * @param z height
- * @see #getX()
- * @see #getY()
- * @see #getZ()
- */
- public FieldVector3D(final T x, final T y, final T z) {
- this.x = x;
- this.y = y;
- this.z = z;
- }
-
- /** Simple constructor.
- * Build a vector from its coordinates
- * @param v coordinates array
- * @exception DimensionMismatchException if array does not have 3 elements
- * @see #toArray()
- */
- public FieldVector3D(final T[] v) throws DimensionMismatchException {
- if (v.length != 3) {
- throw new DimensionMismatchException(v.length, 3);
- }
- this.x = v[0];
- this.y = v[1];
- this.z = v[2];
- }
-
- /** Simple constructor.
- * Build a vector from its azimuthal coordinates
- * @param alpha azimuth (α) around Z
- * (0 is +X, π/2 is +Y, π is -X and 3π/2 is -Y)
- * @param delta elevation (δ) above (XY) plane, from -π/2 to +π/2
- * @see #getAlpha()
- * @see #getDelta()
- */
- public FieldVector3D(final T alpha, final T delta) {
- T cosDelta = delta.cos();
- this.x = alpha.cos().multiply(cosDelta);
- this.y = alpha.sin().multiply(cosDelta);
- this.z = delta.sin();
- }
-
- /** 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 FieldVector3D(final T a, final FieldVector3D<T>u) {
- this.x = a.multiply(u.x);
- this.y = a.multiply(u.y);
- this.z = a.multiply(u.z);
- }
-
- /** 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 FieldVector3D(final T a, final Vector3D u) {
- this.x = a.multiply(u.getX());
- this.y = a.multiply(u.getY());
- this.z = a.multiply(u.getZ());
- }
-
- /** 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 FieldVector3D(final double a, final FieldVector3D<T> u) {
- this.x = u.x.multiply(a);
- this.y = u.y.multiply(a);
- this.z = u.z.multiply(a);
- }
-
- /** 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 FieldVector3D(final T a1, final FieldVector3D<T> u1,
- final T a2, final FieldVector3D<T> u2) {
- final T prototype = a1;
- this.x = prototype.linearCombination(a1, u1.getX(), a2, u2.getX());
- this.y = prototype.linearCombination(a1, u1.getY(), a2, u2.getY());
- this.z = prototype.linearCombination(a1, u1.getZ(), a2, u2.getZ());
- }
-
- /** 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 FieldVector3D(final T a1, final Vector3D u1,
- final T a2, final Vector3D u2) {
- final T prototype = a1;
- this.x = prototype.linearCombination(u1.getX(), a1, u2.getX(), a2);
- this.y = prototype.linearCombination(u1.getY(), a1, u2.getY(), a2);
- this.z = prototype.linearCombination(u1.getZ(), a1, u2.getZ(), a2);
- }
-
- /** 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 FieldVector3D(final double a1, final FieldVector3D<T> u1,
- final double a2, final FieldVector3D<T> u2) {
- final T prototype = u1.getX();
- this.x = prototype.linearCombination(a1, u1.getX(), a2, u2.getX());
- this.y = prototype.linearCombination(a1, u1.getY(), a2, u2.getY());
- this.z = prototype.linearCombination(a1, u1.getZ(), a2, u2.getZ());
- }
-
- /** 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 FieldVector3D(final T a1, final FieldVector3D<T> u1,
- final T a2, final FieldVector3D<T> u2,
- final T a3, final FieldVector3D<T> u3) {
- final T prototype = a1;
- this.x = prototype.linearCombination(a1, u1.getX(), a2, u2.getX(), a3, u3.getX());
- this.y = prototype.linearCombination(a1, u1.getY(), a2, u2.getY(), a3, u3.getY());
- this.z = prototype.linearCombination(a1, u1.getZ(), a2, u2.getZ(), a3, u3.getZ());
- }
-
- /** 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 FieldVector3D(final T a1, final Vector3D u1,
- final T a2, final Vector3D u2,
- final T a3, final Vector3D u3) {
- final T prototype = a1;
- this.x = prototype.linearCombination(u1.getX(), a1, u2.getX(), a2, u3.getX(), a3);
- this.y = prototype.linearCombination(u1.getY(), a1, u2.getY(), a2, u3.getY(), a3);
- this.z = prototype.linearCombination(u1.getZ(), a1, u2.getZ(), a2, u3.getZ(), a3);
- }
-
- /** 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 FieldVector3D(final double a1, final FieldVector3D<T> u1,
- final double a2, final FieldVector3D<T> u2,
- final double a3, final FieldVector3D<T> u3) {
- final T prototype = u1.getX();
- this.x = prototype.linearCombination(a1, u1.getX(), a2, u2.getX(), a3, u3.getX());
- this.y = prototype.linearCombination(a1, u1.getY(), a2, u2.getY(), a3, u3.getY());
- this.z = prototype.linearCombination(a1, u1.getZ(), a2, u2.getZ(), a3, u3.getZ());
- }
-
- /** 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 FieldVector3D(final T a1, final FieldVector3D<T> u1,
- final T a2, final FieldVector3D<T> u2,
- final T a3, final FieldVector3D<T> u3,
- final T a4, final FieldVector3D<T> u4) {
- final T prototype = a1;
- this.x = prototype.linearCombination(a1, u1.getX(), a2, u2.getX(), a3, u3.getX(), a4, u4.getX());
- this.y = prototype.linearCombination(a1, u1.getY(), a2, u2.getY(), a3, u3.getY(), a4, u4.getY());
- this.z = prototype.linearCombination(a1, u1.getZ(), a2, u2.getZ(), a3, u3.getZ(), a4, u4.getZ());
- }
-
- /** 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 FieldVector3D(final T a1, final Vector3D u1,
- final T a2, final Vector3D u2,
- final T a3, final Vector3D u3,
- final T a4, final Vector3D u4) {
- final T prototype = a1;
- this.x = prototype.linearCombination(u1.getX(), a1, u2.getX(), a2, u3.getX(), a3, u4.getX(), a4);
- this.y = prototype.linearCombination(u1.getY(), a1, u2.getY(), a2, u3.getY(), a3, u4.getY(), a4);
- this.z = prototype.linearCombination(u1.getZ(), a1, u2.getZ(), a2, u3.getZ(), a3, u4.getZ(), a4);
- }
-
- /** 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 FieldVector3D(final double a1, final FieldVector3D<T> u1,
- final double a2, final FieldVector3D<T> u2,
- final double a3, final FieldVector3D<T> u3,
- final double a4, final FieldVector3D<T> u4) {
- final T prototype = u1.getX();
- this.x = prototype.linearCombination(a1, u1.getX(), a2, u2.getX(), a3, u3.getX(), a4, u4.getX());
- this.y = prototype.linearCombination(a1, u1.getY(), a2, u2.getY(), a3, u3.getY(), a4, u4.getY());
- this.z = prototype.linearCombination(a1, u1.getZ(), a2, u2.getZ(), a3, u3.getZ(), a4, u4.getZ());
- }
-
- /** Get the abscissa of the vector.
- * @return abscissa of the vector
- * @see #FieldVector3D(RealFieldElement, RealFieldElement, RealFieldElement)
- */
- public T getX() {
- return x;
- }
-
- /** Get the ordinate of the vector.
- * @return ordinate of the vector
- * @see #FieldVector3D(RealFieldElement, RealFieldElement, RealFieldElement)
- */
- public T getY() {
- return y;
- }
-
- /** Get the height of the vector.
- * @return height of the vector
- * @see #FieldVector3D(RealFieldElement, RealFieldElement, RealFieldElement)
- */
- public T getZ() {
- return z;
- }
-
- /** Get the vector coordinates as a dimension 3 array.
- * @return vector coordinates
- * @see #FieldVector3D(RealFieldElement[])
- */
- public T[] toArray() {
- final T[] array = MathArrays.buildArray(x.getField(), 3);
- array[0] = x;
- array[1] = y;
- array[2] = z;
- return array;
- }
-
- /** Convert to a constant vector without derivatives.
- * @return a constant vector
- */
- public Vector3D toVector3D() {
- return Vector3D.of(x.getReal(), y.getReal(), z.getReal());
- }
-
- /** Get the L<sub>1</sub> norm for the vector.
- * @return L<sub>1</sub> norm for the vector
- */
- public T getNorm1() {
- return x.abs().add(y.abs()).add(z.abs());
- }
-
- /** Get the L<sub>2</sub> norm for the vector.
- * @return Euclidean norm for the vector
- */
- public T getNorm() {
- // there are no cancellation problems here, so we use the straightforward formula
- return x.multiply(x).add(y.multiply(y)).add(z.multiply(z)).sqrt();
- }
-
- /** Get the square of the norm for the vector.
- * @return square of the Euclidean norm for the vector
- */
- public T getNormSq() {
- // there are no cancellation problems here, so we use the straightforward formula
- return x.multiply(x).add(y.multiply(y)).add(z.multiply(z));
- }
-
- /** Get the L<sub>∞</sub> norm for the vector.
- * @return L<sub>∞</sub> norm for the vector
- */
- public T getNormInf() {
- final T xAbs = x.abs();
- final T yAbs = y.abs();
- final T zAbs = z.abs();
- if (xAbs.getReal() <= yAbs.getReal()) {
- if (yAbs.getReal() <= zAbs.getReal()) {
- return zAbs;
- } else {
- return yAbs;
- }
- } else {
- if (xAbs.getReal() <= zAbs.getReal()) {
- return zAbs;
- } else {
- return xAbs;
- }
- }
- }
-
- /** Get the azimuth of the vector.
- * @return azimuth (α) of the vector, between -π and +π
- * @see #FieldVector3D(RealFieldElement, RealFieldElement)
- */
- public T getAlpha() {
- return y.atan2(x);
- }
-
- /** Get the elevation of the vector.
- * @return elevation (δ) of the vector, between -π/2 and +π/2
- * @see #FieldVector3D(RealFieldElement, RealFieldElement)
- */
- public T getDelta() {
- return z.divide(getNorm()).asin();
- }
-
- /** Add a vector to the instance.
- * @param v vector to add
- * @return a new vector
- */
- public FieldVector3D<T> add(final FieldVector3D<T> v) {
- return new FieldVector3D<>(x.add(v.x), y.add(v.y), z.add(v.z));
- }
-
- /** Add a vector to the instance.
- * @param v vector to add
- * @return a new vector
- */
- public FieldVector3D<T> add(final Vector3D v) {
- return new FieldVector3D<>(x.add(v.getX()), y.add(v.getY()), z.add(v.getZ()));
- }
-
- /** Add a scaled vector to the instance.
- * @param factor scale factor to apply to v before adding it
- * @param v vector to add
- * @return a new vector
- */
- public FieldVector3D<T> add(final T factor, final FieldVector3D<T> v) {
- return new FieldVector3D<>(x.getField().getOne(), this, factor, v);
- }
-
- /** Add a scaled vector to the instance.
- * @param factor scale factor to apply to v before adding it
- * @param v vector to add
- * @return a new vector
- */
- public FieldVector3D<T> add(final T factor, final Vector3D v) {
- return new FieldVector3D<>(x.add(factor.multiply(v.getX())),
- y.add(factor.multiply(v.getY())),
- z.add(factor.multiply(v.getZ())));
- }
-
- /** Add a scaled vector to the instance.
- * @param factor scale factor to apply to v before adding it
- * @param v vector to add
- * @return a new vector
- */
- public FieldVector3D<T> add(final double factor, final FieldVector3D<T> v) {
- return new FieldVector3D<>(1.0, this, factor, v);
- }
-
- /** Add a scaled vector to the instance.
- * @param factor scale factor to apply to v before adding it
- * @param v vector to add
- * @return a new vector
- */
- public FieldVector3D<T> add(final double factor, final Vector3D v) {
- return new FieldVector3D<>(x.add(factor * v.getX()),
- y.add(factor * v.getY()),
- z.add(factor * v.getZ()));
- }
-
- /** Subtract a vector from the instance.
- * @param v vector to subtract
- * @return a new vector
- */
- public FieldVector3D<T> subtract(final FieldVector3D<T> v) {
- return new FieldVector3D<>(x.subtract(v.x), y.subtract(v.y), z.subtract(v.z));
- }
-
- /** Subtract a vector from the instance.
- * @param v vector to subtract
- * @return a new vector
- */
- public FieldVector3D<T> subtract(final Vector3D v) {
- return new FieldVector3D<>(x.subtract(v.getX()), y.subtract(v.getY()), z.subtract(v.getZ()));
- }
-
- /** Subtract a scaled vector from the instance.
- * @param factor scale factor to apply to v before subtracting it
- * @param v vector to subtract
- * @return a new vector
- */
- public FieldVector3D<T> subtract(final T factor, final FieldVector3D<T> v) {
- return new FieldVector3D<>(x.getField().getOne(), this, factor.negate(), v);
- }
-
- /** Subtract a scaled vector from the instance.
- * @param factor scale factor to apply to v before subtracting it
- * @param v vector to subtract
- * @return a new vector
- */
- public FieldVector3D<T> subtract(final T factor, final Vector3D v) {
- return new FieldVector3D<>(x.subtract(factor.multiply(v.getX())),
- y.subtract(factor.multiply(v.getY())),
- z.subtract(factor.multiply(v.getZ())));
- }
-
- /** Subtract a scaled vector from the instance.
- * @param factor scale factor to apply to v before subtracting it
- * @param v vector to subtract
- * @return a new vector
- */
- public FieldVector3D<T> subtract(final double factor, final FieldVector3D<T> v) {
- return new FieldVector3D<>(1.0, this, -factor, v);
- }
-
- /** Subtract a scaled vector from the instance.
- * @param factor scale factor to apply to v before subtracting it
- * @param v vector to subtract
- * @return a new vector
- */
- public FieldVector3D<T> subtract(final double factor, final Vector3D v) {
- return new FieldVector3D<>(x.subtract(factor * v.getX()),
- y.subtract(factor * v.getY()),
- z.subtract(factor * v.getZ()));
- }
-
- /** Get a normalized vector aligned with the instance.
- * @return a new normalized vector
- * @exception MathArithmeticException if the norm is zero
- */
- public FieldVector3D<T> normalize() throws MathArithmeticException {
- final T s = getNorm();
- if (s.getReal() == 0) {
- throw new MathArithmeticException(LocalizedFormats.CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR);
- }
- return scalarMultiply(s.reciprocal());
- }
-
- /** Get a vector orthogonal to the instance.
- * <p>There are an infinite number of normalized vectors orthogonal
- * to the instance. This method picks up one of them almost
- * arbitrarily. It is useful when one needs to compute a reference
- * frame with one of the axes in a predefined direction. The
- * following example shows how to build a frame having the k axis
- * aligned with the known vector u :
- * <pre><code>
- * Vector3D k = u.normalize();
- * Vector3D i = k.orthogonal();
- * Vector3D j = Vector3D.crossProduct(k, i);
- * </code></pre>
- * @return a new normalized vector orthogonal to the instance
- * @exception MathArithmeticException if the norm of the instance is null
- */
- public FieldVector3D<T> orthogonal() throws MathArithmeticException {
-
- final double threshold = 0.6 * getNorm().getReal();
- if (threshold == 0) {
- throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
- }
-
- if (FastMath.abs(x.getReal()) <= threshold) {
- final T inverse = y.multiply(y).add(z.multiply(z)).sqrt().reciprocal();
- return new FieldVector3D<>(inverse.getField().getZero(), inverse.multiply(z), inverse.multiply(y).negate());
- } else if (FastMath.abs(y.getReal()) <= threshold) {
- final T inverse = x.multiply(x).add(z.multiply(z)).sqrt().reciprocal();
- return new FieldVector3D<>(inverse.multiply(z).negate(), inverse.getField().getZero(), inverse.multiply(x));
- } else {
- final T inverse = x.multiply(x).add(y.multiply(y)).sqrt().reciprocal();
- return new FieldVector3D<>(inverse.multiply(y), inverse.multiply(x).negate(), inverse.getField().getZero());
- }
-
- }
-
- /** 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
- * @param <T> the type of the field elements
- * @return angular separation between v1 and v2
- * @exception MathArithmeticException if either vector has a null norm
- */
- public static <T extends RealFieldElement<T>> T angle(final FieldVector3D<T> v1, final FieldVector3D<T> v2)
- throws MathArithmeticException {
-
- final T normProduct = v1.getNorm().multiply(v2.getNorm());
- if (normProduct.getReal() == 0) {
- throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
- }
-
- final T dot = dotProduct(v1, v2);
- final double threshold = normProduct.getReal() * 0.9999;
- if ((dot.getReal() < -threshold) || (dot.getReal() > threshold)) {
- // the vectors are almost aligned, compute using the sine
- FieldVector3D<T> v3 = crossProduct(v1, v2);
- if (dot.getReal() >= 0) {
- return v3.getNorm().divide(normProduct).asin();
- }
- return v3.getNorm().divide(normProduct).asin().subtract(FastMath.PI).negate();
- }
-
- // the vectors are sufficiently separated to use the cosine
- return dot.divide(normProduct).acos();
-
- }
-
- /** 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
- * @param <T> the type of the field elements
- * @return angular separation between v1 and v2
- * @exception MathArithmeticException if either vector has a null norm
- */
- public static <T extends RealFieldElement<T>> T angle(final FieldVector3D<T> v1, final Vector3D v2)
- throws MathArithmeticException {
-
- final T normProduct = v1.getNorm().multiply(v2.norm());
- if (normProduct.getReal() == 0) {
- throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
- }
-
- final T dot = dotProduct(v1, v2);
- final double threshold = normProduct.getReal() * 0.9999;
- if ((dot.getReal() < -threshold) || (dot.getReal() > threshold)) {
- // the vectors are almost aligned, compute using the sine
- FieldVector3D<T> v3 = crossProduct(v1, v2);
- if (dot.getReal() >= 0) {
- return v3.getNorm().divide(normProduct).asin();
- }
- return v3.getNorm().divide(normProduct).asin().subtract(FastMath.PI).negate();
- }
-
- // the vectors are sufficiently separated to use the cosine
- return dot.divide(normProduct).acos();
-
- }
-
- /** 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
- * @param <T> the type of the field elements
- * @return angular separation between v1 and v2
- * @exception MathArithmeticException if either vector has a null norm
- */
- public static <T extends RealFieldElement<T>> T angle(final Vector3D v1, final FieldVector3D<T> v2)
- throws MathArithmeticException {
- return angle(v2, v1);
- }
-
- /** Get the opposite of the instance.
- * @return a new vector which is opposite to the instance
- */
- public FieldVector3D<T> negate() {
- return new FieldVector3D<>(x.negate(), y.negate(), z.negate());
- }
-
- /** Multiply the instance by a scalar.
- * @param a scalar
- * @return a new vector
- */
- public FieldVector3D<T> scalarMultiply(final T a) {
- return new FieldVector3D<>(x.multiply(a), y.multiply(a), z.multiply(a));
- }
-
- /** Multiply the instance by a scalar.
- * @param a scalar
- * @return a new vector
- */
- public FieldVector3D<T> scalarMultiply(final double a) {
- return new FieldVector3D<>(x.multiply(a), y.multiply(a), z.multiply(a));
- }
-
- /**
- * Returns true if any coordinate of this vector is NaN; false otherwise
- * @return true if any coordinate of this vector is NaN; false otherwise
- */
- public boolean isNaN() {
- return Double.isNaN(x.getReal()) || Double.isNaN(y.getReal()) || Double.isNaN(z.getReal());
- }
-
- /**
- * Returns true if any coordinate of this vector is infinite and none are NaN;
- * false otherwise
- * @return true if any coordinate of this vector is infinite and none are NaN;
- * false otherwise
- */
- public boolean isInfinite() {
- return !isNaN() && (Double.isInfinite(x.getReal()) || Double.isInfinite(y.getReal()) || Double.isInfinite(z.getReal()));
- }
-
- /**
- * Test for the equality of two 3D vectors.
- * <p>
- * If all coordinates of two 3D vectors are exactly the same, and none of their
- * {@link RealFieldElement#getReal() real part} are <code>NaN</code>, the
- * two 3D 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) real part of the
- * coordinates of the 3D vector are <code>NaN</code>, the 3D vector is <code>NaN</code>.
- * </p>
- *
- * @param other Object to test for equality to this
- * @return true if two 3D vector objects are equal, false if
- * object is null, not an instance of FieldVector3D, or
- * not equal to this FieldVector3D instance
- *
- */
- @Override
- public boolean equals(Object other) {
-
- if (this == other) {
- return true;
- }
-
- if (other instanceof FieldVector3D) {
- @SuppressWarnings("unchecked")
- final FieldVector3D<T> rhs = (FieldVector3D<T>) other;
- if (rhs.isNaN()) {
- return this.isNaN();
- }
-
- return x.equals(rhs.x) && y.equals(rhs.y) && z.equals(rhs.z);
-
- }
- return false;
- }
-
- /**
- * Get a hashCode for the 3D 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 409;
- }
- return 311 * (107 * x.hashCode() + 83 * y.hashCode() + z.hashCode());
- }
-
- /** Compute the dot-product of the instance and another vector.
- * <p>
- * The implementation uses specific multiplication and addition
- * algorithms to preserve accuracy and reduce cancellation effects.
- * It should be very accurate even for nearly orthogonal vectors.
- * </p>
- *
- * @param v second vector
- * @return the dot product this.v
- */
- public T dotProduct(final FieldVector3D<T> v) {
- return x.linearCombination(x, v.x, y, v.y, z, v.z);
- }
-
- /** Compute the dot-product of the instance and another vector.
- * <p>
- * The implementation uses specific multiplication and addition
- * algorithms to preserve accuracy and reduce cancellation effects.
- * It should be very accurate even for nearly orthogonal vectors.
- * </p>
- *
- * @param v second vector
- * @return the dot product this.v
- */
- public T dotProduct(final Vector3D v) {
- return x.linearCombination(v.getX(), x, v.getY(), y, v.getZ(), z);
- }
-
- /** Compute the cross-product of the instance with another vector.
- * @param v other vector
- * @return the cross product this ^ v as a new FieldVector3D
- */
- public FieldVector3D<T> crossProduct(final FieldVector3D<T> v) {
- return new FieldVector3D<>(x.linearCombination(y, v.z, z.negate(), v.y),
- y.linearCombination(z, v.x, x.negate(), v.z),
- z.linearCombination(x, v.y, y.negate(), v.x));
- }
-
- /** Compute the cross-product of the instance with another vector.
- * @param v other vector
- * @return the cross product this ^ v as a new FieldVector3D
- */
- public FieldVector3D<T> crossProduct(final Vector3D v) {
- return new FieldVector3D<>(x.linearCombination(v.getZ(), y, -v.getY(), z),
- y.linearCombination(v.getX(), z, -v.getZ(), x),
- z.linearCombination(v.getY(), x, -v.getX(), y));
- }
-
- /** Compute the distance between the instance and another vector according to the L<sub>1</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>q.subtract(p).getNorm1()</code> except that no intermediate
- * vector is built</p>
- * @param v second vector
- * @return the distance between the instance and p according to the L<sub>1</sub> norm
- */
- public T distance1(final FieldVector3D<T> v) {
- final T dx = v.x.subtract(x).abs();
- final T dy = v.y.subtract(y).abs();
- final T dz = v.z.subtract(z).abs();
- return dx.add(dy).add(dz);
- }
-
- /** Compute the distance between the instance and another vector according to the L<sub>1</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>q.subtract(p).getNorm1()</code> except that no intermediate
- * vector is built</p>
- * @param v second vector
- * @return the distance between the instance and p according to the L<sub>1</sub> norm
- */
- public T distance1(final Vector3D v) {
- final T dx = x.subtract(v.getX()).abs();
- final T dy = y.subtract(v.getY()).abs();
- final T dz = z.subtract(v.getZ()).abs();
- return dx.add(dy).add(dz);
- }
-
- /** Compute the distance between the instance and another vector according to the L<sub>2</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>q.subtract(p).getNorm()</code> except that no intermediate
- * vector is built</p>
- * @param v second vector
- * @return the distance between the instance and p according to the L<sub>2</sub> norm
- */
- public T distance(final FieldVector3D<T> v) {
- final T dx = v.x.subtract(x);
- final T dy = v.y.subtract(y);
- final T dz = v.z.subtract(z);
- return dx.multiply(dx).add(dy.multiply(dy)).add(dz.multiply(dz)).sqrt();
- }
-
- /** Compute the distance between the instance and another vector according to the L<sub>2</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>q.subtract(p).getNorm()</code> except that no intermediate
- * vector is built</p>
- * @param v second vector
- * @return the distance between the instance and p according to the L<sub>2</sub> norm
- */
- public T distance(final Vector3D v) {
- final T dx = x.subtract(v.getX());
- final T dy = y.subtract(v.getY());
- final T dz = z.subtract(v.getZ());
- return dx.multiply(dx).add(dy.multiply(dy)).add(dz.multiply(dz)).sqrt();
- }
-
- /** Compute the distance between the instance and another vector according to the L<sub>∞</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>q.subtract(p).getNormInf()</code> except that no intermediate
- * vector is built</p>
- * @param v second vector
- * @return the distance between the instance and p according to the L<sub>∞</sub> norm
- */
- public T distanceInf(final FieldVector3D<T> v) {
- final T dx = v.x.subtract(x).abs();
- final T dy = v.y.subtract(y).abs();
- final T dz = v.z.subtract(z).abs();
- if (dx.getReal() <= dy.getReal()) {
- if (dy.getReal() <= dz.getReal()) {
- return dz;
- } else {
- return dy;
- }
- } else {
- if (dx.getReal() <= dz.getReal()) {
- return dz;
- } else {
- return dx;
- }
- }
- }
-
- /** Compute the distance between the instance and another vector according to the L<sub>∞</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>q.subtract(p).getNormInf()</code> except that no intermediate
- * vector is built</p>
- * @param v second vector
- * @return the distance between the instance and p according to the L<sub>∞</sub> norm
- */
- public T distanceInf(final Vector3D v) {
- final T dx = x.subtract(v.getX()).abs();
- final T dy = y.subtract(v.getY()).abs();
- final T dz = z.subtract(v.getZ()).abs();
- if (dx.getReal() <= dy.getReal()) {
- if (dy.getReal() <= dz.getReal()) {
- return dz;
- } else {
- return dy;
- }
- } else {
- if (dx.getReal() <= dz.getReal()) {
- return dz;
- } else {
- return dx;
- }
- }
- }
-
- /** Compute the square of the distance between the instance and another vector.
- * <p>Calling this method is equivalent to calling:
- * <code>q.subtract(p).getNormSq()</code> except that no intermediate
- * vector is built</p>
- * @param v second vector
- * @return the square of the distance between the instance and p
- */
- public T distanceSq(final FieldVector3D<T> v) {
- final T dx = v.x.subtract(x);
- final T dy = v.y.subtract(y);
- final T dz = v.z.subtract(z);
- return dx.multiply(dx).add(dy.multiply(dy)).add(dz.multiply(dz));
- }
-
- /** Compute the square of the distance between the instance and another vector.
- * <p>Calling this method is equivalent to calling:
- * <code>q.subtract(p).getNormSq()</code> except that no intermediate
- * vector is built</p>
- * @param v second vector
- * @return the square of the distance between the instance and p
- */
- public T distanceSq(final Vector3D v) {
- final T dx = x.subtract(v.getX());
- final T dy = y.subtract(v.getY());
- final T dz = z.subtract(v.getZ());
- return dx.multiply(dx).add(dy.multiply(dy)).add(dz.multiply(dz));
- }
-
- /** Compute the dot-product of two vectors.
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the dot product v1.v2
- */
- public static <T extends RealFieldElement<T>> T dotProduct(final FieldVector3D<T> v1,
- final FieldVector3D<T> v2) {
- return v1.dotProduct(v2);
- }
-
- /** Compute the dot-product of two vectors.
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the dot product v1.v2
- */
- public static <T extends RealFieldElement<T>> T dotProduct(final FieldVector3D<T> v1,
- final Vector3D v2) {
- return v1.dotProduct(v2);
- }
-
- /** Compute the dot-product of two vectors.
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the dot product v1.v2
- */
- public static <T extends RealFieldElement<T>> T dotProduct(final Vector3D v1,
- final FieldVector3D<T> v2) {
- return v2.dotProduct(v1);
- }
-
- /** Compute the cross-product of two vectors.
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the cross product v1 ^ v2 as a new Vector
- */
- public static <T extends RealFieldElement<T>> FieldVector3D<T> crossProduct(final FieldVector3D<T> v1,
- final FieldVector3D<T> v2) {
- return v1.crossProduct(v2);
- }
-
- /** Compute the cross-product of two vectors.
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the cross product v1 ^ v2 as a new Vector
- */
- public static <T extends RealFieldElement<T>> FieldVector3D<T> crossProduct(final FieldVector3D<T> v1,
- final Vector3D v2) {
- return v1.crossProduct(v2);
- }
-
- /** Compute the cross-product of two vectors.
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the cross product v1 ^ v2 as a new Vector
- */
- public static <T extends RealFieldElement<T>> FieldVector3D<T> crossProduct(final Vector3D v1,
- final FieldVector3D<T> v2) {
- return new FieldVector3D<>(v2.x.linearCombination(v1.getY(), v2.z, -v1.getZ(), v2.y),
- v2.y.linearCombination(v1.getZ(), v2.x, -v1.getX(), v2.z),
- v2.z.linearCombination(v1.getX(), v2.y, -v1.getY(), v2.x));
- }
-
- /** Compute the distance between two vectors according to the L<sub>1</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNorm1()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the distance between v1 and v2 according to the L<sub>1</sub> norm
- */
- public static <T extends RealFieldElement<T>> T distance1(final FieldVector3D<T> v1,
- final FieldVector3D<T> v2) {
- return v1.distance1(v2);
- }
-
- /** Compute the distance between two vectors according to the L<sub>1</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNorm1()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the distance between v1 and v2 according to the L<sub>1</sub> norm
- */
- public static <T extends RealFieldElement<T>> T distance1(final FieldVector3D<T> v1,
- final Vector3D v2) {
- return v1.distance1(v2);
- }
-
- /** Compute the distance between two vectors according to the L<sub>1</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNorm1()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the distance between v1 and v2 according to the L<sub>1</sub> norm
- */
- public static <T extends RealFieldElement<T>> T distance1(final Vector3D v1,
- final FieldVector3D<T> v2) {
- return v2.distance1(v1);
- }
-
- /** Compute the distance between two vectors according to the L<sub>2</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNorm()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the distance between v1 and v2 according to the L<sub>2</sub> norm
- */
- public static <T extends RealFieldElement<T>> T distance(final FieldVector3D<T> v1,
- final FieldVector3D<T> v2) {
- return v1.distance(v2);
- }
-
- /** Compute the distance between two vectors according to the L<sub>2</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNorm()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the distance between v1 and v2 according to the L<sub>2</sub> norm
- */
- public static <T extends RealFieldElement<T>> T distance(final FieldVector3D<T> v1,
- final Vector3D v2) {
- return v1.distance(v2);
- }
-
- /** Compute the distance between two vectors according to the L<sub>2</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNorm()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the distance between v1 and v2 according to the L<sub>2</sub> norm
- */
- public static <T extends RealFieldElement<T>> T distance(final Vector3D v1,
- final FieldVector3D<T> v2) {
- return v2.distance(v1);
- }
-
- /** Compute the distance between two vectors according to the L<sub>∞</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNormInf()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the distance between v1 and v2 according to the L<sub>∞</sub> norm
- */
- public static <T extends RealFieldElement<T>> T distanceInf(final FieldVector3D<T> v1,
- final FieldVector3D<T> v2) {
- return v1.distanceInf(v2);
- }
-
- /** Compute the distance between two vectors according to the L<sub>∞</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNormInf()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the distance between v1 and v2 according to the L<sub>∞</sub> norm
- */
- public static <T extends RealFieldElement<T>> T distanceInf(final FieldVector3D<T> v1,
- final Vector3D v2) {
- return v1.distanceInf(v2);
- }
-
- /** Compute the distance between two vectors according to the L<sub>∞</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNormInf()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the distance between v1 and v2 according to the L<sub>∞</sub> norm
- */
- public static <T extends RealFieldElement<T>> T distanceInf(final Vector3D v1,
- final FieldVector3D<T> v2) {
- return v2.distanceInf(v1);
- }
-
- /** Compute the square of the distance between two vectors.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNormSq()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the square of the distance between v1 and v2
- */
- public static <T extends RealFieldElement<T>> T distanceSq(final FieldVector3D<T> v1,
- final FieldVector3D<T> v2) {
- return v1.distanceSq(v2);
- }
-
- /** Compute the square of the distance between two vectors.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNormSq()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the square of the distance between v1 and v2
- */
- public static <T extends RealFieldElement<T>> T distanceSq(final FieldVector3D<T> v1,
- final Vector3D v2) {
- return v1.distanceSq(v2);
- }
-
- /** Compute the square of the distance between two vectors.
- * <p>Calling this method is equivalent to calling:
- * <code>v1.subtract(v2).getNormSq()</code> except that no intermediate
- * vector is built</p>
- * @param v1 first vector
- * @param v2 second vector
- * @param <T> the type of the field elements
- * @return the square of the distance between v1 and v2
- */
- public static <T extends RealFieldElement<T>> T distanceSq(final Vector3D v1,
- final FieldVector3D<T> v2) {
- return v2.distanceSq(v1);
- }
-
- /** Get a string representation of this vector.
- * @return a string representation of this vector
- */
- @Override
- public String toString() {
- return toVector3D().toString();
- }
-}
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/NotARotationMatrixException.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/NotARotationMatrixException.java
deleted file mode 100644
index 09d00f8..0000000
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/NotARotationMatrixException.java
+++ /dev/null
@@ -1,47 +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.threed;
-
-import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.exception.util.Localizable;
-
-/**
- * This class represents exceptions thrown while building rotations
- * from matrices.
- *
- * @since 1.2
- */
-
-public class NotARotationMatrixException
- extends MathIllegalArgumentException {
-
- /** Serializable version identifier */
- private static final long serialVersionUID = 5647178478658937642L;
-
- /**
- * Simple constructor.
- * Build an exception by translating and formatting a message
- * @param specifier format specifier (to be translated)
- * @param parts to insert in the format (no translation)
- * @since 2.2
- */
- public NotARotationMatrixException(Localizable specifier, Object ... parts) {
- super(specifier, parts);
- }
-
-}
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/RotationConvention.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/RotationConvention.java
deleted file mode 100644
index a80fe9b..0000000
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/RotationConvention.java
+++ /dev/null
@@ -1,81 +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.threed;
-
-import org.apache.commons.geometry.euclidean.threed.Vector3D;
-
-/**
- * This enumerates is used to differentiate the semantics of a rotation.
- * @see FieldRotation
- * @since 3.6
- */
-public enum RotationConvention {
-
- /** Constant for rotation that have the semantics of a vector operator.
- * <p>
- * According to this convention, the rotation moves vectors with respect
- * to a fixed reference frame.
- * </p>
- * <p>
- * This means that if we define rotation r is a 90 degrees rotation around
- * the Z axis, the image of vector {@link Vector3D.Unit#PLUS_X} would be
- * {@link Vector3D.Unit#PLUS_Y}, the image of vector {@link Vector3D.Unit#PLUS_Y}
- * would be {@link Vector3D.Unit#MINUS_X}, the image of vector {@link Vector3D.Unit#PLUS_Z}
- * would be {@link Vector3D.Unit#PLUS_Z}, and the image of vector with coordinates (1, 2, 3)
- * would be vector (-2, 1, 3). This means that the vector rotates counterclockwise.
- * </p>
- * <p>
- * This convention was the only one supported by Apache Commons Math up to version 3.5.
- * </p>
- * <p>
- * The difference with {@link #FRAME_TRANSFORM} is only the semantics of the sign
- * of the angle. It is always possible to create or use a rotation using either
- * convention to really represent a rotation that would have been best created or
- * used with the other convention, by changing accordingly the sign of the
- * rotation angle. This is how things were done up to version 3.5.
- * </p>
- */
- VECTOR_OPERATOR,
-
- /** Constant for rotation that have the semantics of a frame conversion.
- * <p>
- * According to this convention, the rotation considered vectors to be fixed,
- * but their coordinates change as they are converted from an initial frame to
- * a destination frame rotated with respect to the initial frame.
- * </p>
- * <p>
- * This means that if we define rotation r is a 90 degrees rotation around
- * the Z axis, the image of vector {@link Vector3D.Unit#PLUS_X} would be
- * {@link Vector3D.Unit#MINUS_Y}, the image of vector {@link Vector3D.Unit#PLUS_Y}
- * would be {@link Vector3D.Unit#PLUS_X}, the image of vector {@link Vector3D.Unit#PLUS_Z}
- * would be {@link Vector3D.Unit#PLUS_Z}, and the image of vector with coordinates (1, 2, 3)
- * would be vector (2, -1, 3). This means that the coordinates of the vector rotates
- * clockwise, because they are expressed with respect to a destination frame that is rotated
- * counterclockwise.
- * </p>
- * <p>
- * The difference with {@link #VECTOR_OPERATOR} is only the semantics of the sign
- * of the angle. It is always possible to create or use a rotation using either
- * convention to really represent a rotation that would have been best created or
- * used with the other convention, by changing accordingly the sign of the
- * rotation angle. This is how things were done up to version 3.5.
- * </p>
- */
- FRAME_TRANSFORM;
-
-}
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
deleted file mode 100644
index 8bd19d5..0000000
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/RotationOrder.java
+++ /dev/null
@@ -1,171 +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.threed;
-
-import org.apache.commons.geometry.euclidean.threed.Vector3D;
-
-/**
- * This class is a utility representing a rotation order specification
- * for Cardan or Euler angles specification.
- *
- * @since 1.2
- */
-public final class RotationOrder {
-
- /** Set of Cardan angles.
- * this ordered set of rotations is around X, then around Y, then
- * around Z
- */
- public static final RotationOrder XYZ =
- new RotationOrder("XYZ", Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z);
-
- /** 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", Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y);
-
- /** 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", Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z);
-
- /** 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", Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X);
-
- /** 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", Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y);
-
- /** 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", Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X);
-
- /** 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", Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X);
-
- /** 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", Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X);
-
- /** 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", Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y);
-
- /** 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", Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y);
-
- /** 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", Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z);
-
- /** 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", Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z);
-
- /** Name of the rotations order. */
- private final String name;
-
- /** Axis of the first rotation. */
- private final Vector3D a1;
-
- /** Axis of the second rotation. */
- private final Vector3D a2;
-
- /** Axis of the third rotation. */
- private final Vector3D a3;
-
- /** Private constructor.
- * This is a utility class that cannot be instantiated by the user,
- * so its only constructor is private.
- * @param name name of the rotation order
- * @param a1 axis of the first rotation
- * @param a2 axis of the second rotation
- * @param a3 axis of the third rotation
- */
- private RotationOrder(final String name,
- final Vector3D a1, final Vector3D a2, final Vector3D a3) {
- this.name = name;
- this.a1 = a1;
- this.a2 = a2;
- this.a3 = a3;
- }
-
- /** Get a string representation of the instance.
- * @return a string representation of the instance (in fact, its name)
- */
- @Override
- public String toString() {
- return name;
- }
-
- /** Get the axis of the first rotation.
- * @return axis of the first rotation
- */
- public Vector3D getA1() {
- return a1;
- }
-
- /** Get the axis of the second rotation.
- * @return axis of the second rotation
- */
- public Vector3D getA2() {
- return a2;
- }
-
- /** Get the axis of the second rotation.
- * @return axis of the second rotation
- */
- public Vector3D getA3() {
- return a3;
- }
-
-}
diff --git a/src/main/java/org/apache/commons/math4/geometry/package-info.java b/src/main/java/org/apache/commons/math4/geometry/package-info.java
deleted file mode 100644
index 8b9bd9d..0000000
--- a/src/main/java/org/apache/commons/math4/geometry/package-info.java
+++ /dev/null
@@ -1,25 +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.
- */
-/**
- *
- * <p>
- * This package is the top level package for geometry. It provides only a few interfaces
- * related to vectorial/affine spaces that are implemented in sub-packages.
- * </p>
- *
- */
-package org.apache.commons.math4.geometry;
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java
deleted file mode 100644
index 929ee16..0000000
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java
+++ /dev/null
@@ -1,1278 +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.threed;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.apache.commons.numbers.angle.PlaneAngleRadians;
-import org.apache.commons.numbers.quaternion.Quaternion;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.simple.RandomSource;
-import org.apache.commons.rng.sampling.UnitSphereSampler;
-import org.apache.commons.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.geometry.euclidean.threed.rotation.QuaternionRotation;
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.exception.MathArithmeticException;
-import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.geometry.euclidean.threed.CardanEulerSingularityException;
-import org.apache.commons.math4.geometry.euclidean.threed.FieldRotation;
-import org.apache.commons.math4.geometry.euclidean.threed.FieldVector3D;
-import org.apache.commons.math4.geometry.euclidean.threed.NotARotationMatrixException;
-import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder;
-import org.apache.commons.math4.linear.MatrixUtils;
-import org.apache.commons.math4.linear.RealMatrix;
-import org.apache.commons.math4.util.FastMath;
-
-
-public class FieldRotationDSTest {
-
- @Test
- public void testIdentity() {
-
- FieldRotation<DerivativeStructure> r = createRotation(1, 0, 0, 0, false);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(1, 0, 0));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(0, 1, 0));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(0, 0, 1));
- checkAngle(r.getAngle(), 0);
-
- r = createRotation(-1, 0, 0, 0, false);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(1, 0, 0));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(0, 1, 0));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(0, 0, 1));
- checkAngle(r.getAngle(), 0);
-
- r = createRotation(42, 0, 0, 0, true);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(1, 0, 0));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(0, 1, 0));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(0, 0, 1));
- checkAngle(r.getAngle(), 0);
-
- }
-
- @Test
- @Deprecated
- public void testAxisAngleDeprecated() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(createAxis(10, 10, 10), createAngle(2 * FastMath.PI / 3));
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(0, 1, 0));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(0, 0, 1));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(1, 0, 0));
- double s = 1 / FastMath.sqrt(3);
- checkVector(r.getAxis(), createVector(s, s, s));
- checkAngle(r.getAngle(), 2 * FastMath.PI / 3);
-
- try {
- new FieldRotation<>(createAxis(0, 0, 0), createAngle(2 * FastMath.PI / 3));
- Assert.fail("an exception should have been thrown");
- } catch (MathIllegalArgumentException e) {
- }
-
- r = new FieldRotation<>(createAxis(0, 0, 1), createAngle(1.5 * FastMath.PI));
- checkVector(r.getAxis(), createVector(0, 0, -1));
- checkAngle(r.getAngle(), 0.5 * FastMath.PI);
-
- r = new FieldRotation<>(createAxis(0, 1, 0), createAngle(FastMath.PI));
- checkVector(r.getAxis(), createVector(0, 1, 0));
- checkAngle(r.getAngle(), FastMath.PI);
-
- checkVector(createRotation(1, 0, 0, 0, false).getAxis(), createVector(1, 0, 0));
-
- }
-
- @Test
- public void testAxisAngleVectorOperator() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(createAxis(10, 10, 10),
- createAngle(2 * FastMath.PI / 3) ,
- RotationConvention.VECTOR_OPERATOR);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(0, 1, 0));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(0, 0, 1));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(1, 0, 0));
- double s = 1 / FastMath.sqrt(3);
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector( s, s, s));
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector(-s, -s, -s));
- checkAngle(r.getAngle(), 2 * FastMath.PI / 3);
-
- try {
- new FieldRotation<>(createAxis(0, 0, 0),
- createAngle(2 * FastMath.PI / 3),
- RotationConvention.VECTOR_OPERATOR);
- Assert.fail("an exception should have been thrown");
- } catch (MathIllegalArgumentException e) {
- }
-
- r = new FieldRotation<>(createAxis(0, 0, 1),
- createAngle(1.5 * FastMath.PI),
- RotationConvention.VECTOR_OPERATOR);
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector(0, 0, -1));
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector(0, 0, +1));
- checkAngle(r.getAngle(), 0.5 * FastMath.PI);
-
- r = new FieldRotation<>(createAxis(0, 1, 0),
- createAngle(FastMath.PI),
- RotationConvention.VECTOR_OPERATOR);
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector(0, +1, 0));
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector(0, -1, 0));
- checkAngle(r.getAngle(), FastMath.PI);
-
- checkVector(createRotation(1, 0, 0, 0, false).getAxis(RotationConvention.VECTOR_OPERATOR), createVector(+1, 0, 0));
- checkVector(createRotation(1, 0, 0, 0, false).getAxis(RotationConvention.FRAME_TRANSFORM), createVector(-1, 0, 0));
-
- }
-
- @Test
- public void testAxisAngleFrameTransform() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(createAxis(10, 10, 10),
- createAngle(2 * FastMath.PI / 3) ,
- RotationConvention.FRAME_TRANSFORM);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(0, 0, 1));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(1, 0, 0));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(0, 1, 0));
- double s = 1 / FastMath.sqrt(3);
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector( s, s, s));
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector(-s, -s, -s));
- checkAngle(r.getAngle(), 2 * FastMath.PI / 3);
-
- try {
- new FieldRotation<>(createAxis(0, 0, 0),
- createAngle(2 * FastMath.PI / 3),
- RotationConvention.FRAME_TRANSFORM);
- Assert.fail("an exception should have been thrown");
- } catch (MathIllegalArgumentException e) {
- }
-
- r = new FieldRotation<>(createAxis(0, 0, 1),
- createAngle(1.5 * FastMath.PI),
- RotationConvention.FRAME_TRANSFORM);
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector(0, 0, -1));
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector(0, 0, +1));
- checkAngle(r.getAngle(), 0.5 * FastMath.PI);
-
- r = new FieldRotation<>(createAxis(0, 1, 0),
- createAngle(FastMath.PI),
- RotationConvention.FRAME_TRANSFORM);
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector(0, +1, 0));
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector(0, -1, 0));
- checkAngle(r.getAngle(), FastMath.PI);
-
- checkVector(createRotation(1, 0, 0, 0, false).getAxis(RotationConvention.FRAME_TRANSFORM), createVector(-1, 0, 0));
- checkVector(createRotation(1, 0, 0, 0, false).getAxis(RotationConvention.VECTOR_OPERATOR), createVector(+1, 0, 0));
-
- }
-
- @Test
- public void testRevert() {
- double a = 0.001;
- double b = 0.36;
- double c = 0.48;
- double d = 0.8;
- FieldRotation<DerivativeStructure> r = createRotation(a, b, c, d, true);
- double a2 = a * a;
- double b2 = b * b;
- double c2 = c * c;
- double d2 = d * d;
- double den = (a2 + b2 + c2 + d2) * FastMath.sqrt(a2 + b2 + c2 + d2);
- Assert.assertEquals((b2 + c2 + d2) / den, r.getQ0().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(-a * b / den, r.getQ0().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(-a * c / den, r.getQ0().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(-a * d / den, r.getQ0().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(-b * a / den, r.getQ1().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals((a2 + c2 + d2) / den, r.getQ1().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(-b * c / den, r.getQ1().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(-b * d / den, r.getQ1().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(-c * a / den, r.getQ2().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(-c * b / den, r.getQ2().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals((a2 + b2 + d2) / den, r.getQ2().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(-c * d / den, r.getQ2().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(-d * a / den, r.getQ3().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(-d * b / den, r.getQ3().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(-d * c / den, r.getQ3().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals((a2 + b2 + c2) / den, r.getQ3().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- FieldRotation<DerivativeStructure> reverted = r.revert();
- FieldRotation<DerivativeStructure> rrT = r.applyTo(reverted);
- checkRotationDS(rrT, 1, 0, 0, 0);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- FieldRotation<DerivativeStructure> rTr = reverted.applyTo(r);
- checkRotationDS(rTr, 1, 0, 0, 0);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(r.getAngle().getReal(), reverted.getAngle().getReal(), 1.0e-15);
- Assert.assertEquals(-1,
- FieldVector3D.dotProduct(r.getAxis(RotationConvention.VECTOR_OPERATOR),
- reverted.getAxis(RotationConvention.VECTOR_OPERATOR)).getReal(),
- 1.0e-15);
- }
-
- @Test
- public void testRevertVectorOperator() {
- double a = 0.001;
- double b = 0.36;
- double c = 0.48;
- double d = 0.8;
- FieldRotation<DerivativeStructure> r = createRotation(a, b, c, d, true);
- double a2 = a * a;
- double b2 = b * b;
- double c2 = c * c;
- double d2 = d * d;
- double den = (a2 + b2 + c2 + d2) * FastMath.sqrt(a2 + b2 + c2 + d2);
- Assert.assertEquals((b2 + c2 + d2) / den, r.getQ0().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(-a * b / den, r.getQ0().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(-a * c / den, r.getQ0().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(-a * d / den, r.getQ0().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(-b * a / den, r.getQ1().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals((a2 + c2 + d2) / den, r.getQ1().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(-b * c / den, r.getQ1().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(-b * d / den, r.getQ1().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(-c * a / den, r.getQ2().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(-c * b / den, r.getQ2().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals((a2 + b2 + d2) / den, r.getQ2().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(-c * d / den, r.getQ2().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(-d * a / den, r.getQ3().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(-d * b / den, r.getQ3().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(-d * c / den, r.getQ3().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals((a2 + b2 + c2) / den, r.getQ3().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- FieldRotation<DerivativeStructure> reverted = r.revert();
- FieldRotation<DerivativeStructure> rrT = r.compose(reverted, RotationConvention.VECTOR_OPERATOR);
- checkRotationDS(rrT, 1, 0, 0, 0);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- FieldRotation<DerivativeStructure> rTr = reverted.compose(r, RotationConvention.VECTOR_OPERATOR);
- checkRotationDS(rTr, 1, 0, 0, 0);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(r.getAngle().getReal(), reverted.getAngle().getReal(), 1.0e-15);
- Assert.assertEquals(-1,
- FieldVector3D.dotProduct(r.getAxis(RotationConvention.VECTOR_OPERATOR),
- reverted.getAxis(RotationConvention.VECTOR_OPERATOR)).getReal(),
- 1.0e-15);
- }
-
- @Test
- public void testRevertFrameTransform() {
- double a = 0.001;
- double b = 0.36;
- double c = 0.48;
- double d = 0.8;
- FieldRotation<DerivativeStructure> r = createRotation(a, b, c, d, true);
- double a2 = a * a;
- double b2 = b * b;
- double c2 = c * c;
- double d2 = d * d;
- double den = (a2 + b2 + c2 + d2) * FastMath.sqrt(a2 + b2 + c2 + d2);
- Assert.assertEquals((b2 + c2 + d2) / den, r.getQ0().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(-a * b / den, r.getQ0().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(-a * c / den, r.getQ0().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(-a * d / den, r.getQ0().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(-b * a / den, r.getQ1().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals((a2 + c2 + d2) / den, r.getQ1().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(-b * c / den, r.getQ1().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(-b * d / den, r.getQ1().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(-c * a / den, r.getQ2().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(-c * b / den, r.getQ2().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals((a2 + b2 + d2) / den, r.getQ2().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(-c * d / den, r.getQ2().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(-d * a / den, r.getQ3().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(-d * b / den, r.getQ3().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(-d * c / den, r.getQ3().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals((a2 + b2 + c2) / den, r.getQ3().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- FieldRotation<DerivativeStructure> reverted = r.revert();
- FieldRotation<DerivativeStructure> rrT = r.compose(reverted, RotationConvention.FRAME_TRANSFORM);
- checkRotationDS(rrT, 1, 0, 0, 0);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ0().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ1().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ2().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rrT.getQ3().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- FieldRotation<DerivativeStructure> rTr = reverted.compose(r, RotationConvention.FRAME_TRANSFORM);
- checkRotationDS(rTr, 1, 0, 0, 0);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ0().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ1().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ2().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(1, 0, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(0, 1, 0, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(0, 0, 1, 0), 1.0e-15);
- Assert.assertEquals(0, rTr.getQ3().getPartialDerivative(0, 0, 0, 1), 1.0e-15);
- Assert.assertEquals(r.getAngle().getReal(), reverted.getAngle().getReal(), 1.0e-15);
- Assert.assertEquals(-1,
- FieldVector3D.dotProduct(r.getAxis(RotationConvention.FRAME_TRANSFORM),
- reverted.getAxis(RotationConvention.FRAME_TRANSFORM)).getReal(),
- 1.0e-15);
- }
-
- @Test
- public void testVectorOnePair() throws MathArithmeticException {
-
- FieldVector3D<DerivativeStructure> u = createVector(3, 2, 1);
- FieldVector3D<DerivativeStructure> v = createVector(-4, 2, 2);
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(u, v);
- checkVector(r.applyTo(u.scalarMultiply(v.getNorm())), v.scalarMultiply(u.getNorm()));
-
- checkAngle(new FieldRotation<>(u, u.negate()).getAngle(), FastMath.PI);
-
- try {
- new FieldRotation<>(u, createVector(0, 0, 0));
- Assert.fail("an exception should have been thrown");
- } catch (MathArithmeticException e) {
- // expected behavior
- }
-
- }
-
- @Test
- public void testVectorTwoPairs() throws MathArithmeticException {
-
- FieldVector3D<DerivativeStructure> u1 = createVector(3, 0, 0);
- FieldVector3D<DerivativeStructure> u2 = createVector(0, 5, 0);
- FieldVector3D<DerivativeStructure> v1 = createVector(0, 0, 2);
- FieldVector3D<DerivativeStructure> v2 = createVector(-2, 0, 2);
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(u1, u2, v1, v2);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(0, 0, 1));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(-1, 0, 0));
-
- r = new FieldRotation<>(u1, u2, u1.negate(), u2.negate());
- FieldVector3D<DerivativeStructure> axis = r.getAxis(RotationConvention.VECTOR_OPERATOR);
- if (FieldVector3D.dotProduct(axis, createVector(0, 0, 1)).getReal() > 0) {
- checkVector(axis, createVector(0, 0, 1));
- } else {
- checkVector(axis, createVector(0, 0, -1));
- }
- checkAngle(r.getAngle(), FastMath.PI);
-
- double sqrt = FastMath.sqrt(2) / 2;
- r = new FieldRotation<>(createVector(1, 0, 0), createVector(0, 1, 0),
- createVector(0.5, 0.5, sqrt),
- createVector(0.5, 0.5, -sqrt));
- checkRotationDS(r, sqrt, 0.5, 0.5, 0);
-
- r = new FieldRotation<>(u1, u2, u1, FieldVector3D.crossProduct(u1, u2));
- checkRotationDS(r, sqrt, -sqrt, 0, 0);
-
- checkRotationDS(new FieldRotation<>(u1, u2, u1, u2), 1, 0, 0, 0);
-
- try {
- new FieldRotation<>(u1, u2, createVector(0, 0, 0), v2);
- Assert.fail("an exception should have been thrown");
- } catch (MathArithmeticException e) {
- // expected behavior
- }
-
- }
-
- @Test
- public void testMatrix()
- throws NotARotationMatrixException {
-
- try {
- createRotation(new double[][] {
- { 0.0, 1.0, 0.0 },
- { 1.0, 0.0, 0.0 }
- }, 1.0e-7);
- Assert.fail("Expecting NotARotationMatrixException");
- } catch (NotARotationMatrixException nrme) {
- // expected behavior
- }
-
- try {
- createRotation(new double[][] {
- { 0.445888, 0.797184, -0.407040 },
- { 0.821760, -0.184320, 0.539200 },
- { -0.354816, 0.574912, 0.737280 }
- }, 1.0e-7);
- Assert.fail("Expecting NotARotationMatrixException");
- } catch (NotARotationMatrixException nrme) {
- // expected behavior
- }
-
- try {
- createRotation(new double[][] {
- { 0.4, 0.8, -0.4 },
- { -0.4, 0.6, 0.7 },
- { 0.8, -0.2, 0.5 }
- }, 1.0e-15);
- Assert.fail("Expecting NotARotationMatrixException");
- } catch (NotARotationMatrixException nrme) {
- // expected behavior
- }
-
- checkRotationDS(createRotation(new double[][] {
- { 0.445888, 0.797184, -0.407040 },
- { -0.354816, 0.574912, 0.737280 },
- { 0.821760, -0.184320, 0.539200 }
- }, 1.0e-10),
- 0.8, 0.288, 0.384, 0.36);
-
- checkRotationDS(createRotation(new double[][] {
- { 0.539200, 0.737280, 0.407040 },
- { 0.184320, -0.574912, 0.797184 },
- { 0.821760, -0.354816, -0.445888 }
- }, 1.0e-10),
- 0.36, 0.8, 0.288, 0.384);
-
- checkRotationDS(createRotation(new double[][] {
- { -0.445888, 0.797184, -0.407040 },
- { 0.354816, 0.574912, 0.737280 },
- { 0.821760, 0.184320, -0.539200 }
- }, 1.0e-10),
- 0.384, 0.36, 0.8, 0.288);
-
- checkRotationDS(createRotation(new double[][] {
- { -0.539200, 0.737280, 0.407040 },
- { -0.184320, -0.574912, 0.797184 },
- { 0.821760, 0.354816, 0.445888 }
- }, 1.0e-10),
- 0.288, 0.384, 0.36, 0.8);
-
- double[][] m1 = { { 0.0, 1.0, 0.0 },
- { 0.0, 0.0, 1.0 },
- { 1.0, 0.0, 0.0 } };
- FieldRotation<DerivativeStructure> r = createRotation(m1, 1.0e-7);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(0, 0, 1));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(1, 0, 0));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(0, 1, 0));
-
- double[][] m2 = { { 0.83203, -0.55012, -0.07139 },
- { 0.48293, 0.78164, -0.39474 },
- { 0.27296, 0.29396, 0.91602 } };
- r = createRotation(m2, 1.0e-12);
-
- DerivativeStructure[][] m3 = r.getMatrix();
- double d00 = m2[0][0] - m3[0][0].getReal();
- double d01 = m2[0][1] - m3[0][1].getReal();
- double d02 = m2[0][2] - m3[0][2].getReal();
- double d10 = m2[1][0] - m3[1][0].getReal();
- double d11 = m2[1][1] - m3[1][1].getReal();
- double d12 = m2[1][2] - m3[1][2].getReal();
- double d20 = m2[2][0] - m3[2][0].getReal();
- double d21 = m2[2][1] - m3[2][1].getReal();
- double d22 = m2[2][2] - m3[2][2].getReal();
-
- Assert.assertTrue(FastMath.abs(d00) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d01) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d02) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d10) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d11) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d12) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d20) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d21) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d22) < 6.0e-6);
-
- Assert.assertTrue(FastMath.abs(d00) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d01) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d02) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d10) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d11) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d12) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d20) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d21) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d22) > 4.0e-7);
-
- for (int i = 0; i < 3; ++i) {
- for (int j = 0; j < 3; ++j) {
- double m3tm3 = m3[i][0].getReal() * m3[j][0].getReal() +
- m3[i][1].getReal() * m3[j][1].getReal() +
- m3[i][2].getReal() * m3[j][2].getReal();
- if (i == j) {
- Assert.assertTrue(FastMath.abs(m3tm3 - 1.0) < 1.0e-10);
- } else {
- Assert.assertTrue(FastMath.abs(m3tm3) < 1.0e-10);
- }
- }
- }
-
- checkVector(r.applyTo(createVector(1, 0, 0)),
- new FieldVector3D<>(m3[0][0], m3[1][0], m3[2][0]));
- checkVector(r.applyTo(createVector(0, 1, 0)),
- new FieldVector3D<>(m3[0][1], m3[1][1], m3[2][1]));
- checkVector(r.applyTo(createVector(0, 0, 1)),
- new FieldVector3D<>(m3[0][2], m3[1][2], m3[2][2]));
-
- double[][] m4 = { { 1.0, 0.0, 0.0 },
- { 0.0, -1.0, 0.0 },
- { 0.0, 0.0, -1.0 } };
- r = createRotation(m4, 1.0e-7);
- checkAngle(r.getAngle(), FastMath.PI);
-
- try {
- double[][] m5 = { { 0.0, 0.0, 1.0 },
- { 0.0, 1.0, 0.0 },
- { 1.0, 0.0, 0.0 } };
- r = createRotation(m5, 1.0e-7);
- Assert.fail("got " + r + ", should have caught an exception");
- } catch (NotARotationMatrixException e) {
- // expected
- }
-
- }
-
- @Test
- @Deprecated
- public void testAnglesDeprecated()
- throws CardanEulerSingularityException {
-
- RotationOrder[] CardanOrders = {
- RotationOrder.XYZ, RotationOrder.XZY, RotationOrder.YXZ,
- RotationOrder.YZX, RotationOrder.ZXY, RotationOrder.ZYX
- };
-
- for (int i = 0; i < CardanOrders.length; ++i) {
- for (double alpha1 = 0.1; alpha1 < 6.2; alpha1 += 0.3) {
- for (double alpha2 = -1.55; alpha2 < 1.55; alpha2 += 0.3) {
- for (double alpha3 = 0.1; alpha3 < 6.2; alpha3 += 0.3) {
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(CardanOrders[i],
- new DerivativeStructure(3, 1, 0, alpha1),
- new DerivativeStructure(3, 1, 1, alpha2),
- new DerivativeStructure(3, 1, 2, alpha3));
- DerivativeStructure[] angles = r.getAngles(CardanOrders[i]);
- checkAngle(angles[0], alpha1);
- checkAngle(angles[1], alpha2);
- checkAngle(angles[2], alpha3);
- }
- }
- }
- }
-
- RotationOrder[] EulerOrders = {
- RotationOrder.XYX, RotationOrder.XZX, RotationOrder.YXY,
- RotationOrder.YZY, RotationOrder.ZXZ, RotationOrder.ZYZ
- };
-
- for (int i = 0; i < EulerOrders.length; ++i) {
- for (double alpha1 = 0.1; alpha1 < 6.2; alpha1 += 0.3) {
- for (double alpha2 = 0.05; alpha2 < 3.1; alpha2 += 0.3) {
- for (double alpha3 = 0.1; alpha3 < 6.2; alpha3 += 0.3) {
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(EulerOrders[i],
- new DerivativeStructure(3, 1, 0, alpha1),
- new DerivativeStructure(3, 1, 1, alpha2),
- new DerivativeStructure(3, 1, 2, alpha3));
- DerivativeStructure[] angles = r.getAngles(EulerOrders[i]);
- checkAngle(angles[0], alpha1);
- checkAngle(angles[1], alpha2);
- checkAngle(angles[2], alpha3);
- }
- }
- }
- }
-
- }
-
- @Test
- public void testAngles()
- throws CardanEulerSingularityException {
-
- for (RotationConvention convention : RotationConvention.values()) {
- RotationOrder[] CardanOrders = {
- RotationOrder.XYZ, RotationOrder.XZY, RotationOrder.YXZ,
- RotationOrder.YZX, RotationOrder.ZXY, RotationOrder.ZYX
- };
-
- for (int i = 0; i < CardanOrders.length; ++i) {
- for (double alpha1 = 0.1; alpha1 < 6.2; alpha1 += 0.3) {
- for (double alpha2 = -1.55; alpha2 < 1.55; alpha2 += 0.3) {
- for (double alpha3 = 0.1; alpha3 < 6.2; alpha3 += 0.3) {
- FieldRotation<DerivativeStructure> r =
- new FieldRotation<>(CardanOrders[i],
- convention,
- new DerivativeStructure(3, 1, 0, alpha1),
- new DerivativeStructure(3, 1, 1, alpha2),
- new DerivativeStructure(3, 1, 2, alpha3));
- DerivativeStructure[] angles = r.getAngles(CardanOrders[i], convention);
- checkAngle(angles[0], alpha1);
- checkAngle(angles[1], alpha2);
- checkAngle(angles[2], alpha3);
- }
- }
- }
- }
-
- RotationOrder[] EulerOrders = {
- RotationOrder.XYX, RotationOrder.XZX, RotationOrder.YXY,
- RotationOrder.YZY, RotationOrder.ZXZ, RotationOrder.ZYZ
- };
-
- for (int i = 0; i < EulerOrders.length; ++i) {
- for (double alpha1 = 0.1; alpha1 < 6.2; alpha1 += 0.3) {
- for (double alpha2 = 0.05; alpha2 < 3.1; alpha2 += 0.3) {
- for (double alpha3 = 0.1; alpha3 < 6.2; alpha3 += 0.3) {
- FieldRotation<DerivativeStructure> r =
- new FieldRotation<>(EulerOrders[i],
- convention,
- new DerivativeStructure(3, 1, 0, alpha1),
- new DerivativeStructure(3, 1, 1, alpha2),
- new DerivativeStructure(3, 1, 2, alpha3));
- DerivativeStructure[] angles = r.getAngles(EulerOrders[i], convention);
- checkAngle(angles[0], alpha1);
- checkAngle(angles[1], alpha2);
- checkAngle(angles[2], alpha3);
- }
- }
- }
- }
- }
-
- }
-
- @Test
- public void testSingularities() {
-
- for (RotationConvention convention : RotationConvention.values()) {
- RotationOrder[] CardanOrders = {
- RotationOrder.XYZ, RotationOrder.XZY, RotationOrder.YXZ,
- RotationOrder.YZX, RotationOrder.ZXY, RotationOrder.ZYX
- };
-
- double[] singularCardanAngle = { FastMath.PI / 2, -FastMath.PI / 2 };
- for (int i = 0; i < CardanOrders.length; ++i) {
- for (int j = 0; j < singularCardanAngle.length; ++j) {
- FieldRotation<DerivativeStructure> r =
- new FieldRotation<>(CardanOrders[i],
- convention,
- new DerivativeStructure(3, 1, 0, 0.1),
- new DerivativeStructure(3, 1, 1, singularCardanAngle[j]),
- new DerivativeStructure(3, 1, 2, 0.3));
- try {
- r.getAngles(CardanOrders[i], convention);
- Assert.fail("an exception should have been caught");
- } catch (CardanEulerSingularityException cese) {
- // expected behavior
- }
- }
- }
-
- RotationOrder[] EulerOrders = {
- RotationOrder.XYX, RotationOrder.XZX, RotationOrder.YXY,
- RotationOrder.YZY, RotationOrder.ZXZ, RotationOrder.ZYZ
- };
-
- double[] singularEulerAngle = { 0, FastMath.PI };
- for (int i = 0; i < EulerOrders.length; ++i) {
- for (int j = 0; j < singularEulerAngle.length; ++j) {
- FieldRotation<DerivativeStructure> r =
- new FieldRotation<>(EulerOrders[i],
- convention,
- new DerivativeStructure(3, 1, 0, 0.1),
- new DerivativeStructure(3, 1, 1, singularEulerAngle[j]),
- new DerivativeStructure(3, 1, 2, 0.3));
- try {
- r.getAngles(EulerOrders[i], convention);
- Assert.fail("an exception should have been caught");
- } catch (CardanEulerSingularityException cese) {
- // expected behavior
- }
- }
- }
-
- }
- }
-
- @Test
- public void testQuaternion() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- double n = 23.5;
- FieldRotation<DerivativeStructure> r2 = new FieldRotation<>(r1.getQ0().multiply(n), r1.getQ1().multiply(n),
- r1.getQ2().multiply(n), r1.getQ3().multiply(n),
- true);
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(x, y, z);
- checkVector(r2.applyTo(u), r1.applyTo(u));
- }
- }
- }
-
- r1 = createRotation(0.288, 0.384, 0.36, 0.8, false);
- checkRotationDS(r1,
- -r1.getQ0().getReal(), -r1.getQ1().getReal(),
- -r1.getQ2().getReal(), -r1.getQ3().getReal());
- final Quaternion r1Quat = r1.toRotation().getQuaternion();
- Assert.assertEquals(0.288, r1Quat.getW(), 1.0e-15);
- Assert.assertEquals(0.384, r1Quat.getX(), 1.0e-15);
- Assert.assertEquals(0.36, r1Quat.getY(), 1.0e-15);
- Assert.assertEquals(0.8, r1Quat.getZ(), 1.0e-15);
-
- }
-
- @Test
- public void testApplyToRotation() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> r3 = r2.applyTo(r1);
- FieldRotation<DerivativeStructure> r3Double = r2.applyTo(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()));
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(x, y, z);
- checkVector(r2.applyTo(r1.applyTo(u)), r3.applyTo(u));
- checkVector(r2.applyTo(r1.applyTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testComposeVectorOperator() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> r3 = r2.compose(r1, RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> r3Double = r2.compose(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()),
- RotationConvention.VECTOR_OPERATOR);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(x, y, z);
- checkVector(r2.applyTo(r1.applyTo(u)), r3.applyTo(u));
- checkVector(r2.applyTo(r1.applyTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testComposeFrameTransform() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.FRAME_TRANSFORM);
- FieldRotation<DerivativeStructure> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.FRAME_TRANSFORM);
- FieldRotation<DerivativeStructure> r3 = r2.compose(r1, RotationConvention.FRAME_TRANSFORM);
- FieldRotation<DerivativeStructure> r3Double = r2.compose(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()),
- RotationConvention.FRAME_TRANSFORM);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(x, y, z);
- checkVector(r1.applyTo(r2.applyTo(u)), r3.applyTo(u));
- checkVector(r1.applyTo(r2.applyTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testApplyInverseToRotation() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> r3 = r2.applyInverseTo(r1);
- FieldRotation<DerivativeStructure> r3Double = r2.applyInverseTo(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()));
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(x, y, z);
- checkVector(r2.applyInverseTo(r1.applyTo(u)), r3.applyTo(u));
- checkVector(r2.applyInverseTo(r1.applyTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testComposeInverseVectorOperator() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> r3 = r2.composeInverse(r1, RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> r3Double = r2.composeInverse(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()),
- RotationConvention.VECTOR_OPERATOR);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(x, y, z);
- checkVector(r2.applyInverseTo(r1.applyTo(u)), r3.applyTo(u));
- checkVector(r2.applyInverseTo(r1.applyTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testComposeInverseframeTransform() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.FRAME_TRANSFORM);
- FieldRotation<DerivativeStructure> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.FRAME_TRANSFORM);
- FieldRotation<DerivativeStructure> r3 = r2.composeInverse(r1, RotationConvention.FRAME_TRANSFORM);
- FieldRotation<DerivativeStructure> r3Double = r2.composeInverse(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()),
- RotationConvention.FRAME_TRANSFORM);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(x, y, z);
- checkVector(r1.applyTo(r2.applyInverseTo(u)), r3.applyTo(u));
- checkVector(r1.applyTo(r2.applyInverseTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testDoubleVectors() throws MathIllegalArgumentException {
- UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
- 0x180b41cfeeffaf67l);
- UnitSphereSampler g = new UnitSphereSampler(3, random);
- for (int i = 0; i < 10; ++i) {
- double[] unit = g.nextVector();
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(createVector(unit[0], unit[1], unit[2]),
- createAngle(random.nextDouble()),
- RotationConvention.VECTOR_OPERATOR);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<DerivativeStructure> uds = createVector(x, y, z);
- FieldVector3D<DerivativeStructure> ruds = r.applyTo(uds);
- FieldVector3D<DerivativeStructure> rIuds = r.applyInverseTo(uds);
- Vector3D u = Vector3D.of(x, y, z);
- FieldVector3D<DerivativeStructure> ru = r.applyTo(u);
- FieldVector3D<DerivativeStructure> rIu = r.applyInverseTo(u);
- DerivativeStructure[] ruArray = new DerivativeStructure[3];
- r.applyTo(new double[] { x, y, z}, ruArray);
- DerivativeStructure[] rIuArray = new DerivativeStructure[3];
- r.applyInverseTo(new double[] { x, y, z}, rIuArray);
- checkVector(ruds, ru);
- checkVector(ruds, new FieldVector3D<>(ruArray));
- checkVector(rIuds, rIu);
- checkVector(rIuds, new FieldVector3D<>(rIuArray));
- }
- }
- }
- }
-
- }
-
- @Test
- public void testDoubleRotations() throws MathIllegalArgumentException {
- UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
- 0x180b41cfeeffaf67l);
- UnitSphereSampler g = new UnitSphereSampler(3, random);
- for (int i = 0; i < 10; ++i) {
- double[] unit1 = g.nextVector();
- QuaternionRotation r1 = QuaternionRotation.of(random.nextDouble(),
- unit1[0], unit1[1], unit1[2]);
- final Quaternion r1Quat = r1.getQuaternion();
- FieldRotation<DerivativeStructure> r1Prime = new FieldRotation<>(new DerivativeStructure(4, 1, 0, r1Quat.getW()),
- new DerivativeStructure(4, 1, 1, r1Quat.getX()),
- new DerivativeStructure(4, 1, 2, r1Quat.getY()),
- new DerivativeStructure(4, 1, 3, r1Quat.getZ()),
- false);
- double[] unit2 = g.nextVector();
- FieldRotation<DerivativeStructure> r2 = new FieldRotation<>(createVector(unit2[0], unit2[1], unit2[2]),
- createAngle(random.nextDouble()),
- RotationConvention.VECTOR_OPERATOR);
-
- FieldRotation<DerivativeStructure> rA = FieldRotation.applyTo(r1, r2);
- FieldRotation<DerivativeStructure> rB = r1Prime.compose(r2, RotationConvention.VECTOR_OPERATOR);
- FieldRotation<DerivativeStructure> rC = FieldRotation.applyInverseTo(r1, r2);
- FieldRotation<DerivativeStructure> rD = r1Prime.composeInverse(r2, RotationConvention.VECTOR_OPERATOR);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
-
- FieldVector3D<DerivativeStructure> uds = createVector(x, y, z);
- checkVector(r1Prime.applyTo(uds), FieldRotation.applyTo(r1, uds));
- checkVector(r1Prime.applyInverseTo(uds), FieldRotation.applyInverseTo(r1, uds));
- checkVector(rA.applyTo(uds), rB.applyTo(uds));
- checkVector(rA.applyInverseTo(uds), rB.applyInverseTo(uds));
- checkVector(rC.applyTo(uds), rD.applyTo(uds));
- checkVector(rC.applyInverseTo(uds), rD.applyInverseTo(uds));
-
- }
- }
- }
- }
-
- }
-
- @Test
- public void testDerivatives() {
-
- double eps = 5.0e-16;
- double kx = 2;
- double ky = -3;
- double kz = 5;
- double n2 = kx * kx + ky * ky + kz * kz;
- double n = FastMath.sqrt(n2);
- double theta = 1.7;
- double cosTheta = FastMath.cos(theta);
- double sinTheta = FastMath.sin(theta);
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(createAxis(kx, ky, kz),
- createAngle(theta),
- RotationConvention.VECTOR_OPERATOR);
- Vector3D a = Vector3D.of(kx / n, ky / n, kz / n);
-
- // Jacobian of the normalized rotation axis a with respect to the Cartesian vector k
- RealMatrix dadk = MatrixUtils.createRealMatrix(new double[][] {
- { (ky * ky + kz * kz) / ( n * n2), -kx * ky / ( n * n2), -kx * kz / ( n * n2) },
- { -kx * ky / ( n * n2), (kx * kx + kz * kz) / ( n * n2), -ky * kz / ( n * n2) },
- { -kx * kz / ( n * n2), -ky * kz / ( n * n2), (kx * kx + ky * ky) / ( n * n2) }
- });
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- Vector3D u = Vector3D.of(x, y, z);
- FieldVector3D<DerivativeStructure> v = r.applyTo(createVector(x, y, z));
-
- // explicit formula for rotation of vector u around axis a with angle theta
- double dot = u.dot(a);
- Vector3D cross = a.cross(u);
- double c1 = 1 - cosTheta;
- double c2 = c1 * dot;
- Vector3D rt = Vector3D.linearCombination(cosTheta, u, c2, a, sinTheta, cross);
- Assert.assertEquals(rt.getX(), v.getX().getReal(), eps);
- Assert.assertEquals(rt.getY(), v.getY().getReal(), eps);
- Assert.assertEquals(rt.getZ(), v.getZ().getReal(), eps);
-
- // Jacobian of the image v = r(u) with respect to rotation axis a
- // (analytical differentiation of the explicit formula)
- RealMatrix dvda = MatrixUtils.createRealMatrix(new double[][] {
- { c1 * x * a.getX() + c2, c1 * y * a.getX() + sinTheta * z, c1 * z * a.getX() - sinTheta * y },
- { c1 * x * a.getY() - sinTheta * z, c1 * y * a.getY() + c2, c1 * z * a.getY() + sinTheta * x },
- { c1 * x * a.getZ() + sinTheta * y, c1 * y * a.getZ() - sinTheta * x, c1 * z * a.getZ() + c2 }
- });
-
- // compose Jacobians
- RealMatrix dvdk = dvda.multiply(dadk);
-
- // derivatives with respect to un-normalized axis
- Assert.assertEquals(dvdk.getEntry(0, 0), v.getX().getPartialDerivative(1, 0, 0, 0), eps);
- Assert.assertEquals(dvdk.getEntry(0, 1), v.getX().getPartialDerivative(0, 1, 0, 0), eps);
- Assert.assertEquals(dvdk.getEntry(0, 2), v.getX().getPartialDerivative(0, 0, 1, 0), eps);
- Assert.assertEquals(dvdk.getEntry(1, 0), v.getY().getPartialDerivative(1, 0, 0, 0), eps);
- Assert.assertEquals(dvdk.getEntry(1, 1), v.getY().getPartialDerivative(0, 1, 0, 0), eps);
- Assert.assertEquals(dvdk.getEntry(1, 2), v.getY().getPartialDerivative(0, 0, 1, 0), eps);
- Assert.assertEquals(dvdk.getEntry(2, 0), v.getZ().getPartialDerivative(1, 0, 0, 0), eps);
- Assert.assertEquals(dvdk.getEntry(2, 1), v.getZ().getPartialDerivative(0, 1, 0, 0), eps);
- Assert.assertEquals(dvdk.getEntry(2, 2), v.getZ().getPartialDerivative(0, 0, 1, 0), eps);
-
- // derivative with respect to rotation angle
- // (analytical differentiation of the explicit formula)
- Vector3D dvdTheta =
- Vector3D.linearCombination(-sinTheta, u, sinTheta * dot, a, cosTheta, cross);
- Assert.assertEquals(dvdTheta.getX(), v.getX().getPartialDerivative(0, 0, 0, 1), eps);
- Assert.assertEquals(dvdTheta.getY(), v.getY().getPartialDerivative(0, 0, 0, 1), eps);
- Assert.assertEquals(dvdTheta.getZ(), v.getZ().getPartialDerivative(0, 0, 0, 1), eps);
-
- }
- }
- }
- }
-
- @Test
- public void testArray() throws MathIllegalArgumentException {
-
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(createAxis(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(x, y, z);
- FieldVector3D<DerivativeStructure> v = r.applyTo(u);
- DerivativeStructure[] out = new DerivativeStructure[3];
- r.applyTo(new DerivativeStructure[] { u.getX(), u.getY(), u.getZ() }, out);
- Assert.assertEquals(v.getX().getReal(), out[0].getReal(), 1.0e-10);
- Assert.assertEquals(v.getY().getReal(), out[1].getReal(), 1.0e-10);
- Assert.assertEquals(v.getZ().getReal(), out[2].getReal(), 1.0e-10);
- r.applyInverseTo(out, out);
- Assert.assertEquals(u.getX().getReal(), out[0].getReal(), 1.0e-10);
- Assert.assertEquals(u.getY().getReal(), out[1].getReal(), 1.0e-10);
- Assert.assertEquals(u.getZ().getReal(), out[2].getReal(), 1.0e-10);
- }
- }
- }
-
- }
-
- @Test
- public void testApplyInverseTo() throws MathIllegalArgumentException {
-
- DerivativeStructure[] in = new DerivativeStructure[3];
- DerivativeStructure[] out = new DerivativeStructure[3];
- DerivativeStructure[] rebuilt = new DerivativeStructure[3];
- FieldRotation<DerivativeStructure> r = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- for (double lambda = 0; lambda < 6.2; lambda += 0.2) {
- for (double phi = -1.55; phi < 1.55; phi += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(FastMath.cos(lambda) * FastMath.cos(phi),
- FastMath.sin(lambda) * FastMath.cos(phi),
- FastMath.sin(phi));
- r.applyInverseTo(r.applyTo(u));
- checkVector(u, r.applyInverseTo(r.applyTo(u)));
- checkVector(u, r.applyTo(r.applyInverseTo(u)));
- in[0] = u.getX();
- in[1] = u.getY();
- in[2] = u.getZ();
- r.applyTo(in, out);
- r.applyInverseTo(out, rebuilt);
- Assert.assertEquals(in[0].getReal(), rebuilt[0].getReal(), 1.0e-12);
- Assert.assertEquals(in[1].getReal(), rebuilt[1].getReal(), 1.0e-12);
- Assert.assertEquals(in[2].getReal(), rebuilt[2].getReal(), 1.0e-12);
- }
- }
-
- r = createRotation(1, 0, 0, 0, false);
- for (double lambda = 0; lambda < 6.2; lambda += 0.2) {
- for (double phi = -1.55; phi < 1.55; phi += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(FastMath.cos(lambda) * FastMath.cos(phi),
- FastMath.sin(lambda) * FastMath.cos(phi),
- FastMath.sin(phi));
- checkVector(u, r.applyInverseTo(r.applyTo(u)));
- checkVector(u, r.applyTo(r.applyInverseTo(u)));
- }
- }
-
- r = new FieldRotation<>(createVector(0, 0, 1),
- createAngle(FastMath.PI),
- RotationConvention.VECTOR_OPERATOR);
- for (double lambda = 0; lambda < 6.2; lambda += 0.2) {
- for (double phi = -1.55; phi < 1.55; phi += 0.2) {
- FieldVector3D<DerivativeStructure> u = createVector(FastMath.cos(lambda) * FastMath.cos(phi),
- FastMath.sin(lambda) * FastMath.cos(phi),
- FastMath.sin(phi));
- checkVector(u, r.applyInverseTo(r.applyTo(u)));
- checkVector(u, r.applyTo(r.applyInverseTo(u)));
- }
- }
-
- }
-
- @Test
- public void testIssue639() throws MathArithmeticException{
- FieldVector3D<DerivativeStructure> u1 = createVector(-1321008684645961.0 / 268435456.0,
- -5774608829631843.0 / 268435456.0,
- -3822921525525679.0 / 4294967296.0);
- FieldVector3D<DerivativeStructure> u2 =createVector( -5712344449280879.0 / 2097152.0,
- -2275058564560979.0 / 1048576.0,
- 4423475992255071.0 / 65536.0);
- FieldRotation<DerivativeStructure> rot = new FieldRotation<>(u1, u2, createVector(1, 0, 0),createVector(0, 0, 1));
- Assert.assertEquals( 0.6228370359608200639829222, rot.getQ0().getReal(), 1.0e-15);
- Assert.assertEquals( 0.0257707621456498790029987, rot.getQ1().getReal(), 1.0e-15);
- Assert.assertEquals(-0.0000000002503012255839931, rot.getQ2().getReal(), 1.0e-15);
- Assert.assertEquals(-0.7819270390861109450724902, rot.getQ3().getReal(), 1.0e-15);
- }
-
- @Test
- public void testIssue801() throws MathArithmeticException {
- FieldVector3D<DerivativeStructure> u1 = createVector(0.9999988431610581, -0.0015210774290851095, 0.0);
- FieldVector3D<DerivativeStructure> u2 = createVector(0.0, 0.0, 1.0);
-
- FieldVector3D<DerivativeStructure> v1 = createVector(0.9999999999999999, 0.0, 0.0);
- FieldVector3D<DerivativeStructure> v2 = createVector(0.0, 0.0, -1.0);
-
- FieldRotation<DerivativeStructure> quat = new FieldRotation<>(u1, u2, v1, v2);
- double q2 = quat.getQ0().getReal() * quat.getQ0().getReal() +
- quat.getQ1().getReal() * quat.getQ1().getReal() +
- quat.getQ2().getReal() * quat.getQ2().getReal() +
- quat.getQ3().getReal() * quat.getQ3().getReal();
- Assert.assertEquals(1.0, q2, 1.0e-14);
- Assert.assertEquals(0.0, FieldVector3D.angle(v1, quat.applyTo(u1)).getReal(), 1.0e-14);
- Assert.assertEquals(0.0, FieldVector3D.angle(v2, quat.applyTo(u2)).getReal(), 1.0e-14);
-
- }
-
- private void checkAngle(DerivativeStructure a1, double a2) {
- Assert.assertEquals(a1.getReal(), PlaneAngleRadians.normalize(a2, a1.getReal()), 1.0e-10);
- }
-
- private void checkRotationDS(FieldRotation<DerivativeStructure> r, double q0, double q1, double q2, double q3) {
- FieldRotation<DerivativeStructure> rPrime = createRotation(q0, q1, q2, q3, false);
- Assert.assertEquals(0, FieldRotation.distance(r, rPrime).getReal(), 1.0e-12);
- }
-
- private FieldRotation<DerivativeStructure> createRotation(double q0, double q1, double q2, double q3,
- boolean needsNormalization) {
- return new FieldRotation<>(new DerivativeStructure(4, 1, 0, q0),
- new DerivativeStructure(4, 1, 1, q1),
- new DerivativeStructure(4, 1, 2, q2),
- new DerivativeStructure(4, 1, 3, q3),
- needsNormalization);
- }
-
- private FieldRotation<DerivativeStructure> createRotation(double[][] m, double threshold) {
- DerivativeStructure[][] mds = new DerivativeStructure[m.length][m[0].length];
- int index = 0;
- for (int i = 0; i < m.length; ++i) {
- for (int j = 0; j < m[i].length; ++j) {
- mds[i][j] = new DerivativeStructure(4, 1, index, m[i][j]);
- index = (index + 1) % 4;
- }
- }
- return new FieldRotation<>(mds, threshold);
- }
-
- private FieldVector3D<DerivativeStructure> createVector(double x, double y, double z) {
- return new FieldVector3D<>(new DerivativeStructure(4, 1, x),
- new DerivativeStructure(4, 1, y),
- new DerivativeStructure(4, 1, z));
- }
-
- private FieldVector3D<DerivativeStructure> createAxis(double x, double y, double z) {
- return new FieldVector3D<>(new DerivativeStructure(4, 1, 0, x),
- new DerivativeStructure(4, 1, 1, y),
- new DerivativeStructure(4, 1, 2, z));
- }
-
- private DerivativeStructure createAngle(double alpha) {
- return new DerivativeStructure(4, 1, 3, alpha);
- }
-
- private void checkVector(FieldVector3D<DerivativeStructure> u, FieldVector3D<DerivativeStructure> v) {
- Assert.assertEquals(u.getX().getReal(), v.getX().getReal(), 1.0e-12);
- Assert.assertEquals(u.getY().getReal(), v.getY().getReal(), 1.0e-12);
- Assert.assertEquals(u.getZ().getReal(), v.getZ().getReal(), 1.0e-12);
- }
-
-}
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java
deleted file mode 100644
index 3bda1c4..0000000
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java
+++ /dev/null
@@ -1,1038 +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.threed;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.apache.commons.numbers.angle.PlaneAngleRadians;
-import org.apache.commons.numbers.quaternion.Quaternion;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.simple.RandomSource;
-import org.apache.commons.rng.sampling.UnitSphereSampler;
-import org.apache.commons.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.geometry.euclidean.threed.rotation.QuaternionRotation;
-import org.apache.commons.math4.dfp.Dfp;
-import org.apache.commons.math4.dfp.DfpField;
-import org.apache.commons.math4.exception.MathArithmeticException;
-import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.geometry.euclidean.threed.CardanEulerSingularityException;
-import org.apache.commons.math4.geometry.euclidean.threed.FieldRotation;
-import org.apache.commons.math4.geometry.euclidean.threed.FieldVector3D;
-import org.apache.commons.math4.geometry.euclidean.threed.NotARotationMatrixException;
-import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder;
-import org.apache.commons.math4.util.FastMath;
-
-public class FieldRotationDfpTest {
-
- @Test
- public void testIdentity() {
-
- FieldRotation<Dfp> r = createRotation(1, 0, 0, 0, false);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(1, 0, 0));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(0, 1, 0));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(0, 0, 1));
- checkAngle(r.getAngle(), 0);
-
- r = createRotation(-1, 0, 0, 0, false);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(1, 0, 0));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(0, 1, 0));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(0, 0, 1));
- checkAngle(r.getAngle(), 0);
-
- r = createRotation(42, 0, 0, 0, true);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(1, 0, 0));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(0, 1, 0));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(0, 0, 1));
- checkAngle(r.getAngle(), 0);
-
- }
-
- @Test
- @Deprecated
- public void testAxisAngleDeprecated() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r = new FieldRotation<>(createAxis(10, 10, 10), createAngle(2 * FastMath.PI / 3));
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(0, 1, 0));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(0, 0, 1));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(1, 0, 0));
- double s = 1 / FastMath.sqrt(3);
- checkVector(r.getAxis(), createVector(s, s, s));
- checkAngle(r.getAngle(), 2 * FastMath.PI / 3);
-
- try {
- new FieldRotation<>(createAxis(0, 0, 0), createAngle(2 * FastMath.PI / 3));
- Assert.fail("an exception should have been thrown");
- } catch (MathIllegalArgumentException e) {
- }
-
- r = new FieldRotation<>(createAxis(0, 0, 1), createAngle(1.5 * FastMath.PI));
- checkVector(r.getAxis(), createVector(0, 0, -1));
- checkAngle(r.getAngle(), 0.5 * FastMath.PI);
-
- r = new FieldRotation<>(createAxis(0, 1, 0), createAngle(FastMath.PI));
- checkVector(r.getAxis(), createVector(0, 1, 0));
- checkAngle(r.getAngle(), FastMath.PI);
-
- checkVector(createRotation(1, 0, 0, 0, false).getAxis(), createVector(1, 0, 0));
-
- }
-
- @Test
- public void testAxisAngleVectorOperator() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r = new FieldRotation<>(createAxis(10, 10, 10),
- createAngle(2 * FastMath.PI / 3) ,
- RotationConvention.VECTOR_OPERATOR);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(0, 1, 0));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(0, 0, 1));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(1, 0, 0));
- double s = 1 / FastMath.sqrt(3);
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector( s, s, s));
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector(-s, -s, -s));
- checkAngle(r.getAngle(), 2 * FastMath.PI / 3);
-
- try {
- new FieldRotation<>(createAxis(0, 0, 0),
- createAngle(2 * FastMath.PI / 3),
- RotationConvention.VECTOR_OPERATOR);
- Assert.fail("an exception should have been thrown");
- } catch (MathIllegalArgumentException e) {
- }
-
- r = new FieldRotation<>(createAxis(0, 0, 1),
- createAngle(1.5 * FastMath.PI),
- RotationConvention.VECTOR_OPERATOR);
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector(0, 0, -1));
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector(0, 0, +1));
- checkAngle(r.getAngle(), 0.5 * FastMath.PI);
-
- r = new FieldRotation<>(createAxis(0, 1, 0),
- createAngle(FastMath.PI),
- RotationConvention.VECTOR_OPERATOR);
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector(0, +1, 0));
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector(0, -1, 0));
- checkAngle(r.getAngle(), FastMath.PI);
-
- checkVector(createRotation(1, 0, 0, 0, false).getAxis(RotationConvention.VECTOR_OPERATOR), createVector(+1, 0, 0));
- checkVector(createRotation(1, 0, 0, 0, false).getAxis(RotationConvention.FRAME_TRANSFORM), createVector(-1, 0, 0));
-
- }
-
- @Test
- public void testAxisAngleFrameTransform() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r = new FieldRotation<>(createAxis(10, 10, 10),
- createAngle(2 * FastMath.PI / 3) ,
- RotationConvention.FRAME_TRANSFORM);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(0, 0, 1));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(1, 0, 0));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(0, 1, 0));
- double s = 1 / FastMath.sqrt(3);
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector( s, s, s));
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector(-s, -s, -s));
- checkAngle(r.getAngle(), 2 * FastMath.PI / 3);
-
- try {
- new FieldRotation<>(createAxis(0, 0, 0),
- createAngle(2 * FastMath.PI / 3),
- RotationConvention.FRAME_TRANSFORM);
- Assert.fail("an exception should have been thrown");
- } catch (MathIllegalArgumentException e) {
- }
-
- r = new FieldRotation<>(createAxis(0, 0, 1),
- createAngle(1.5 * FastMath.PI),
- RotationConvention.FRAME_TRANSFORM);
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector(0, 0, -1));
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector(0, 0, +1));
- checkAngle(r.getAngle(), 0.5 * FastMath.PI);
-
- r = new FieldRotation<>(createAxis(0, 1, 0),
- createAngle(FastMath.PI),
- RotationConvention.FRAME_TRANSFORM);
- checkVector(r.getAxis(RotationConvention.FRAME_TRANSFORM), createVector(0, +1, 0));
- checkVector(r.getAxis(RotationConvention.VECTOR_OPERATOR), createVector(0, -1, 0));
- checkAngle(r.getAngle(), FastMath.PI);
-
- checkVector(createRotation(1, 0, 0, 0, false).getAxis(RotationConvention.FRAME_TRANSFORM), createVector(-1, 0, 0));
- checkVector(createRotation(1, 0, 0, 0, false).getAxis(RotationConvention.VECTOR_OPERATOR), createVector(+1, 0, 0));
-
- }
-
- @Test
- public void testRevert() {
- double a = 0.001;
- double b = 0.36;
- double c = 0.48;
- double d = 0.8;
- FieldRotation<Dfp> r = createRotation(a, b, c, d, true);
- FieldRotation<Dfp> reverted = r.revert();
- FieldRotation<Dfp> rrT = r.applyTo(reverted);
- checkRotationDS(rrT, 1, 0, 0, 0);
- FieldRotation<Dfp> rTr = reverted.applyTo(r);
- checkRotationDS(rTr, 1, 0, 0, 0);
- Assert.assertEquals(r.getAngle().getReal(), reverted.getAngle().getReal(), 1.0e-15);
- Assert.assertEquals(-1,
- FieldVector3D.dotProduct(r.getAxis(RotationConvention.VECTOR_OPERATOR),
- reverted.getAxis(RotationConvention.VECTOR_OPERATOR)).getReal(),
- 1.0e-15);
- }
-
- @Test
- public void testRevertVectorOperator() {
- double a = 0.001;
- double b = 0.36;
- double c = 0.48;
- double d = 0.8;
- FieldRotation<Dfp> r = createRotation(a, b, c, d, true);
- FieldRotation<Dfp> reverted = r.revert();
- FieldRotation<Dfp> rrT = r.compose(reverted, RotationConvention.VECTOR_OPERATOR);
- checkRotationDS(rrT, 1, 0, 0, 0);
- FieldRotation<Dfp> rTr = reverted.compose(r, RotationConvention.VECTOR_OPERATOR);
- checkRotationDS(rTr, 1, 0, 0, 0);
- Assert.assertEquals(r.getAngle().getReal(), reverted.getAngle().getReal(), 1.0e-15);
- Assert.assertEquals(-1,
- FieldVector3D.dotProduct(r.getAxis(RotationConvention.VECTOR_OPERATOR),
- reverted.getAxis(RotationConvention.VECTOR_OPERATOR)).getReal(),
- 1.0e-15);
- }
-
- @Test
- public void testRevertFrameTransform() {
- double a = 0.001;
- double b = 0.36;
- double c = 0.48;
- double d = 0.8;
- FieldRotation<Dfp> r = createRotation(a, b, c, d, true);
- FieldRotation<Dfp> reverted = r.revert();
- FieldRotation<Dfp> rrT = r.compose(reverted, RotationConvention.FRAME_TRANSFORM);
- checkRotationDS(rrT, 1, 0, 0, 0);
- FieldRotation<Dfp> rTr = reverted.compose(r, RotationConvention.FRAME_TRANSFORM);
- checkRotationDS(rTr, 1, 0, 0, 0);
- Assert.assertEquals(r.getAngle().getReal(), reverted.getAngle().getReal(), 1.0e-15);
- Assert.assertEquals(-1,
- FieldVector3D.dotProduct(r.getAxis(RotationConvention.FRAME_TRANSFORM),
- reverted.getAxis(RotationConvention.FRAME_TRANSFORM)).getReal(),
- 1.0e-15);
- }
-
- @Test
- public void testVectorOnePair() throws MathArithmeticException {
-
- FieldVector3D<Dfp> u = createVector(3, 2, 1);
- FieldVector3D<Dfp> v = createVector(-4, 2, 2);
- FieldRotation<Dfp> r = new FieldRotation<>(u, v);
- checkVector(r.applyTo(u.scalarMultiply(v.getNorm())), v.scalarMultiply(u.getNorm()));
-
- checkAngle(new FieldRotation<>(u, u.negate()).getAngle(), FastMath.PI);
-
- try {
- new FieldRotation<>(u, createVector(0, 0, 0));
- Assert.fail("an exception should have been thrown");
- } catch (MathArithmeticException e) {
- // expected behavior
- }
-
- }
-
- @Test
- public void testVectorTwoPairs() throws MathArithmeticException {
-
- FieldVector3D<Dfp> u1 = createVector(3, 0, 0);
- FieldVector3D<Dfp> u2 = createVector(0, 5, 0);
- FieldVector3D<Dfp> v1 = createVector(0, 0, 2);
- FieldVector3D<Dfp> v2 = createVector(-2, 0, 2);
- FieldRotation<Dfp> r = new FieldRotation<>(u1, u2, v1, v2);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(0, 0, 1));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(-1, 0, 0));
-
- r = new FieldRotation<>(u1, u2, u1.negate(), u2.negate());
- FieldVector3D<Dfp> axis = r.getAxis(RotationConvention.VECTOR_OPERATOR);
- if (FieldVector3D.dotProduct(axis, createVector(0, 0, 1)).getReal() > 0) {
- checkVector(axis, createVector(0, 0, 1));
- } else {
- checkVector(axis, createVector(0, 0, -1));
- }
- checkAngle(r.getAngle(), FastMath.PI);
-
- double sqrt = FastMath.sqrt(2) / 2;
- r = new FieldRotation<>(createVector(1, 0, 0), createVector(0, 1, 0),
- createVector(0.5, 0.5, sqrt),
- createVector(0.5, 0.5, -sqrt));
- checkRotationDS(r, sqrt, 0.5, 0.5, 0);
-
- r = new FieldRotation<>(u1, u2, u1, FieldVector3D.crossProduct(u1, u2));
- checkRotationDS(r, sqrt, -sqrt, 0, 0);
-
- checkRotationDS(new FieldRotation<>(u1, u2, u1, u2), 1, 0, 0, 0);
-
- try {
- new FieldRotation<>(u1, u2, createVector(0, 0, 0), v2);
- Assert.fail("an exception should have been thrown");
- } catch (MathArithmeticException e) {
- // expected behavior
- }
-
- }
-
- @Test
- public void testMatrix()
- throws NotARotationMatrixException {
-
- try {
- createRotation(new double[][] {
- { 0.0, 1.0, 0.0 },
- { 1.0, 0.0, 0.0 }
- }, 1.0e-7);
- Assert.fail("Expecting NotARotationMatrixException");
- } catch (NotARotationMatrixException nrme) {
- // expected behavior
- }
-
- try {
- createRotation(new double[][] {
- { 0.445888, 0.797184, -0.407040 },
- { 0.821760, -0.184320, 0.539200 },
- { -0.354816, 0.574912, 0.737280 }
- }, 1.0e-7);
- Assert.fail("Expecting NotARotationMatrixException");
- } catch (NotARotationMatrixException nrme) {
- // expected behavior
- }
-
- try {
- createRotation(new double[][] {
- { 0.4, 0.8, -0.4 },
- { -0.4, 0.6, 0.7 },
- { 0.8, -0.2, 0.5 }
- }, 1.0e-15);
- Assert.fail("Expecting NotARotationMatrixException");
- } catch (NotARotationMatrixException nrme) {
- // expected behavior
- }
-
- checkRotationDS(createRotation(new double[][] {
- { 0.445888, 0.797184, -0.407040 },
- { -0.354816, 0.574912, 0.737280 },
- { 0.821760, -0.184320, 0.539200 }
- }, 1.0e-10),
- 0.8, 0.288, 0.384, 0.36);
-
- checkRotationDS(createRotation(new double[][] {
- { 0.539200, 0.737280, 0.407040 },
- { 0.184320, -0.574912, 0.797184 },
- { 0.821760, -0.354816, -0.445888 }
- }, 1.0e-10),
- 0.36, 0.8, 0.288, 0.384);
-
- checkRotationDS(createRotation(new double[][] {
- { -0.445888, 0.797184, -0.407040 },
- { 0.354816, 0.574912, 0.737280 },
- { 0.821760, 0.184320, -0.539200 }
- }, 1.0e-10),
- 0.384, 0.36, 0.8, 0.288);
-
- checkRotationDS(createRotation(new double[][] {
- { -0.539200, 0.737280, 0.407040 },
- { -0.184320, -0.574912, 0.797184 },
- { 0.821760, 0.354816, 0.445888 }
- }, 1.0e-10),
- 0.288, 0.384, 0.36, 0.8);
-
- double[][] m1 = { { 0.0, 1.0, 0.0 },
- { 0.0, 0.0, 1.0 },
- { 1.0, 0.0, 0.0 } };
- FieldRotation<Dfp> r = createRotation(m1, 1.0e-7);
- checkVector(r.applyTo(createVector(1, 0, 0)), createVector(0, 0, 1));
- checkVector(r.applyTo(createVector(0, 1, 0)), createVector(1, 0, 0));
- checkVector(r.applyTo(createVector(0, 0, 1)), createVector(0, 1, 0));
-
- double[][] m2 = { { 0.83203, -0.55012, -0.07139 },
- { 0.48293, 0.78164, -0.39474 },
- { 0.27296, 0.29396, 0.91602 } };
- r = createRotation(m2, 1.0e-12);
-
- Dfp[][] m3 = r.getMatrix();
- double d00 = m2[0][0] - m3[0][0].getReal();
- double d01 = m2[0][1] - m3[0][1].getReal();
- double d02 = m2[0][2] - m3[0][2].getReal();
- double d10 = m2[1][0] - m3[1][0].getReal();
- double d11 = m2[1][1] - m3[1][1].getReal();
- double d12 = m2[1][2] - m3[1][2].getReal();
- double d20 = m2[2][0] - m3[2][0].getReal();
- double d21 = m2[2][1] - m3[2][1].getReal();
- double d22 = m2[2][2] - m3[2][2].getReal();
-
- Assert.assertTrue(FastMath.abs(d00) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d01) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d02) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d10) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d11) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d12) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d20) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d21) < 6.0e-6);
- Assert.assertTrue(FastMath.abs(d22) < 6.0e-6);
-
- Assert.assertTrue(FastMath.abs(d00) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d01) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d02) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d10) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d11) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d12) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d20) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d21) > 4.0e-7);
- Assert.assertTrue(FastMath.abs(d22) > 4.0e-7);
-
- for (int i = 0; i < 3; ++i) {
- for (int j = 0; j < 3; ++j) {
- double m3tm3 = m3[i][0].getReal() * m3[j][0].getReal() +
- m3[i][1].getReal() * m3[j][1].getReal() +
- m3[i][2].getReal() * m3[j][2].getReal();
- if (i == j) {
- Assert.assertTrue(FastMath.abs(m3tm3 - 1.0) < 1.0e-10);
- } else {
- Assert.assertTrue(FastMath.abs(m3tm3) < 1.0e-10);
- }
- }
- }
-
- checkVector(r.applyTo(createVector(1, 0, 0)),
- new FieldVector3D<>(m3[0][0], m3[1][0], m3[2][0]));
- checkVector(r.applyTo(createVector(0, 1, 0)),
- new FieldVector3D<>(m3[0][1], m3[1][1], m3[2][1]));
- checkVector(r.applyTo(createVector(0, 0, 1)),
- new FieldVector3D<>(m3[0][2], m3[1][2], m3[2][2]));
-
- double[][] m4 = { { 1.0, 0.0, 0.0 },
- { 0.0, -1.0, 0.0 },
- { 0.0, 0.0, -1.0 } };
- r = createRotation(m4, 1.0e-7);
- checkAngle(r.getAngle(), FastMath.PI);
-
- try {
- double[][] m5 = { { 0.0, 0.0, 1.0 },
- { 0.0, 1.0, 0.0 },
- { 1.0, 0.0, 0.0 } };
- r = createRotation(m5, 1.0e-7);
- Assert.fail("got " + r + ", should have caught an exception");
- } catch (NotARotationMatrixException e) {
- // expected
- }
-
- }
-
- @Test
- @Deprecated
- public void testAnglesDeprecated()
- throws CardanEulerSingularityException {
-
- DfpField field = new DfpField(15);
-
- RotationOrder[] CardanOrders = {
- RotationOrder.XYZ, RotationOrder.XZY, RotationOrder.YXZ,
- RotationOrder.YZX, RotationOrder.ZXY, RotationOrder.ZYX
- };
-
- for (int i = 0; i < CardanOrders.length; ++i) {
- for (double alpha1 = 0.1; alpha1 < 6.2; alpha1 += 2.0) {
- for (double alpha2 = -1.55; alpha2 < 1.55; alpha2 += 0.8) {
- for (double alpha3 = 0.1; alpha3 < 6.2; alpha3 += 2.0) {
- FieldRotation<Dfp> r = new FieldRotation<>(CardanOrders[i],
- field.newDfp(alpha1),
- field.newDfp(alpha2),
- field.newDfp(alpha3));
- Dfp[] angles = r.getAngles(CardanOrders[i]);
- checkAngle(angles[0], alpha1);
- checkAngle(angles[1], alpha2);
- checkAngle(angles[2], alpha3);
- }
- }
- }
- }
-
- RotationOrder[] EulerOrders = {
- RotationOrder.XYX, RotationOrder.XZX, RotationOrder.YXY,
- RotationOrder.YZY, RotationOrder.ZXZ, RotationOrder.ZYZ
- };
-
- for (int i = 0; i < EulerOrders.length; ++i) {
- for (double alpha1 = 0.1; alpha1 < 6.2; alpha1 += 2.0) {
- for (double alpha2 = 0.05; alpha2 < 3.1; alpha2 += 0.8) {
- for (double alpha3 = 0.1; alpha3 < 6.2; alpha3 += 2.0) {
- FieldRotation<Dfp> r = new FieldRotation<>(EulerOrders[i],
- field.newDfp(alpha1),
- field.newDfp(alpha2),
- field.newDfp(alpha3));
- Dfp[] angles = r.getAngles(EulerOrders[i]);
- checkAngle(angles[0], alpha1);
- checkAngle(angles[1], alpha2);
- checkAngle(angles[2], alpha3);
- }
- }
- }
- }
-
- }
-
- @Test
- public void testAngles()
- throws CardanEulerSingularityException {
-
- DfpField field = new DfpField(15);
-
- for (RotationConvention convention : RotationConvention.values()) {
- RotationOrder[] CardanOrders = {
- RotationOrder.XYZ, RotationOrder.XZY, RotationOrder.YXZ,
- RotationOrder.YZX, RotationOrder.ZXY, RotationOrder.ZYX
- };
-
- for (int i = 0; i < CardanOrders.length; ++i) {
- for (double alpha1 = 0.1; alpha1 < 6.2; alpha1 += 2.0) {
- for (double alpha2 = -1.55; alpha2 < 1.55; alpha2 += 0.8) {
- for (double alpha3 = 0.1; alpha3 < 6.2; alpha3 += 2.0) {
- FieldRotation<Dfp> r = new FieldRotation<>(CardanOrders[i],
- convention,
- field.newDfp(alpha1),
- field.newDfp(alpha2),
- field.newDfp(alpha3));
- Dfp[] angles = r.getAngles(CardanOrders[i], convention);
- checkAngle(angles[0], alpha1);
- checkAngle(angles[1], alpha2);
- checkAngle(angles[2], alpha3);
- }
- }
- }
- }
-
- RotationOrder[] EulerOrders = {
- RotationOrder.XYX, RotationOrder.XZX, RotationOrder.YXY,
- RotationOrder.YZY, RotationOrder.ZXZ, RotationOrder.ZYZ
- };
-
- for (int i = 0; i < EulerOrders.length; ++i) {
- for (double alpha1 = 0.1; alpha1 < 6.2; alpha1 += 2.0) {
- for (double alpha2 = 0.05; alpha2 < 3.1; alpha2 += 0.8) {
- for (double alpha3 = 0.1; alpha3 < 6.2; alpha3 += 2.0) {
- FieldRotation<Dfp> r = new FieldRotation<>(EulerOrders[i],
- convention,
- field.newDfp(alpha1),
- field.newDfp(alpha2),
- field.newDfp(alpha3));
- Dfp[] angles = r.getAngles(EulerOrders[i], convention);
- checkAngle(angles[0], alpha1);
- checkAngle(angles[1], alpha2);
- checkAngle(angles[2], alpha3);
- }
- }
- }
- }
- }
-
- }
-
- @Test
- public void testSingularities() {
-
- DfpField field = new DfpField(20);
- for (RotationConvention convention : RotationConvention.values()) {
- RotationOrder[] CardanOrders = {
- RotationOrder.XYZ, RotationOrder.XZY, RotationOrder.YXZ,
- RotationOrder.YZX, RotationOrder.ZXY, RotationOrder.ZYX
- };
-
- double[] singularCardanAngle = { FastMath.PI / 2, -FastMath.PI / 2 };
- for (int i = 0; i < CardanOrders.length; ++i) {
- for (int j = 0; j < singularCardanAngle.length; ++j) {
- FieldRotation<Dfp> r = new FieldRotation<>(CardanOrders[i],
- convention,
- field.newDfp(0.1),
- field.newDfp(singularCardanAngle[j]),
- field.newDfp(0.3));
- try {
- r.getAngles(CardanOrders[i], convention);
- Assert.fail("an exception should have been caught");
- } catch (CardanEulerSingularityException cese) {
- // expected behavior
- }
- }
- }
-
- RotationOrder[] EulerOrders = {
- RotationOrder.XYX, RotationOrder.XZX, RotationOrder.YXY,
- RotationOrder.YZY, RotationOrder.ZXZ, RotationOrder.ZYZ
- };
-
- double[] singularEulerAngle = { 0, FastMath.PI };
- for (int i = 0; i < EulerOrders.length; ++i) {
- for (int j = 0; j < singularEulerAngle.length; ++j) {
- FieldRotation<Dfp> r = new FieldRotation<>(EulerOrders[i],
- convention,
- field.newDfp(0.1),
- field.newDfp(singularEulerAngle[j]),
- field.newDfp(0.3));
- try {
- r.getAngles(EulerOrders[i], convention);
- Assert.fail("an exception should have been caught");
- } catch (CardanEulerSingularityException cese) {
- // expected behavior
- }
- }
- }
-
- }
- }
-
- @Test
- public void testQuaternion() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- double n = 23.5;
- FieldRotation<Dfp> r2 = new FieldRotation<>(r1.getQ0().multiply(n), r1.getQ1().multiply(n),
- r1.getQ2().multiply(n), r1.getQ3().multiply(n),
- true);
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<Dfp> u = createVector(x, y, z);
- checkVector(r2.applyTo(u), r1.applyTo(u));
- }
- }
- }
-
- r1 = createRotation(0.288, 0.384, 0.36, 0.8, false);
- checkRotationDS(r1,
- -r1.getQ0().getReal(), -r1.getQ1().getReal(),
- -r1.getQ2().getReal(), -r1.getQ3().getReal());
-
- }
-
- @Test
- public void testApplyToRotation() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> r3 = r2.applyTo(r1);
- FieldRotation<Dfp> r3Double = r2.applyTo(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()));
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<Dfp> u = createVector(x, y, z);
- checkVector(r2.applyTo(r1.applyTo(u)), r3.applyTo(u));
- checkVector(r2.applyTo(r1.applyTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testComposeVectorOperator() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> r3 = r2.compose(r1, RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> r3Double = r2.compose(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()),
- RotationConvention.VECTOR_OPERATOR);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<Dfp> u = createVector(x, y, z);
- checkVector(r2.applyTo(r1.applyTo(u)), r3.applyTo(u));
- checkVector(r2.applyTo(r1.applyTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testComposeFrameTransform() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.FRAME_TRANSFORM);
- FieldRotation<Dfp> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.FRAME_TRANSFORM);
- FieldRotation<Dfp> r3 = r2.compose(r1, RotationConvention.FRAME_TRANSFORM);
- FieldRotation<Dfp> r3Double = r2.compose(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()),
- RotationConvention.FRAME_TRANSFORM);
- FieldRotation<Dfp> r4 = r1.compose(r2, RotationConvention.VECTOR_OPERATOR);
- Assert.assertEquals(0.0, FieldRotation.distance(r3, r4).getReal(), 1.0e-15);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<Dfp> u = createVector(x, y, z);
- checkVector(r1.applyTo(r2.applyTo(u)), r3.applyTo(u));
- checkVector(r1.applyTo(r2.applyTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testApplyInverseToRotation() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> r3 = r2.applyInverseTo(r1);
- FieldRotation<Dfp> r3Double = r2.applyInverseTo(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()));
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<Dfp> u = createVector(x, y, z);
- checkVector(r2.applyInverseTo(r1.applyTo(u)), r3.applyTo(u));
- checkVector(r2.applyInverseTo(r1.applyTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testComposeInverseVectorOperator() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> r3 = r2.composeInverse(r1, RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> r3Double = r2.composeInverse(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()),
- RotationConvention.VECTOR_OPERATOR);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<Dfp> u = createVector(x, y, z);
- checkVector(r2.applyInverseTo(r1.applyTo(u)), r3.applyTo(u));
- checkVector(r2.applyInverseTo(r1.applyTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testComposeInverseFrameTransform() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r1 = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.FRAME_TRANSFORM);
- FieldRotation<Dfp> r2 = new FieldRotation<>(createVector(-1, 3, 2),
- createAngle(0.3),
- RotationConvention.FRAME_TRANSFORM);
- FieldRotation<Dfp> r3 = r2.composeInverse(r1, RotationConvention.FRAME_TRANSFORM);
- FieldRotation<Dfp> r3Double = r2.composeInverse(QuaternionRotation.of(r1.getQ0().getReal(),
- r1.getQ1().getReal(),
- r1.getQ2().getReal(),
- r1.getQ3().getReal()),
- RotationConvention.FRAME_TRANSFORM);
- FieldRotation<Dfp> r4 = r1.revert().composeInverse(r2.revert(), RotationConvention.VECTOR_OPERATOR);
- Assert.assertEquals(0.0, FieldRotation.distance(r3, r4).getReal(), 1.0e-15);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<Dfp> u = createVector(x, y, z);
- checkVector(r1.applyTo(r2.applyInverseTo(u)), r3.applyTo(u));
- checkVector(r1.applyTo(r2.applyInverseTo(u)), r3Double.applyTo(u));
- }
- }
- }
-
- }
-
- @Test
- public void testDoubleVectors() throws MathIllegalArgumentException {
- UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
- 0x180b41cfeeffaf67l);
- UnitSphereSampler g = new UnitSphereSampler(3, random);
- for (int i = 0; i < 10; ++i) {
- double[] unit = g.nextVector();
- FieldRotation<Dfp> r = new FieldRotation<>(createVector(unit[0], unit[1], unit[2]),
- createAngle(random.nextDouble()),
- RotationConvention.VECTOR_OPERATOR);
-
- for (double x = -0.9; x < 0.9; x += 0.4) {
- for (double y = -0.9; y < 0.9; y += 0.4) {
- for (double z = -0.9; z < 0.9; z += 0.4) {
- FieldVector3D<Dfp> uds = createVector(x, y, z);
- FieldVector3D<Dfp> ruds = r.applyTo(uds);
- FieldVector3D<Dfp> rIuds = r.applyInverseTo(uds);
- Vector3D u = Vector3D.of(x, y, z);
- FieldVector3D<Dfp> ru = r.applyTo(u);
- FieldVector3D<Dfp> rIu = r.applyInverseTo(u);
- Dfp[] ruArray = new Dfp[3];
- r.applyTo(new double[] { x, y, z}, ruArray);
- Dfp[] rIuArray = new Dfp[3];
- r.applyInverseTo(new double[] { x, y, z}, rIuArray);
- checkVector(ruds, ru);
- checkVector(ruds, new FieldVector3D<>(ruArray));
- checkVector(rIuds, rIu);
- checkVector(rIuds, new FieldVector3D<>(rIuArray));
- }
- }
- }
- }
- }
-
- @Test
- public void testDoubleRotations() throws MathIllegalArgumentException {
- UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
- 0x180b41cfeeffaf67l);
- DfpField field = new DfpField(20);
- UnitSphereSampler g = new UnitSphereSampler(3, random);
- for (int i = 0; i < 10; ++i) {
- double[] unit1 = g.nextVector();
- QuaternionRotation r1 = QuaternionRotation.of(random.nextDouble(),
- unit1[0], unit1[1], unit1[2]);
- final Quaternion r1Quat = r1.getQuaternion();
- FieldRotation<Dfp> r1Prime = new FieldRotation<>(field.newDfp(r1Quat.getW()),
- field.newDfp(r1Quat.getX()),
- field.newDfp(r1Quat.getY()),
- field.newDfp(r1Quat.getZ()),
- false);
- double[] unit2 = g.nextVector();
- FieldRotation<Dfp> r2 = new FieldRotation<>(createVector(unit2[0], unit2[1], unit2[2]),
- createAngle(random.nextDouble()),
- RotationConvention.VECTOR_OPERATOR);
-
- FieldRotation<Dfp> rA = FieldRotation.applyTo(r1, r2);
- FieldRotation<Dfp> rB = r1Prime.compose(r2, RotationConvention.VECTOR_OPERATOR);
- FieldRotation<Dfp> rC = FieldRotation.applyInverseTo(r1, r2);
- FieldRotation<Dfp> rD = r1Prime.composeInverse(r2, RotationConvention.VECTOR_OPERATOR);
-
- for (double x = -0.9; x < 0.9; x += 0.4) {
- for (double y = -0.9; y < 0.9; y += 0.4) {
- for (double z = -0.9; z < 0.9; z += 0.4) {
-
- FieldVector3D<Dfp> uds = createVector(x, y, z);
- checkVector(r1Prime.applyTo(uds), FieldRotation.applyTo(r1, uds));
- checkVector(r1Prime.applyInverseTo(uds), FieldRotation.applyInverseTo(r1, uds));
- checkVector(rA.applyTo(uds), rB.applyTo(uds));
- checkVector(rA.applyInverseTo(uds), rB.applyInverseTo(uds));
- checkVector(rC.applyTo(uds), rD.applyTo(uds));
- checkVector(rC.applyInverseTo(uds), rD.applyInverseTo(uds));
-
- }
- }
- }
- }
-
- }
-
- @Test
- public void testArray() throws MathIllegalArgumentException {
-
- FieldRotation<Dfp> r = new FieldRotation<>(createAxis(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
-
- for (double x = -0.9; x < 0.9; x += 0.2) {
- for (double y = -0.9; y < 0.9; y += 0.2) {
- for (double z = -0.9; z < 0.9; z += 0.2) {
- FieldVector3D<Dfp> u = createVector(x, y, z);
- FieldVector3D<Dfp> v = r.applyTo(u);
- Dfp[] out = new Dfp[3];
- r.applyTo(new Dfp[] { u.getX(), u.getY(), u.getZ() }, out);
- Assert.assertEquals(v.getX().getReal(), out[0].getReal(), 1.0e-10);
- Assert.assertEquals(v.getY().getReal(), out[1].getReal(), 1.0e-10);
- Assert.assertEquals(v.getZ().getReal(), out[2].getReal(), 1.0e-10);
- r.applyInverseTo(out, out);
- Assert.assertEquals(u.getX().getReal(), out[0].getReal(), 1.0e-10);
- Assert.assertEquals(u.getY().getReal(), out[1].getReal(), 1.0e-10);
- Assert.assertEquals(u.getZ().getReal(), out[2].getReal(), 1.0e-10);
- }
- }
- }
-
- }
-
- @Test
- public void testApplyInverseTo() throws MathIllegalArgumentException {
-
- Dfp[] in = new Dfp[3];
- Dfp[] out = new Dfp[3];
- Dfp[] rebuilt = new Dfp[3];
- FieldRotation<Dfp> r = new FieldRotation<>(createVector(2, -3, 5),
- createAngle(1.7),
- RotationConvention.VECTOR_OPERATOR);
- for (double lambda = 0; lambda < 6.2; lambda += 0.2) {
- for (double phi = -1.55; phi < 1.55; phi += 0.2) {
- FieldVector3D<Dfp> u = createVector(FastMath.cos(lambda) * FastMath.cos(phi),
- FastMath.sin(lambda) * FastMath.cos(phi),
- FastMath.sin(phi));
- r.applyInverseTo(r.applyTo(u));
- checkVector(u, r.applyInverseTo(r.applyTo(u)));
- checkVector(u, r.applyTo(r.applyInverseTo(u)));
- in[0] = u.getX();
- in[1] = u.getY();
- in[2] = u.getZ();
- r.applyTo(in, out);
- r.applyInverseTo(out, rebuilt);
- Assert.assertEquals(in[0].getReal(), rebuilt[0].getReal(), 1.0e-12);
- Assert.assertEquals(in[1].getReal(), rebuilt[1].getReal(), 1.0e-12);
- Assert.assertEquals(in[2].getReal(), rebuilt[2].getReal(), 1.0e-12);
- }
- }
-
- r = createRotation(1, 0, 0, 0, false);
- for (double lambda = 0; lambda < 6.2; lambda += 0.2) {
- for (double phi = -1.55; phi < 1.55; phi += 0.2) {
- FieldVector3D<Dfp> u = createVector(FastMath.cos(lambda) * FastMath.cos(phi),
- FastMath.sin(lambda) * FastMath.cos(phi),
- FastMath.sin(phi));
- checkVector(u, r.applyInverseTo(r.applyTo(u)));
- checkVector(u, r.applyTo(r.applyInverseTo(u)));
- }
- }
-
- r = new FieldRotation<>(createVector(0, 0, 1), createAngle(FastMath.PI), RotationConvention.VECTOR_OPERATOR);
- for (double lambda = 0; lambda < 6.2; lambda += 0.2) {
- for (double phi = -1.55; phi < 1.55; phi += 0.2) {
- FieldVector3D<Dfp> u = createVector(FastMath.cos(lambda) * FastMath.cos(phi),
- FastMath.sin(lambda) * FastMath.cos(phi),
- FastMath.sin(phi));
- checkVector(u, r.applyInverseTo(r.applyTo(u)));
- checkVector(u, r.applyTo(r.applyInverseTo(u)));
- }
- }
-
- }
-
- @Test
- public void testIssue639() throws MathArithmeticException{
- FieldVector3D<Dfp> u1 = createVector(-1321008684645961.0 / 268435456.0,
- -5774608829631843.0 / 268435456.0,
- -3822921525525679.0 / 4294967296.0);
- FieldVector3D<Dfp> u2 =createVector( -5712344449280879.0 / 2097152.0,
- -2275058564560979.0 / 1048576.0,
- 4423475992255071.0 / 65536.0);
- FieldRotation<Dfp> rot = new FieldRotation<>(u1, u2, createVector(1, 0, 0),createVector(0, 0, 1));
- Assert.assertEquals( 0.6228370359608200639829222, rot.getQ0().getReal(), 1.0e-15);
- Assert.assertEquals( 0.0257707621456498790029987, rot.getQ1().getReal(), 1.0e-15);
- Assert.assertEquals(-0.0000000002503012255839931, rot.getQ2().getReal(), 1.0e-15);
- Assert.assertEquals(-0.7819270390861109450724902, rot.getQ3().getReal(), 1.0e-15);
- }
-
- @Test
- public void testIssue801() throws MathArithmeticException {
- FieldVector3D<Dfp> u1 = createVector(0.9999988431610581, -0.0015210774290851095, 0.0);
- FieldVector3D<Dfp> u2 = createVector(0.0, 0.0, 1.0);
-
- FieldVector3D<Dfp> v1 = createVector(0.9999999999999999, 0.0, 0.0);
- FieldVector3D<Dfp> v2 = createVector(0.0, 0.0, -1.0);
-
- FieldRotation<Dfp> quat = new FieldRotation<>(u1, u2, v1, v2);
- double q2 = quat.getQ0().getReal() * quat.getQ0().getReal() +
- quat.getQ1().getReal() * quat.getQ1().getReal() +
- quat.getQ2().getReal() * quat.getQ2().getReal() +
- quat.getQ3().getReal() * quat.getQ3().getReal();
- Assert.assertEquals(1.0, q2, 1.0e-14);
- Assert.assertEquals(0.0, FieldVector3D.angle(v1, quat.applyTo(u1)).getReal(), 1.0e-14);
- Assert.assertEquals(0.0, FieldVector3D.angle(v2, quat.applyTo(u2)).getReal(), 1.0e-14);
-
- }
-
- private void checkAngle(Dfp a1, double a2) {
- Assert.assertEquals(a1.getReal(), PlaneAngleRadians.normalize(a2, a1.getReal()), 1.0e-10);
- }
-
- private void checkRotationDS(FieldRotation<Dfp> r, double q0, double q1, double q2, double q3) {
- FieldRotation<Dfp> rPrime = createRotation(q0, q1, q2, q3, false);
- Assert.assertEquals(0, FieldRotation.distance(r, rPrime).getReal(), 1.0e-12);
- }
-
- private FieldRotation<Dfp> createRotation(double q0, double q1, double q2, double q3,
- boolean needsNormalization) {
- DfpField field = new DfpField(20);
- return new FieldRotation<>(field.newDfp(q0),
- field.newDfp(q1),
- field.newDfp(q2),
- field.newDfp(q3),
- needsNormalization);
- }
-
- private FieldRotation<Dfp> createRotation(double[][] m, double threshold) {
- DfpField field = new DfpField(20);
- Dfp[][] mds = new Dfp[m.length][m[0].length];
- for (int i = 0; i < m.length; ++i) {
- for (int j = 0; j < m[i].length; ++j) {
- mds[i][j] = field.newDfp(m[i][j]);
- }
- }
- return new FieldRotation<>(mds, threshold);
- }
-
- private FieldVector3D<Dfp> createVector(double x, double y, double z) {
- DfpField field = new DfpField(20);
- return new FieldVector3D<>(field.newDfp(x), field.newDfp(y), field.newDfp(z));
- }
-
- private FieldVector3D<Dfp> createAxis(double x, double y, double z) {
- DfpField field = new DfpField(20);
- return new FieldVector3D<>(field.newDfp(x), field.newDfp(y), field.newDfp(z));
- }
-
- private Dfp createAngle(double alpha) {
- return new DfpField(20).newDfp(alpha);
- }
-
- private void checkVector(FieldVector3D<Dfp> u, FieldVector3D<Dfp> v) {
- Assert.assertEquals(u.getX().getReal(), v.getX().getReal(), 1.0e-12);
- Assert.assertEquals(u.getY().getReal(), v.getY().getReal(), 1.0e-12);
- Assert.assertEquals(u.getZ().getReal(), v.getZ().getReal(), 1.0e-12);
- }
-
-}
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java
deleted file mode 100644
index 283cc9e..0000000
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java
+++ /dev/null
@@ -1,726 +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.threed;
-
-import org.apache.commons.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.MathArithmeticException;
-import org.apache.commons.math4.geometry.euclidean.threed.FieldVector3D;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.simple.RandomSource;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.numbers.core.Precision;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class FieldVector3DTest {
-
- @Test
- public void testConstructors() throws DimensionMismatchException {
- double cosAlpha = 1 / 2.0;
- double sinAlpha = FastMath.sqrt(3) / 2.0;
- double cosDelta = FastMath.sqrt(2) / 2.0;
- double sinDelta = -FastMath.sqrt(2) / 2.0;
- FieldVector3D<DerivativeStructure> u = new FieldVector3D<>(2,
- new FieldVector3D<>(new DerivativeStructure(2, 1, 0, FastMath.PI / 3),
- new DerivativeStructure(2, 1, 1, -FastMath.PI / 4)));
- checkVector(u, 2 * cosAlpha * cosDelta, 2 * sinAlpha * cosDelta, 2 * sinDelta);
- Assert.assertEquals(-2 * sinAlpha * cosDelta, u.getX().getPartialDerivative(1, 0), 1.0e-12);
- Assert.assertEquals(+2 * cosAlpha * cosDelta, u.getY().getPartialDerivative(1, 0), 1.0e-12);
- Assert.assertEquals(0, u.getZ().getPartialDerivative(1, 0), 1.0e-12);
- Assert.assertEquals(-2 * cosAlpha * sinDelta, u.getX().getPartialDerivative(0, 1), 1.0e-12);
- Assert.assertEquals(-2 * sinAlpha * sinDelta, u.getY().getPartialDerivative(0, 1), 1.0e-12);
- Assert.assertEquals(2 * cosDelta, u.getZ().getPartialDerivative(0, 1), 1.0e-12);
-
- checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3)),
- 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2);
- checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0),
- createVector(1, 0, 0, 4)),
- 2, 0, 0, 2, 0, 0, 1, 0, 2, 0, 0, 0, 0, 2, 0);
- checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0),
- Vector3D.of(1, 0, 0)),
- 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
-
- checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3),
- -3, createVector(0, 0, -1, 3)),
- 2, 0, 3, -1, 0, 0, 0, -1, 0, 0, 0, -1);
- checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0),
- createVector(1, 0, 0, 4),
- new DerivativeStructure(4, 1, 3, -3.0),
- createVector(0, 0, -1, 4)),
- 2, 0, 3, -1, 0, 0, 1, 0, -1, 0, 0, 0, 0, -1, -1);
- checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0),
- Vector3D.of(1, 0, 0),
- new DerivativeStructure(4, 1, 3, -3.0),
- Vector3D.of(0, 0, -1)),
- 2, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1);
-
- checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3),
- 5, createVector(0, 1, 0, 3),
- -3, createVector(0, 0, -1, 3)),
- 2, 5, 3, 4, 0, 0, 0, 4, 0, 0, 0, 4);
- checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0),
- createVector(1, 0, 0, 4),
- new DerivativeStructure(4, 1, 3, 5.0),
- createVector(0, 1, 0, 4),
- new DerivativeStructure(4, 1, 3, -3.0),
- createVector(0, 0, -1, 4)),
- 2, 5, 3, 4, 0, 0, 1, 0, 4, 0, 1, 0, 0, 4, -1);
- checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0),
- Vector3D.of(1, 0, 0),
- new DerivativeStructure(4, 1, 3, 5.0),
- Vector3D.of(0, 1, 0),
- new DerivativeStructure(4, 1, 3, -3.0),
- Vector3D.of(0, 0, -1)),
- 2, 5, 3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, -1);
-
- checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3),
- 5, createVector(0, 1, 0, 3),
- 5, createVector(0, -1, 0, 3),
- -3, createVector(0, 0, -1, 3)),
- 2, 0, 3, 9, 0, 0, 0, 9, 0, 0, 0, 9);
- checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0),
- createVector(1, 0, 0, 4),
- new DerivativeStructure(4, 1, 3, 5.0),
- createVector(0, 1, 0, 4),
- new DerivativeStructure(4, 1, 3, 5.0),
- createVector(0, -1, 0, 4),
- new DerivativeStructure(4, 1, 3, -3.0),
- createVector(0, 0, -1, 4)),
- 2, 0, 3, 9, 0, 0, 1, 0, 9, 0, 0, 0, 0, 9, -1);
- checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0),
- Vector3D.of(1, 0, 0),
- new DerivativeStructure(4, 1, 3, 5.0),
- Vector3D.of(0, 1, 0),
- new DerivativeStructure(4, 1, 3, 5.0),
- Vector3D.of(0, -1, 0),
- new DerivativeStructure(4, 1, 3, -3.0),
- Vector3D.of(0, 0, -1)),
- 2, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1);
-
- checkVector(new FieldVector3D<>(new DerivativeStructure[] {
- new DerivativeStructure(3, 1, 2, 2),
- new DerivativeStructure(3, 1, 1, 5),
- new DerivativeStructure(3, 1, 0, -3)
- }),
- 2, 5, -3, 0, 0, 1, 0, 1, 0, 1, 0, 0);
-
- }
-
- @Test
- public void testEquals() {
- FieldVector3D<DerivativeStructure> u1 = createVector(1, 2, 3, 3);
- FieldVector3D<DerivativeStructure> v = createVector(1, 2, 3 + 10 * Precision.EPSILON, 3);
- Assert.assertTrue(u1.equals(u1));
- Assert.assertTrue(u1.equals(new FieldVector3D<>(new DerivativeStructure(3, 1, 0, 1.0),
- new DerivativeStructure(3, 1, 1, 2.0),
- new DerivativeStructure(3, 1, 2, 3.0))));
- Assert.assertFalse(u1.equals(new FieldVector3D<>(new DerivativeStructure(3, 1, 1.0),
- new DerivativeStructure(3, 1, 1, 2.0),
- new DerivativeStructure(3, 1, 2, 3.0))));
- Assert.assertFalse(u1.equals(new FieldVector3D<>(new DerivativeStructure(3, 1, 0, 1.0),
- new DerivativeStructure(3, 1, 2.0),
- new DerivativeStructure(3, 1, 2, 3.0))));
- Assert.assertFalse(u1.equals(new FieldVector3D<>(new DerivativeStructure(3, 1, 0, 1.0),
- new DerivativeStructure(3, 1, 1, 2.0),
- new DerivativeStructure(3, 1, 3.0))));
- Assert.assertFalse(u1.equals(v));
- Assert.assertFalse(u1.equals(u1.toVector3D()));
- Assert.assertTrue(createVector(0, Double.NaN, 0, 3).equals(createVector(0, 0, Double.NaN, 3)));
- }
-
- @Test
- public void testHash() {
- Assert.assertEquals(createVector(0, Double.NaN, 0, 3).hashCode(), createVector(0, 0, Double.NaN, 3).hashCode());
- FieldVector3D<DerivativeStructure> u = createVector(1, 2, 3, 3);
- FieldVector3D<DerivativeStructure> v = createVector(1, 2, 3 + 10 * Precision.EPSILON, 3);
- Assert.assertTrue(u.hashCode() != v.hashCode());
- }
-
- @Test
- public void testInfinite() {
- Assert.assertTrue(createVector(1, 1, Double.NEGATIVE_INFINITY, 3).isInfinite());
- Assert.assertTrue(createVector(1, Double.NEGATIVE_INFINITY, 1, 3).isInfinite());
- Assert.assertTrue(createVector(Double.NEGATIVE_INFINITY, 1, 1, 3).isInfinite());
- Assert.assertFalse(createVector(1, 1, 2, 3).isInfinite());
- Assert.assertFalse(createVector(1, Double.NaN, Double.NEGATIVE_INFINITY, 3).isInfinite());
- }
-
- @Test
- public void testNaN() {
- Assert.assertTrue(createVector(1, 1, Double.NaN, 3).isNaN());
- Assert.assertTrue(createVector(1, Double.NaN, 1, 3).isNaN());
- Assert.assertTrue(createVector(Double.NaN, 1, 1, 3).isNaN());
- Assert.assertFalse(createVector(1, 1, 2, 3).isNaN());
- Assert.assertFalse(createVector(1, 1, Double.NEGATIVE_INFINITY, 3).isNaN());
- }
-
- @Test
- public void testToString() {
- Assert.assertEquals(Vector3D.of(3, 2, 1).toString(),
- createVector(3, 2, 1, 3).toString());
- }
-
- @Test(expected=DimensionMismatchException.class)
- public void testWrongDimension() throws DimensionMismatchException {
- new FieldVector3D<>(new DerivativeStructure[] {
- new DerivativeStructure(3, 1, 0, 2),
- new DerivativeStructure(3, 1, 0, 5)
- });
- }
-
- @Test
- public void testCoordinates() {
- FieldVector3D<DerivativeStructure> v = createVector(1, 2, 3, 3);
- Assert.assertTrue(FastMath.abs(v.getX().getReal() - 1) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(v.getY().getReal() - 2) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(v.getZ().getReal() - 3) < 1.0e-12);
- DerivativeStructure[] coordinates = v.toArray();
- Assert.assertTrue(FastMath.abs(coordinates[0].getReal() - 1) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(coordinates[1].getReal() - 2) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(coordinates[2].getReal() - 3) < 1.0e-12);
- }
-
- @Test
- public void testNorm1() {
- Assert.assertEquals( 0.0, createVector(0, 0, 0, 3).getNorm1().getReal(), 0);
- Assert.assertEquals( 6.0, createVector(1, -2, 3, 3).getNorm1().getReal(), 0);
- Assert.assertEquals( 1.0, createVector(1, -2, 3, 3).getNorm1().getPartialDerivative(1, 0, 0), 0);
- Assert.assertEquals(-1.0, createVector(1, -2, 3, 3).getNorm1().getPartialDerivative(0, 1, 0), 0);
- Assert.assertEquals( 1.0, createVector(1, -2, 3, 3).getNorm1().getPartialDerivative(0, 0, 1), 0);
- }
-
- @Test
- public void testNorm() {
- double r = FastMath.sqrt(14);
- Assert.assertEquals(0.0, createVector(0, 0, 0, 3).getNorm().getReal(), 0);
- Assert.assertEquals(r, createVector(1, 2, 3, 3).getNorm().getReal(), 1.0e-12);
- Assert.assertEquals( 1.0 / r, createVector(1, 2, 3, 3).getNorm().getPartialDerivative(1, 0, 0), 0);
- Assert.assertEquals( 2.0 / r, createVector(1, 2, 3, 3).getNorm().getPartialDerivative(0, 1, 0), 0);
- Assert.assertEquals( 3.0 / r, createVector(1, 2, 3, 3).getNorm().getPartialDerivative(0, 0, 1), 0);
- }
-
- @Test
- public void testNormSq() {
- Assert.assertEquals(0.0, createVector(0, 0, 0, 3).getNormSq().getReal(), 0);
- Assert.assertEquals(14, createVector(1, 2, 3, 3).getNormSq().getReal(), 1.0e-12);
- Assert.assertEquals( 2, createVector(1, 2, 3, 3).getNormSq().getPartialDerivative(1, 0, 0), 0);
- Assert.assertEquals( 4, createVector(1, 2, 3, 3).getNormSq().getPartialDerivative(0, 1, 0), 0);
- Assert.assertEquals( 6, createVector(1, 2, 3, 3).getNormSq().getPartialDerivative(0, 0, 1), 0);
- }
-
- @Test
- public void testNormInf() {
- Assert.assertEquals( 0.0, createVector(0, 0, 0, 3).getNormInf().getReal(), 0);
- Assert.assertEquals( 3.0, createVector(1, -2, 3, 3).getNormInf().getReal(), 0);
- Assert.assertEquals( 0.0, createVector(1, -2, 3, 3).getNormInf().getPartialDerivative(1, 0, 0), 0);
- Assert.assertEquals( 0.0, createVector(1, -2, 3, 3).getNormInf().getPartialDerivative(0, 1, 0), 0);
- Assert.assertEquals( 1.0, createVector(1, -2, 3, 3).getNormInf().getPartialDerivative(0, 0, 1), 0);
- Assert.assertEquals( 3.0, createVector(2, -1, 3, 3).getNormInf().getReal(), 0);
- Assert.assertEquals( 0.0, createVector(2, -1, 3, 3).getNormInf().getPartialDerivative(1, 0, 0), 0);
- Assert.assertEquals( 0.0, createVector(2, -1, 3, 3).getNormInf().getPartialDerivative(0, 1, 0), 0);
- Assert.assertEquals( 1.0, createVector(2, -1, 3, 3).getNormInf().getPartialDerivative(0, 0, 1), 0);
- Assert.assertEquals( 3.0, createVector(1, -3, 2, 3).getNormInf().getReal(), 0);
- Assert.assertEquals( 0.0, createVector(1, -3, 2, 3).getNormInf().getPartialDerivative(1, 0, 0), 0);
- Assert.assertEquals(-1.0, createVector(1, -3, 2, 3).getNormInf().getPartialDerivative(0, 1, 0), 0);
- Assert.assertEquals( 0.0, createVector(1, -3, 2, 3).getNormInf().getPartialDerivative(0, 0, 1), 0);
- Assert.assertEquals( 3.0, createVector(2, -3, 1, 3).getNormInf().getReal(), 0);
- Assert.assertEquals( 0.0, createVector(2, -3, 1, 3).getNormInf().getPartialDerivative(1, 0, 0), 0);
- Assert.assertEquals(-1.0, createVector(2, -3, 1, 3).getNormInf().getPartialDerivative(0, 1, 0), 0);
- Assert.assertEquals( 0.0, createVector(2, -3, 1, 3).getNormInf().getPartialDerivative(0, 0, 1), 0);
- Assert.assertEquals( 3.0, createVector(3, -1, 2, 3).getNormInf().getReal(), 0);
- Assert.assertEquals( 1.0, createVector(3, -1, 2, 3).getNormInf().getPartialDerivative(1, 0, 0), 0);
- Assert.assertEquals( 0.0, createVector(3, -1, 2, 3).getNormInf().getPartialDerivative(0, 1, 0), 0);
- Assert.assertEquals( 0.0, createVector(3, -1, 2, 3).getNormInf().getPartialDerivative(0, 0, 1), 0);
- Assert.assertEquals( 3.0, createVector(3, -2, 1, 3).getNormInf().getReal(), 0);
- Assert.assertEquals( 1.0, createVector(3, -2, 1, 3).getNormInf().getPartialDerivative(1, 0, 0), 0);
- Assert.assertEquals( 0.0, createVector(3, -2, 1, 3).getNormInf().getPartialDerivative(0, 1, 0), 0);
- Assert.assertEquals( 0.0, createVector(3, -2, 1, 3).getNormInf().getPartialDerivative(0, 0, 1), 0);
- }
-
- @Test
- public void testDistance1() {
- FieldVector3D<DerivativeStructure> v1 = createVector(1, -2, 3, 3);
- FieldVector3D<DerivativeStructure> v2 = createVector(-4, 2, 0, 3);
- Assert.assertEquals(0.0, FieldVector3D.distance1(createVector(-1, 0, 0, 3), createVector(-1, 0, 0, 3)).getReal(), 0);
- DerivativeStructure distance = FieldVector3D.distance1(v1, v2);
- Assert.assertEquals(12.0, distance.getReal(), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(0, 0, 1), 1.0e-12);
- distance = FieldVector3D.distance1(v1, Vector3D.of(-4, 2, 0));
- Assert.assertEquals(12.0, distance.getReal(), 1.0e-12);
- Assert.assertEquals( 1, distance.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(-1, distance.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals( 1, distance.getPartialDerivative(0, 0, 1), 1.0e-12);
- distance = FieldVector3D.distance1(Vector3D.of(-4, 2, 0), v1);
- Assert.assertEquals(12.0, distance.getReal(), 1.0e-12);
- Assert.assertEquals( 1, distance.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(-1, distance.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals( 1, distance.getPartialDerivative(0, 0, 1), 1.0e-12);
- }
-
- @Test
- public void testDistance() {
- FieldVector3D<DerivativeStructure> v1 = createVector(1, -2, 3, 3);
- FieldVector3D<DerivativeStructure> v2 = createVector(-4, 2, 0, 3);
- Assert.assertEquals(0.0, FieldVector3D.distance(createVector(-1, 0, 0, 3), createVector(-1, 0, 0, 3)).getReal(), 0);
- DerivativeStructure distance = FieldVector3D.distance(v1, v2);
- Assert.assertEquals(FastMath.sqrt(50), distance.getReal(), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(0, 0, 1), 1.0e-12);
- distance = FieldVector3D.distance(v1, Vector3D.of(-4, 2, 0));
- Assert.assertEquals(FastMath.sqrt(50), distance.getReal(), 1.0e-12);
- Assert.assertEquals( 5 / FastMath.sqrt(50), distance.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(-4 / FastMath.sqrt(50), distance.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals( 3 / FastMath.sqrt(50), distance.getPartialDerivative(0, 0, 1), 1.0e-12);
- distance = FieldVector3D.distance(Vector3D.of(-4, 2, 0), v1);
- Assert.assertEquals(FastMath.sqrt(50), distance.getReal(), 1.0e-12);
- Assert.assertEquals( 5 / FastMath.sqrt(50), distance.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(-4 / FastMath.sqrt(50), distance.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals( 3 / FastMath.sqrt(50), distance.getPartialDerivative(0, 0, 1), 1.0e-12);
- }
-
- @Test
- public void testDistanceSq() {
- FieldVector3D<DerivativeStructure> v1 = createVector(1, -2, 3, 3);
- FieldVector3D<DerivativeStructure> v2 = createVector(-4, 2, 0, 3);
- Assert.assertEquals(0.0, FieldVector3D.distanceSq(createVector(-1, 0, 0, 3), createVector(-1, 0, 0, 3)).getReal(), 0);
- DerivativeStructure distanceSq = FieldVector3D.distanceSq(v1, v2);
- Assert.assertEquals(50.0, distanceSq.getReal(), 1.0e-12);
- Assert.assertEquals(0, distanceSq.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(0, distanceSq.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals(0, distanceSq.getPartialDerivative(0, 0, 1), 1.0e-12);
- distanceSq = FieldVector3D.distanceSq(v1, Vector3D.of(-4, 2, 0));
- Assert.assertEquals(50.0, distanceSq.getReal(), 1.0e-12);
- Assert.assertEquals(10, distanceSq.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(-8, distanceSq.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals( 6, distanceSq.getPartialDerivative(0, 0, 1), 1.0e-12);
- distanceSq = FieldVector3D.distanceSq(Vector3D.of(-4, 2, 0), v1);
- Assert.assertEquals(50.0, distanceSq.getReal(), 1.0e-12);
- Assert.assertEquals(10, distanceSq.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(-8, distanceSq.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals( 6, distanceSq.getPartialDerivative(0, 0, 1), 1.0e-12);
- }
-
- @Test
- public void testDistanceInf() {
- FieldVector3D<DerivativeStructure> v1 = createVector(1, -2, 3, 3);
- FieldVector3D<DerivativeStructure> v2 = createVector(-4, 2, 0, 3);
- Assert.assertEquals(0.0, FieldVector3D.distanceInf(createVector(-1, 0, 0, 3), createVector(-1, 0, 0, 3)).getReal(), 0);
- DerivativeStructure distance = FieldVector3D.distanceInf(v1, v2);
- Assert.assertEquals(5.0, distance.getReal(), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(0, 0, 1), 1.0e-12);
- distance = FieldVector3D.distanceInf(v1, Vector3D.of(-4, 2, 0));
- Assert.assertEquals(5.0, distance.getReal(), 1.0e-12);
- Assert.assertEquals(1, distance.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(0, 0, 1), 1.0e-12);
- distance = FieldVector3D.distanceInf(Vector3D.of(-4, 2, 0), v1);
- Assert.assertEquals(5.0, distance.getReal(), 1.0e-12);
- Assert.assertEquals(1, distance.getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals(0, distance.getPartialDerivative(0, 0, 1), 1.0e-12);
- Assert.assertEquals(v1.subtract(v2).getNormInf().getReal(), FieldVector3D.distanceInf(v1, v2).getReal(), 1.0e-12);
-
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector( 1, -2, 3, 3), createVector(-4, 2, 0, 3)).getReal(),
- 1.0e-12);
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector( 1, 3, -2, 3), createVector(-4, 0, 2, 3)).getReal(),
- 1.0e-12);
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector(-2, 1, 3, 3), createVector( 2, -4, 0, 3)).getReal(),
- 1.0e-12);
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector(-2, 3, 1, 3), createVector( 2, 0, -4, 3)).getReal(),
- 1.0e-12);
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector(3, -2, 1, 3), createVector(0, 2, -4, 3)).getReal(),
- 1.0e-12);
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector(3, 1, -2, 3), createVector(0, -4, 2, 3)).getReal(),
- 1.0e-12);
-
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector( 1, -2, 3, 3), Vector3D.of(-4, 2, 0)).getReal(),
- 1.0e-12);
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector( 1, 3, -2, 3), Vector3D.of(-4, 0, 2)).getReal(),
- 1.0e-12);
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector(-2, 1, 3, 3), Vector3D.of( 2, -4, 0)).getReal(),
- 1.0e-12);
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector(-2, 3, 1, 3), Vector3D.of( 2, 0, -4)).getReal(),
- 1.0e-12);
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector(3, -2, 1, 3), Vector3D.of(0, 2, -4)).getReal(),
- 1.0e-12);
- Assert.assertEquals(5.0,
- FieldVector3D.distanceInf(createVector(3, 1, -2, 3), Vector3D.of(0, -4, 2)).getReal(),
- 1.0e-12);
-
- }
-
- @Test
- public void testSubtract() {
- FieldVector3D<DerivativeStructure> v1 = createVector(1, 2, 3, 3);
- FieldVector3D<DerivativeStructure> v2 = createVector(-3, -2, -1, 3);
- v1 = v1.subtract(v2);
- checkVector(v1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0);
-
- checkVector(v2.subtract(v1), -7, -6, -5, 1, 0, 0, 0, 1, 0, 0, 0, 1);
- checkVector(v2.subtract(Vector3D.of(4, 4, 4)), -7, -6, -5, 1, 0, 0, 0, 1, 0, 0, 0, 1);
- checkVector(v2.subtract(3, v1), -15, -14, -13, 1, 0, 0, 0, 1, 0, 0, 0, 1);
- checkVector(v2.subtract(3, Vector3D.of(4, 4, 4)), -15, -14, -13, 1, 0, 0, 0, 1, 0, 0, 0, 1);
- checkVector(v2.subtract(new DerivativeStructure(3, 1, 2, 3), Vector3D.of(4, 4, 4)),
- -15, -14, -13, 1, 0, -4, 0, 1, -4, 0, 0, -3);
-
- checkVector(createVector(1, 2, 3, 4).subtract(new DerivativeStructure(4, 1, 3, 5.0),
- createVector(3, -2, 1, 4)),
- -14, 12, -2,
- -4, 0, 0, -3,
- 0, -4, 0, 2,
- 0, 0, -4, -1);
-
- }
-
- @Test
- public void testAdd() {
- FieldVector3D<DerivativeStructure> v1 = createVector(1, 2, 3, 3);
- FieldVector3D<DerivativeStructure> v2 = createVector(-3, -2, -1, 3);
- v1 = v1.add(v2);
- checkVector(v1, -2, 0, 2, 2, 0, 0, 0, 2, 0, 0, 0, 2);
-
- checkVector(v2.add(v1), -5, -2, 1, 3, 0, 0, 0, 3, 0, 0, 0, 3);
- checkVector(v2.add(Vector3D.of(-2, 0, 2)), -5, -2, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1);
- checkVector(v2.add(3, v1), -9, -2, 5, 7, 0, 0, 0, 7, 0, 0, 0, 7);
- checkVector(v2.add(3, Vector3D.of(-2, 0, 2)), -9, -2, 5, 1, 0, 0, 0, 1, 0, 0, 0, 1);
- checkVector(v2.add(new DerivativeStructure(3, 1, 2, 3), Vector3D.of(-2, 0, 2)),
- -9, -2, 5, 1, 0, -2, 0, 1, 0, 0, 0, 3);
-
- checkVector(createVector(1, 2, 3, 4).add(new DerivativeStructure(4, 1, 3, 5.0),
- createVector(3, -2, 1, 4)),
- 16, -8, 8,
- 6, 0, 0, 3,
- 0, 6, 0, -2,
- 0, 0, 6, 1);
-
- }
-
- @Test
- public void testScalarProduct() {
- FieldVector3D<DerivativeStructure> v = createVector(1, 2, 3, 3);
- v = v.scalarMultiply(3);
- checkVector(v, 3, 6, 9);
-
- checkVector(v.scalarMultiply(0.5), 1.5, 3, 4.5);
- }
-
- @Test
- public void testVectorialProducts() {
- FieldVector3D<DerivativeStructure> v1 = createVector(2, 1, -4, 3);
- FieldVector3D<DerivativeStructure> v2 = createVector(3, 1, -1, 3);
-
- Assert.assertTrue(FastMath.abs(FieldVector3D.dotProduct(v1, v2).getReal() - 11) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(FieldVector3D.dotProduct(v1, v2.toVector3D()).getReal() - 11) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(FieldVector3D.dotProduct(v1.toVector3D(), v2).getReal() - 11) < 1.0e-12);
-
- FieldVector3D<DerivativeStructure> v3 = FieldVector3D.crossProduct(v1, v2);
- checkVector(v3, 3, -10, -1);
- Assert.assertTrue(FastMath.abs(FieldVector3D.dotProduct(v1, v3).getReal()) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(FieldVector3D.dotProduct(v2, v3).getReal()) < 1.0e-12);
-
- v3 = FieldVector3D.crossProduct(v1, v2.toVector3D());
- checkVector(v3, 3, -10, -1);
- Assert.assertTrue(FastMath.abs(FieldVector3D.dotProduct(v1, v3).getReal()) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(FieldVector3D.dotProduct(v2, v3).getReal()) < 1.0e-12);
-
- v3 = FieldVector3D.crossProduct(v1.toVector3D(), v2);
- checkVector(v3, 3, -10, -1);
- Assert.assertTrue(FastMath.abs(FieldVector3D.dotProduct(v1, v3).getReal()) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(FieldVector3D.dotProduct(v2, v3).getReal()) < 1.0e-12);
-
- }
-
- @Test
- public void testCrossProductCancellation() {
- FieldVector3D<DerivativeStructure> v1 = createVector(9070467121.0, 4535233560.0, 1, 3);
- FieldVector3D<DerivativeStructure> v2 = createVector(9070467123.0, 4535233561.0, 1, 3);
- checkVector(FieldVector3D.crossProduct(v1, v2), -1, 2, 1);
-
- double scale = FastMath.scalb(1.0, 100);
- FieldVector3D<DerivativeStructure> big1 = new FieldVector3D<>(scale, v1);
- FieldVector3D<DerivativeStructure> small2 = new FieldVector3D<>(1 / scale, v2);
- checkVector(FieldVector3D.crossProduct(big1, small2), -1, 2, 1);
-
- }
-
- @Test
- public void testAngular() {
- Assert.assertEquals(0, createVector(1, 0, 0, 3).getAlpha().getReal(), 1.0e-10);
- Assert.assertEquals(0, createVector(1, 0, 0, 3).getDelta().getReal(), 1.0e-10);
- Assert.assertEquals(FastMath.PI / 2, createVector(0, 1, 0, 3).getAlpha().getReal(), 1.0e-10);
- Assert.assertEquals(0, createVector(0, 1, 0, 3).getDelta().getReal(), 1.0e-10);
- Assert.assertEquals(FastMath.PI / 2, createVector(0, 0, 1, 3).getDelta().getReal(), 1.0e-10);
-
- FieldVector3D<DerivativeStructure> u = createVector(-1, 1, -1, 3);
- Assert.assertEquals(3 * FastMath.PI /4, u.getAlpha().getReal(), 1.0e-10);
- Assert.assertEquals(-1.0 / FastMath.sqrt(3), u.getDelta().sin().getReal(), 1.0e-10);
- }
-
- @Test
- public void testAngularSeparation() throws MathArithmeticException {
- FieldVector3D<DerivativeStructure> v1 = createVector(2, -1, 4, 3);
-
- FieldVector3D<DerivativeStructure> k = v1.normalize();
- FieldVector3D<DerivativeStructure> i = k.orthogonal();
- FieldVector3D<DerivativeStructure> v2 = k.scalarMultiply(FastMath.cos(1.2)).add(i.scalarMultiply(FastMath.sin(1.2)));
-
- Assert.assertTrue(FastMath.abs(FieldVector3D.angle(v1, v2).getReal() - 1.2) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(FieldVector3D.angle(v1, v2.toVector3D()).getReal() - 1.2) < 1.0e-12);
- Assert.assertTrue(FastMath.abs(FieldVector3D.angle(v1.toVector3D(), v2).getReal() - 1.2) < 1.0e-12);
-
- try {
- FieldVector3D.angle(v1, Vector3D.ZERO);
- Assert.fail("an exception should have been thrown");
- } catch (MathArithmeticException mae) {
- // expected
- }
- Assert.assertEquals(0.0, FieldVector3D.angle(v1, v1.toVector3D()).getReal(), 1.0e-15);
- Assert.assertEquals(FastMath.PI, FieldVector3D.angle(v1, v1.negate().toVector3D()).getReal(), 1.0e-15);
-
- }
-
- @Test
- public void testNormalize() throws MathArithmeticException {
- Assert.assertEquals(1.0, createVector(5, -4, 2, 3).normalize().getNorm().getReal(), 1.0e-12);
- try {
- createVector(0, 0, 0, 3).normalize();
- Assert.fail("an exception should have been thrown");
- } catch (MathArithmeticException ae) {
- // expected behavior
- }
- }
-
- @Test
- public void testNegate() {
- checkVector(createVector(0.1, 2.5, 1.3, 3).negate(),
- -0.1, -2.5, -1.3, -1, 0, 0, 0, -1, 0, 0, 0, -1);
- }
-
- @Test
- public void testOrthogonal() throws MathArithmeticException {
- FieldVector3D<DerivativeStructure> v1 = createVector(0.1, 2.5, 1.3, 3);
- Assert.assertEquals(0.0, FieldVector3D.dotProduct(v1, v1.orthogonal()).getReal(), 1.0e-12);
- FieldVector3D<DerivativeStructure> v2 = createVector(2.3, -0.003, 7.6, 3);
- Assert.assertEquals(0.0, FieldVector3D.dotProduct(v2, v2.orthogonal()).getReal(), 1.0e-12);
- FieldVector3D<DerivativeStructure> v3 = createVector(-1.7, 1.4, 0.2, 3);
- Assert.assertEquals(0.0, FieldVector3D.dotProduct(v3, v3.orthogonal()).getReal(), 1.0e-12);
- FieldVector3D<DerivativeStructure> v4 = createVector(4.2, 0.1, -1.8, 3);
- Assert.assertEquals(0.0, FieldVector3D.dotProduct(v4, v4.orthogonal()).getReal(), 1.0e-12);
- try {
- createVector(0, 0, 0, 3).orthogonal();
- Assert.fail("an exception should have been thrown");
- } catch (MathArithmeticException ae) {
- // expected behavior
- }
- }
-
- @Test
- public void testAngle() throws MathArithmeticException {
- Assert.assertEquals(0.22572612855273393616,
- FieldVector3D.angle(createVector(1, 2, 3, 3), createVector(4, 5, 6, 3)).getReal(),
- 1.0e-12);
- Assert.assertEquals(7.98595620686106654517199e-8,
- FieldVector3D.angle(createVector(1, 2, 3, 3), createVector(2, 4, 6.000001, 3)).getReal(),
- 1.0e-12);
- Assert.assertEquals(3.14159257373023116985197793156,
- FieldVector3D.angle(createVector(1, 2, 3, 3), createVector(-2, -4, -6.000001, 3)).getReal(),
- 1.0e-12);
- try {
- FieldVector3D.angle(createVector(0, 0, 0, 3), createVector(1, 0, 0, 3));
- Assert.fail("an exception should have been thrown");
- } catch (MathArithmeticException ae) {
- // expected behavior
- }
- }
-
- @Test
- public void testAccurateDotProduct() {
- // the following two vectors are nearly but not exactly orthogonal
- // naive dot product (i.e. computing u1.x * u2.x + u1.y * u2.y + u1.z * u2.z
- // leads to a result of 0.0, instead of the correct -1.855129...
- FieldVector3D<DerivativeStructure> u1 = createVector(-1321008684645961.0 / 268435456.0,
- -5774608829631843.0 / 268435456.0,
- -7645843051051357.0 / 8589934592.0, 3);
- FieldVector3D<DerivativeStructure> u2 = createVector(-5712344449280879.0 / 2097152.0,
- -4550117129121957.0 / 2097152.0,
- 8846951984510141.0 / 131072.0, 3);
- DerivativeStructure sNaive = u1.getX().multiply(u2.getX()).add(u1.getY().multiply(u2.getY())).add(u1.getZ().multiply(u2.getZ()));
- DerivativeStructure sAccurate = FieldVector3D.dotProduct(u1, u2);
- Assert.assertEquals(0.0, sNaive.getReal(), 1.0e-30);
- Assert.assertEquals(-2088690039198397.0 / 1125899906842624.0, sAccurate.getReal(), 1.0e-15);
- }
-
- @Test
- public void testDotProduct() {
- // we compare accurate versus naive dot product implementations
- // on regular vectors (i.e. not extreme cases like in the previous test)
- UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 553267312521321237l);
- for (int i = 0; i < 10000; ++i) {
- double ux = 10000 * random.nextDouble();
- double uy = 10000 * random.nextDouble();
- double uz = 10000 * random.nextDouble();
- double vx = 10000 * random.nextDouble();
- double vy = 10000 * random.nextDouble();
- double vz = 10000 * random.nextDouble();
- double sNaive = ux * vx + uy * vy + uz * vz;
-
- FieldVector3D<DerivativeStructure> uds = createVector(ux, uy, uz, 3);
- FieldVector3D<DerivativeStructure> vds = createVector(vx, vy, vz, 3);
- Vector3D v = Vector3D.of(vx, vy, vz);
-
- DerivativeStructure sAccurate = FieldVector3D.dotProduct(uds, vds);
- Assert.assertEquals(sNaive, sAccurate.getReal(), 2.5e-16 * sNaive);
- Assert.assertEquals(ux + vx, sAccurate.getPartialDerivative(1, 0, 0), 2.5e-16 * sNaive);
- Assert.assertEquals(uy + vy, sAccurate.getPartialDerivative(0, 1, 0), 2.5e-16 * sNaive);
- Assert.assertEquals(uz + vz, sAccurate.getPartialDerivative(0, 0, 1), 2.5e-16 * sNaive);
-
- sAccurate = FieldVector3D.dotProduct(uds, v);
- Assert.assertEquals(sNaive, sAccurate.getReal(), 2.5e-16 * sNaive);
- Assert.assertEquals(vx, sAccurate.getPartialDerivative(1, 0, 0), 2.5e-16 * sNaive);
- Assert.assertEquals(vy, sAccurate.getPartialDerivative(0, 1, 0), 2.5e-16 * sNaive);
- Assert.assertEquals(vz, sAccurate.getPartialDerivative(0, 0, 1), 2.5e-16 * sNaive);
-
- }
- }
-
- @Test
- public void testAccurateCrossProduct() {
- // the vectors u1 and u2 are nearly but not exactly anti-parallel
- // (7.31e-16 degrees from 180 degrees) naive cross product (i.e.
- // computing u1.x * u2.x + u1.y * u2.y + u1.z * u2.z
- // leads to a result of [0.0009765, -0.0001220, -0.0039062],
- // instead of the correct [0.0006913, -0.0001254, -0.0007909]
- final FieldVector3D<DerivativeStructure> u1 = createVector(-1321008684645961.0 / 268435456.0,
- -5774608829631843.0 / 268435456.0,
- -7645843051051357.0 / 8589934592.0, 3);
- final FieldVector3D<DerivativeStructure> u2 = createVector( 1796571811118507.0 / 2147483648.0,
- 7853468008299307.0 / 2147483648.0,
- 2599586637357461.0 / 17179869184.0, 3);
- final FieldVector3D<DerivativeStructure> u3 = createVector(12753243807587107.0 / 18446744073709551616.0,
- -2313766922703915.0 / 18446744073709551616.0,
- -227970081415313.0 / 288230376151711744.0, 3);
- FieldVector3D<DerivativeStructure> cNaive = new FieldVector3D<>(u1.getY().multiply(u2.getZ()).subtract(u1.getZ().multiply(u2.getY())),
- u1.getZ().multiply(u2.getX()).subtract(u1.getX().multiply(u2.getZ())),
- u1.getX().multiply(u2.getY()).subtract(u1.getY().multiply(u2.getX())));
- FieldVector3D<DerivativeStructure> cAccurate = FieldVector3D.crossProduct(u1, u2);
- Assert.assertTrue(FieldVector3D.distance(u3, cNaive).getReal() > 2.9 * u3.getNorm().getReal());
- Assert.assertEquals(0.0, FieldVector3D.distance(u3, cAccurate).getReal(), 1.0e-30 * cAccurate.getNorm().getReal());
- }
-
- @Test
- public void testCrossProduct() {
- // we compare accurate versus naive cross product implementations
- // on regular vectors (i.e. not extreme cases like in the previous test)
- UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 885362227452043214l);
- for (int i = 0; i < 10000; ++i) {
- double ux = random.nextDouble();
- double uy = random.nextDouble();
- double uz = random.nextDouble();
- double vx = random.nextDouble();
- double vy = random.nextDouble();
- double vz = random.nextDouble();
- Vector3D cNaive = Vector3D.of(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx);
-
- FieldVector3D<DerivativeStructure> uds = createVector(ux, uy, uz, 3);
- FieldVector3D<DerivativeStructure> vds = createVector(vx, vy, vz, 3);
- Vector3D v = Vector3D.of(vx, vy, vz);
-
- checkVector(FieldVector3D.crossProduct(uds, vds),
- cNaive.getX(), cNaive.getY(), cNaive.getZ(),
- 0, vz - uz, uy - vy,
- uz - vz, 0, vx - ux,
- vy - uy, ux - vx, 0);
-
- checkVector(FieldVector3D.crossProduct(uds, v),
- cNaive.getX(), cNaive.getY(), cNaive.getZ(),
- 0, vz, -vy,
- -vz, 0, vx,
- vy, -vx, 0);
- }
- }
-
- private FieldVector3D<DerivativeStructure> createVector(double x, double y, double z, int params) {
- return new FieldVector3D<>(new DerivativeStructure(params, 1, 0, x),
- new DerivativeStructure(params, 1, 1, y),
- new DerivativeStructure(params, 1, 2, z));
- }
-
- private void checkVector(FieldVector3D<DerivativeStructure> v, double x, double y, double z) {
- Assert.assertEquals(x, v.getX().getReal(), 1.0e-12);
- Assert.assertEquals(y, v.getY().getReal(), 1.0e-12);
- Assert.assertEquals(z, v.getZ().getReal(), 1.0e-12);
- }
-
- private void checkVector(FieldVector3D<DerivativeStructure> v, double x, double y, double z,
- double dxdx, double dxdy, double dxdz,
- double dydx, double dydy, double dydz,
- double dzdx, double dzdy, double dzdz) {
- Assert.assertEquals(x, v.getX().getReal(), 1.0e-12);
- Assert.assertEquals(y, v.getY().getReal(), 1.0e-12);
- Assert.assertEquals(z, v.getZ().getReal(), 1.0e-12);
- Assert.assertEquals(dxdx, v.getX().getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(dxdy, v.getX().getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals(dxdz, v.getX().getPartialDerivative(0, 0, 1), 1.0e-12);
- Assert.assertEquals(dydx, v.getY().getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(dydy, v.getY().getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals(dydz, v.getY().getPartialDerivative(0, 0, 1), 1.0e-12);
- Assert.assertEquals(dzdx, v.getZ().getPartialDerivative(1, 0, 0), 1.0e-12);
- Assert.assertEquals(dzdy, v.getZ().getPartialDerivative(0, 1, 0), 1.0e-12);
- Assert.assertEquals(dzdz, v.getZ().getPartialDerivative(0, 0, 1), 1.0e-12);
- }
-
- private void checkVector(FieldVector3D<DerivativeStructure> v, double x, double y, double z,
- double dxdx, double dxdy, double dxdz, double dxdt,
- double dydx, double dydy, double dydz, double dydt,
- double dzdx, double dzdy, double dzdz, double dzdt) {
- Assert.assertEquals(x, v.getX().getReal(), 1.0e-12);
- Assert.assertEquals(y, v.getY().getReal(), 1.0e-12);
- Assert.assertEquals(z, v.getZ().getReal(), 1.0e-12);
- Assert.assertEquals(dxdx, v.getX().getPartialDerivative(1, 0, 0, 0), 1.0e-12);
- Assert.assertEquals(dxdy, v.getX().getPartialDerivative(0, 1, 0, 0), 1.0e-12);
- Assert.assertEquals(dxdz, v.getX().getPartialDerivative(0, 0, 1, 0), 1.0e-12);
- Assert.assertEquals(dxdt, v.getX().getPartialDerivative(0, 0, 0, 1), 1.0e-12);
- Assert.assertEquals(dydx, v.getY().getPartialDerivative(1, 0, 0, 0), 1.0e-12);
- Assert.assertEquals(dydy, v.getY().getPartialDerivative(0, 1, 0, 0), 1.0e-12);
- Assert.assertEquals(dydz, v.getY().getPartialDerivative(0, 0, 1, 0), 1.0e-12);
- Assert.assertEquals(dydt, v.getY().getPartialDerivative(0, 0, 0, 1), 1.0e-12);
- Assert.assertEquals(dzdx, v.getZ().getPartialDerivative(1, 0, 0, 0), 1.0e-12);
- Assert.assertEquals(dzdy, v.getZ().getPartialDerivative(0, 1, 0, 0), 1.0e-12);
- Assert.assertEquals(dzdz, v.getZ().getPartialDerivative(0, 0, 1, 0), 1.0e-12);
- Assert.assertEquals(dzdt, v.getZ().getPartialDerivative(0, 0, 0, 1), 1.0e-12);
- }
-
-}
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationOrderTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationOrderTest.java
deleted file mode 100644
index 68bc5b9..0000000
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationOrderTest.java
+++ /dev/null
@@ -1,59 +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.threed;
-
-import java.lang.reflect.Field;
-
-import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder;
-import org.junit.Assert;
-import org.junit.Test;
-
-
-public class RotationOrderTest {
-
- @Test
- public void testName() {
-
- RotationOrder[] orders = {
- RotationOrder.XYZ, RotationOrder.XZY, RotationOrder.YXZ,
- RotationOrder.YZX, RotationOrder.ZXY, RotationOrder.ZYX,
- RotationOrder.XYX, RotationOrder.XZX, RotationOrder.YXY,
- RotationOrder.YZY, RotationOrder.ZXZ, RotationOrder.ZYZ
- };
-
- for (int i = 0; i < orders.length; ++i) {
- Assert.assertEquals(getFieldName(orders[i]), orders[i].toString());
- }
-
- }
-
- private String getFieldName(RotationOrder order) {
- try {
- Field[] fields = RotationOrder.class.getFields();
- for (int i = 0; i < fields.length; ++i) {
- if (fields[i].get(null) == order) {
- return fields[i].getName();
- }
- }
- } catch (IllegalAccessException iae) {
- // ignored
- }
- return "unknown";
- }
-
-}