commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1449529 [2/5] - in /commons/proper/math/trunk/src: changes/ main/java/org/apache/commons/math3/ main/java/org/apache/commons/math3/analysis/differentiation/ main/java/org/apache/commons/math3/dfp/ main/java/org/apache/commons/math3/geometr...
Date Sun, 24 Feb 2013 19:13:17 GMT
Copied: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/FieldRotation.java (from r1449528, commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/RotationDS.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/FieldRotation.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/FieldRotation.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/RotationDS.java&r1=1449528&r2=1449529&rev=1449529&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/RotationDS.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/FieldRotation.java Sun Feb 24 19:13:17 2013
@@ -19,8 +19,8 @@ package org.apache.commons.math3.geometr
 
 import java.io.Serializable;
 
+import org.apache.commons.math3.ExtendedFieldElement;
 import org.apache.commons.math3.Field;
-import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
 import org.apache.commons.math3.exception.MathArithmeticException;
 import org.apache.commons.math3.exception.MathIllegalArgumentException;
 import org.apache.commons.math3.exception.util.LocalizedFormats;
@@ -28,31 +28,32 @@ import org.apache.commons.math3.util.Fas
 import org.apache.commons.math3.util.MathArrays;
 
 /**
- * This class is a re-implementation of {@link Rotation} using {@link DerivativeStructure}.
+ * This class is a re-implementation of {@link Rotation} using {@link ExtendedFieldElement}.
  * <p>Instance of this class are guaranteed to be immutable.</p>
  *
+ * @param <T> the type of the field elements
  * @version $Id$
  * @see Vector3DDSDS
  * @see RotationOrder
  * @since 3.2
  */
 
-public class RotationDS implements Serializable {
+public class FieldRotation<T extends ExtendedFieldElement<T>> implements Serializable {
 
     /** Serializable version identifier */
-    private static final long serialVersionUID = 20130215l;
+    private static final long serialVersionUID = 20130224l;
 
     /** Scalar coordinate of the quaternion. */
-    private final DerivativeStructure q0;
+    private final T q0;
 
     /** First coordinate of the vectorial part of the quaternion. */
-    private final DerivativeStructure q1;
+    private final T q1;
 
     /** Second coordinate of the vectorial part of the quaternion. */
-    private final DerivativeStructure q2;
+    private final T q2;
 
     /** Third coordinate of the vectorial part of the quaternion. */
-    private final DerivativeStructure q3;
+    private final T q3;
 
     /** Build a rotation from the quaternion coordinates.
      * <p>A rotation can be built from a <em>normalized</em> quaternion,
@@ -72,13 +73,11 @@ public class RotationDS implements Seria
      * not to be normalized, a normalization preprocessing step is performed
      * before using them
      */
-    public RotationDS(final DerivativeStructure q0, final DerivativeStructure q1,
-                      final DerivativeStructure q2, final DerivativeStructure q3,
-                      final boolean needsNormalization) {
+    public FieldRotation(final T q0, final T q1, final T q2, final T q3, final boolean needsNormalization) {
 
         if (needsNormalization) {
             // normalization preprocessing
-            final DerivativeStructure inv =
+            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);
@@ -98,7 +97,7 @@ public class RotationDS implements Seria
      * 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 &pi;/2 as the angle to this constructor, and then
-     * {@link #applyTo(Vector3DDS) apply} the instance to +i, we will get
+     * {@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 &theta; about the unit vector (x, y, z) is the same as the
@@ -114,16 +113,16 @@ public class RotationDS implements Seria
      * @param angle rotation angle.
      * @exception MathIllegalArgumentException if the axis norm is zero
      */
-    public RotationDS(final Vector3DDS axis, final DerivativeStructure angle)
+    public FieldRotation(final FieldVector3D<T> axis, final T angle)
         throws MathIllegalArgumentException {
 
-        final DerivativeStructure norm = axis.getNorm();
-        if (norm.getValue() == 0) {
+        final T norm = axis.getNorm();
+        if (norm.getReal() == 0) {
             throw new MathIllegalArgumentException(LocalizedFormats.ZERO_NORM_FOR_ROTATION_AXIS);
         }
 
-        final DerivativeStructure halfAngle = angle.multiply(-0.5);
-        final DerivativeStructure coeff = halfAngle.sin().divide(norm);
+        final T halfAngle = angle.multiply(-0.5);
+        final T coeff = halfAngle.sin().divide(norm);
 
         q0 = halfAngle.cos();
         q1 = coeff.multiply(axis.getX());
@@ -162,7 +161,7 @@ public class RotationDS implements Seria
      * orthogonal matrix is negative
 
      */
-    public RotationDS(final DerivativeStructure[][] m, final double threshold)
+    public FieldRotation(final T[][] m, final double threshold)
         throws NotARotationMatrixException {
 
         // dimension check
@@ -174,21 +173,21 @@ public class RotationDS implements Seria
         }
 
         // compute a "close" orthogonal matrix
-        final DerivativeStructure[][] ort = orthogonalizeMatrix(m, threshold);
+        final T[][] ort = orthogonalizeMatrix(m, threshold);
 
         // check the sign of the determinant
-        final DerivativeStructure d0 = ort[1][1].multiply(ort[2][2]).subtract(ort[2][1].multiply(ort[1][2]));
-        final DerivativeStructure d1 = ort[0][1].multiply(ort[2][2]).subtract(ort[2][1].multiply(ort[0][2]));
-        final DerivativeStructure d2 = ort[0][1].multiply(ort[1][2]).subtract(ort[1][1].multiply(ort[0][2]));
-        final DerivativeStructure det =
+        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.getValue() < 0.0) {
+        if (det.getReal() < 0.0) {
             throw new NotARotationMatrixException(
                                                   LocalizedFormats.CLOSEST_ORTHOGONAL_MATRIX_HAS_NEGATIVE_DETERMINANT,
                                                   det);
         }
 
-        final DerivativeStructure[] quat = mat2quat(ort);
+        final T[] quat = mat2quat(ort);
         q0 = quat[0];
         q1 = quat[1];
         q2 = quat[2];
@@ -215,41 +214,34 @@ public class RotationDS implements Seria
      * @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 colinear)
      */
-    public RotationDS(Vector3DDS u1, Vector3DDS u2, Vector3DDS v1, Vector3DDS v2)
+    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 colinear, which is forbidden to define a rotation
-        final Vector3DDS u3 = u1.crossProduct(u2).normalize();
+        final FieldVector3D<T> u3 = u1.crossProduct(u2).normalize();
         u2 = u3.crossProduct(u1).normalize();
         u1 = u1.normalize();
 
         // build an orthonormalized base from v1, v2
         // this fails when vectors are null or colinear, which is forbidden to define a rotation
-        final Vector3DDS v3 = v1.crossProduct(v2).normalize();
+        final FieldVector3D<T> v3 = v1.crossProduct(v2).normalize();
         v2 = v3.crossProduct(v1).normalize();
         v1 = v1.normalize();
 
         // buid a matrix transforming the first base into the second one
-        final DerivativeStructure[][] m = new DerivativeStructure[][] {
-            {
-                MathArrays.linearCombination(u1.getX(), v1.getX(), u2.getX(), v2.getX(), u3.getX(), v3.getX()),
-                MathArrays.linearCombination(u1.getY(), v1.getX(), u2.getY(), v2.getX(), u3.getY(), v3.getX()),
-                MathArrays.linearCombination(u1.getZ(), v1.getX(), u2.getZ(), v2.getX(), u3.getZ(), v3.getX())
-            },
-            {
-                MathArrays.linearCombination(u1.getX(), v1.getY(), u2.getX(), v2.getY(), u3.getX(), v3.getY()),
-                MathArrays.linearCombination(u1.getY(), v1.getY(), u2.getY(), v2.getY(), u3.getY(), v3.getY()),
-                MathArrays.linearCombination(u1.getZ(), v1.getY(), u2.getZ(), v2.getY(), u3.getZ(), v3.getY())
-            },
-            {
-                MathArrays.linearCombination(u1.getX(), v1.getZ(), u2.getX(), v2.getZ(), u3.getX(), v3.getZ()),
-                MathArrays.linearCombination(u1.getY(), v1.getZ(), u2.getY(), v2.getZ(), u3.getY(), v3.getZ()),
-                MathArrays.linearCombination(u1.getZ(), v1.getZ(), u2.getZ(), v2.getZ(), u3.getZ(), v3.getZ())
-            }
-        };
+        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()));
 
-        DerivativeStructure[] quat = mat2quat(m);
+        T[] quat = mat2quat(array);
         q0 = quat[0];
         q1 = quat[1];
         q2 = quat[2];
@@ -270,19 +262,19 @@ public class RotationDS implements Seria
      * @param v desired image of u by the rotation
      * @exception MathArithmeticException if the norm of one of the vectors is zero
      */
-    public RotationDS(final Vector3DDS u, final Vector3DDS v) throws MathArithmeticException {
+    public FieldRotation(final FieldVector3D<T> u, final FieldVector3D<T> v) throws MathArithmeticException {
 
-        final DerivativeStructure normProduct = u.getNorm().multiply(v.getNorm());
-        if (normProduct.getValue() == 0) {
+        final T normProduct = u.getNorm().multiply(v.getNorm());
+        if (normProduct.getReal() == 0) {
             throw new MathArithmeticException(LocalizedFormats.ZERO_NORM_FOR_ROTATION_DEFINING_VECTOR);
         }
 
-        final DerivativeStructure dot = u.dotProduct(v);
+        final T dot = u.dotProduct(v);
 
-        if (dot.getValue() < ((2.0e-15 - 1.0) * normProduct.getValue())) {
+        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 Vector3DDS w = u.orthogonal();
+            final FieldVector3D<T> w = u.orthogonal();
             q0 = normProduct.getField().getZero();
             q1 = w.getX().negate();
             q2 = w.getY().negate();
@@ -291,8 +283,8 @@ public class RotationDS implements Seria
             // 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 DerivativeStructure coeff = q0.multiply(normProduct).multiply(2.0).reciprocal();
-            final Vector3DDS q = v.crossProduct(u);
+            final T coeff = q0.multiply(normProduct).multiply(2.0).reciprocal();
+            final FieldVector3D<T> q = v.crossProduct(u);
             q1 = coeff.multiply(q.getX());
             q2 = coeff.multiply(q.getY());
             q3 = coeff.multiply(q.getZ());
@@ -319,26 +311,12 @@ public class RotationDS implements Seria
      * @param alpha2 angle of the second elementary rotation
      * @param alpha3 angle of the third elementary rotation
      */
-    public RotationDS(final RotationOrder order, final DerivativeStructure alpha1,
-                      final DerivativeStructure alpha2, final DerivativeStructure alpha3) {
-        final int p = alpha1.getFreeParameters();
-        final int o  = alpha1.getOrder();
-        final RotationDS r1 =
-                new RotationDS(new Vector3DDS(new DerivativeStructure(p, o, order.getA1().getX()),
-                                              new DerivativeStructure(p, o, order.getA1().getY()),
-                                              new DerivativeStructure(p, o, order.getA1().getZ())),
-                                              alpha1);
-        final RotationDS r2 =
-                new RotationDS(new Vector3DDS(new DerivativeStructure(p, o, order.getA2().getX()),
-                                              new DerivativeStructure(p, o, order.getA2().getY()),
-                                              new DerivativeStructure(p, o, order.getA2().getZ())),
-                                              alpha2);
-        final RotationDS r3 =
-                new RotationDS(new Vector3DDS(new DerivativeStructure(p, o, order.getA3().getX()),
-                                              new DerivativeStructure(p, o, order.getA3().getY()),
-                                              new DerivativeStructure(p, o, order.getA3().getZ())),
-                                              alpha3);
-        final RotationDS composed = r1.applyTo(r2.applyTo(r3));
+    public FieldRotation(final RotationOrder order, final T alpha1, final T alpha2, final T alpha3) {
+        final T one = alpha1.getField().getOne();
+        final FieldRotation<T> r1 = new FieldRotation<T>(new FieldVector3D<T>(one, order.getA1()), alpha1);
+        final FieldRotation<T> r2 = new FieldRotation<T>(new FieldVector3D<T>(one, order.getA2()), alpha2);
+        final FieldRotation<T> r3 = new FieldRotation<T>(new FieldVector3D<T>(one, order.getA3()), alpha3);
+        final FieldRotation<T> composed = r1.applyTo(r2.applyTo(r3));
         q0 = composed.q0;
         q1 = composed.q1;
         q2 = composed.q2;
@@ -349,9 +327,9 @@ public class RotationDS implements Seria
      * @param ort orthogonal rotation matrix
      * @return quaternion corresponding to the matrix
      */
-    private static DerivativeStructure[] mat2quat(final DerivativeStructure[][] ort) {
+    private T[] mat2quat(final T[][] ort) {
 
-        final DerivativeStructure[] quat = new DerivativeStructure[4];
+        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
@@ -364,29 +342,29 @@ public class RotationDS implements Seria
         // 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)
-        DerivativeStructure s = ort[0][0].add(ort[1][1]).add(ort[2][2]);
-        if (s.getValue() > -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);
-            DerivativeStructure inv = quat[0].reciprocal().multiply(0.25);
+            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.getValue() > -0.19) {
+            if (s.getReal() > -0.19) {
                 // compute q1 and deduce q0, q2 and q3
                 quat[1] = s.add(1.0).sqrt().multiply(0.5);
-                DerivativeStructure inv = quat[1].reciprocal().multiply(0.25);
+                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.getValue() > -0.19) {
+                if (s.getReal() > -0.19) {
                     // compute q2 and deduce q0, q1 and q3
                     quat[2] = s.add(1.0).sqrt().multiply(0.5);
-                    DerivativeStructure inv = quat[2].reciprocal().multiply(0.25);
+                    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]));
@@ -394,7 +372,7 @@ public class RotationDS implements Seria
                     // 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);
-                    DerivativeStructure inv = quat[3].reciprocal().multiply(0.25);
+                    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]));
@@ -413,63 +391,63 @@ public class RotationDS implements Seria
      * @return a new rotation whose effect is the reverse of the effect
      * of the instance
      */
-    public RotationDS revert() {
-        return new RotationDS(q0.negate(), q1, q2, q3, false);
+    public FieldRotation<T> revert() {
+        return new FieldRotation<T>(q0.negate(), q1, q2, q3, false);
     }
 
     /** Get the scalar coordinate of the quaternion.
      * @return scalar coordinate of the quaternion
      */
-    public DerivativeStructure getQ0() {
+    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 DerivativeStructure getQ1() {
+    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 DerivativeStructure getQ2() {
+    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 DerivativeStructure getQ3() {
+    public T getQ3() {
         return q3;
     }
 
     /** Get the normalized axis of the rotation.
      * @return normalized axis of the rotation
-     * @see #Rotation(Vector3DDS, DerivativeStructure)
+     * @see #Rotation(FieldVector3D, T)
      */
-    public Vector3DDS getAxis() {
-        final DerivativeStructure squaredSine = q1.multiply(q1).add(q2.multiply(q2)).add(q3.multiply(q3));
-        if (squaredSine.getValue() == 0) {
-            final Field<DerivativeStructure> field = squaredSine.getField();
-            return new Vector3DDS(field.getOne(), field.getZero(), field.getZero());
-        } else if (q0.getValue() < 0) {
-            DerivativeStructure inverse = squaredSine.sqrt().reciprocal();
-            return new Vector3DDS(q1.multiply(inverse), q2.multiply(inverse), q3.multiply(inverse));
+    public FieldVector3D<T> getAxis() {
+        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<T>(field.getOne(), field.getZero(), field.getZero());
+        } else if (q0.getReal() < 0) {
+            T inverse = squaredSine.sqrt().reciprocal();
+            return new FieldVector3D<T>(q1.multiply(inverse), q2.multiply(inverse), q3.multiply(inverse));
         }
-        final DerivativeStructure inverse = squaredSine.sqrt().reciprocal().negate();
-        return new Vector3DDS(q1.multiply(inverse), q2.multiply(inverse), q3.multiply(inverse));
+        final T inverse = squaredSine.sqrt().reciprocal().negate();
+        return new FieldVector3D<T>(q1.multiply(inverse), q2.multiply(inverse), q3.multiply(inverse));
     }
 
     /** Get the angle of the rotation.
      * @return angle of the rotation (between 0 and &pi;)
-     * @see #Rotation(Vector3DDS, DerivativeStructure)
+     * @see #Rotation(FieldVector3D, T)
      */
-    public DerivativeStructure getAngle() {
-        if ((q0.getValue() < -0.1) || (q0.getValue() > 0.1)) {
+    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.getValue() < 0) {
+        } else if (q0.getReal() < 0) {
             return q0.negate().acos().multiply(2);
         }
         return q0.acos().multiply(2);
@@ -510,7 +488,7 @@ public class RotationDS implements Seria
      * @exception CardanEulerSingularityException if the rotation is
      * singular with respect to the angles set specified
      */
-    public DerivativeStructure[] getAngles(final RotationOrder order)
+    public T[] getAngles(final RotationOrder order)
         throws CardanEulerSingularityException {
 
         if (order == RotationOrder.XYZ) {
@@ -520,16 +498,14 @@ public class RotationDS implements Seria
             // (-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]
-            Vector3DDS v1 = applyTo(vector(0, 0, 1));
-            final Vector3DDS v2 = applyInverseTo(vector(1, 0, 0));
-            if  ((v2.getZ().getValue() < -0.9999999999) || (v2.getZ().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getY().negate(), v1.getZ()),
-                v2.getZ().asin(),
-                DerivativeStructure.atan2(v2.getY().negate(), v2.getX())
-            };
+            return buildArray(v1.getY().negate().atan2(v1.getZ()),
+                              v2.getZ().asin(),
+                              v2.getY().negate().atan2(v2.getX()));
 
         } else if (order == RotationOrder.XZY) {
 
@@ -538,16 +514,14 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(0, 1, 0));
-            final Vector3DDS v2 = applyInverseTo(vector(1, 0, 0));
-            if ((v2.getY().getValue() < -0.9999999999) || (v2.getY().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getZ(), v1.getY()),
-                v2.getY().asin().negate(),
-                DerivativeStructure.atan2(v2.getZ(), v2.getX())
-            };
+            return buildArray(v1.getZ().atan2(v1.getY()),
+                              v2.getY().asin().negate(),
+                              v2.getZ().atan2(v2.getX()));
 
         } else if (order == RotationOrder.YXZ) {
 
@@ -556,16 +530,14 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(0, 0, 1));
-            final Vector3DDS v2 = applyInverseTo(vector(0, 1, 0));
-            if ((v2.getZ().getValue() < -0.9999999999) || (v2.getZ().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getX(), v1.getZ()),
-                v2.getZ().asin().negate(),
-                DerivativeStructure.atan2(v2.getX(), v2.getY())
-            };
+            return buildArray(v1.getX().atan2(v1.getZ()),
+                              v2.getZ().asin().negate(),
+                              v2.getX().atan2(v2.getY()));
 
         } else if (order == RotationOrder.YZX) {
 
@@ -574,16 +546,14 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(1, 0, 0));
-            final Vector3DDS v2 = applyInverseTo(vector(0, 1, 0));
-            if ((v2.getX().getValue() < -0.9999999999) || (v2.getX().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getZ().negate(), v1.getX()),
-                v2.getX().asin(),
-                DerivativeStructure.atan2(v2.getZ().negate(), v2.getY())
-            };
+            return buildArray(v1.getZ().negate().atan2(v1.getX()),
+                              v2.getX().asin(),
+                              v2.getZ().negate().atan2(v2.getY()));
 
         } else if (order == RotationOrder.ZXY) {
 
@@ -592,16 +562,14 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(0, 1, 0));
-            final Vector3DDS v2 = applyInverseTo(vector(0, 0, 1));
-            if ((v2.getY().getValue() < -0.9999999999) || (v2.getY().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getX().negate(), v1.getY()),
-                v2.getY().asin(),
-                DerivativeStructure.atan2(v2.getX().negate(), v2.getZ())
-            };
+            return buildArray(v1.getX().negate().atan2(v1.getY()),
+                              v2.getY().asin(),
+                              v2.getX().negate().atan2(v2.getZ()));
 
         } else if (order == RotationOrder.ZYX) {
 
@@ -610,16 +578,14 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(1, 0, 0));
-            final Vector3DDS v2 = applyInverseTo(vector(0, 0, 1));
-            if ((v2.getX().getValue() < -0.9999999999) || (v2.getX().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getY(), v1.getX()),
-                v2.getX().asin().negate(),
-                DerivativeStructure.atan2(v2.getY(), v2.getZ())
-            };
+            return buildArray(v1.getY().atan2(v1.getX()),
+                              v2.getX().asin().negate(),
+                              v2.getY().atan2(v2.getZ()));
 
         } else if (order == RotationOrder.XYX) {
 
@@ -628,16 +594,14 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(1, 0, 0));
-            final Vector3DDS v2 = applyInverseTo(vector(1, 0, 0));
-            if ((v2.getX().getValue() < -0.9999999999) || (v2.getX().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getY(), v1.getZ().negate()),
-                v2.getX().acos(),
-                DerivativeStructure.atan2(v2.getY(), v2.getZ())
-            };
+            return buildArray(v1.getY().atan2(v1.getZ().negate()),
+                              v2.getX().acos(),
+                              v2.getY().atan2(v2.getZ()));
 
         } else if (order == RotationOrder.XZX) {
 
@@ -646,16 +610,14 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(1, 0, 0));
-            final Vector3DDS v2 = applyInverseTo(vector(1, 0, 0));
-            if ((v2.getX().getValue() < -0.9999999999) || (v2.getX().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getZ(), v1.getY()),
-                v2.getX().acos(),
-                DerivativeStructure.atan2(v2.getZ(), v2.getY().negate())
-            };
+            return buildArray(v1.getZ().atan2(v1.getY()),
+                              v2.getX().acos(),
+                              v2.getZ().atan2(v2.getY().negate()));
 
         } else if (order == RotationOrder.YXY) {
 
@@ -664,16 +626,14 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(0, 1, 0));
-            final Vector3DDS v2 = applyInverseTo(vector(0, 1, 0));
-            if ((v2.getY().getValue() < -0.9999999999) || (v2.getY().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getX(), v1.getZ()),
-                v2.getY().acos(),
-                DerivativeStructure.atan2(v2.getX(), v2.getZ().negate())
-            };
+            return buildArray(v1.getX().atan2(v1.getZ()),
+                              v2.getY().acos(),
+                              v2.getX().atan2(v2.getZ().negate()));
 
         } else if (order == RotationOrder.YZY) {
 
@@ -682,16 +642,14 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(0, 1, 0));
-            final Vector3DDS v2 = applyInverseTo(vector(0, 1, 0));
-            if ((v2.getY().getValue() < -0.9999999999) || (v2.getY().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getZ(), v1.getX().negate()),
-                v2.getY().acos(),
-                DerivativeStructure.atan2(v2.getZ(), v2.getX())
-            };
+            return buildArray(v1.getZ().atan2(v1.getX().negate()),
+                              v2.getY().acos(),
+                              v2.getZ().atan2(v2.getX()));
 
         } else if (order == RotationOrder.ZXZ) {
 
@@ -700,16 +658,14 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(0, 0, 1));
-            final Vector3DDS v2 = applyInverseTo(vector(0, 0, 1));
-            if ((v2.getZ().getValue() < -0.9999999999) || (v2.getZ().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getX(), v1.getY().negate()),
-                v2.getZ().acos(),
-                DerivativeStructure.atan2(v2.getX(), v2.getY())
-            };
+            return buildArray(v1.getX().atan2(v1.getY().negate()),
+                              v2.getZ().acos(),
+                              v2.getX().atan2(v2.getY()));
 
         } else { // last possibility is ZYZ
 
@@ -718,57 +674,63 @@ public class RotationDS implements Seria
             // (-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 Vector3DDS v1 = applyTo(vector(0, 0, 1));
-            final Vector3DDS v2 = applyInverseTo(vector(0, 0, 1));
-            if ((v2.getZ().getValue() < -0.9999999999) || (v2.getZ().getValue() > 0.9999999999)) {
+            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 new DerivativeStructure[] {
-                DerivativeStructure.atan2(v1.getY(), v1.getX()),
-                v2.getZ().acos(),
-                DerivativeStructure.atan2(v2.getY(), v2.getX().negate())
-            };
+            return buildArray(v1.getY().atan2(v1.getX()),
+                              v2.getZ().acos(),
+                              v2.getY().atan2(v2.getX().negate()));
 
         }
 
     }
 
-    /** Create a constant vector with appropriate derivation parameters.
+    /** 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 Vector3DDS vector(final double x, final double y, final double z) {
-        final int parameters = q0.getFreeParameters();
-        final int order      = q0.getOrder();
-        return new Vector3DDS(new DerivativeStructure(parameters, order, x),
-                              new DerivativeStructure(parameters, order, y),
-                              new DerivativeStructure(parameters, order, z));
+    private FieldVector3D<T> vector(final double x, final double y, final double z) {
+        final T zero = q0.getField().getZero();
+        return new FieldVector3D<T>(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 DerivativeStructure[][] getMatrix() {
+    public T[][] getMatrix() {
 
         // products
-        final DerivativeStructure q0q0  = q0.multiply(q0);
-        final DerivativeStructure q0q1  = q0.multiply(q1);
-        final DerivativeStructure q0q2  = q0.multiply(q2);
-        final DerivativeStructure q0q3  = q0.multiply(q3);
-        final DerivativeStructure q1q1  = q1.multiply(q1);
-        final DerivativeStructure q1q2  = q1.multiply(q2);
-        final DerivativeStructure q1q3  = q1.multiply(q3);
-        final DerivativeStructure q2q2  = q2.multiply(q2);
-        final DerivativeStructure q2q3  = q2.multiply(q3);
-        final DerivativeStructure q3q3  = q3.multiply(q3);
+        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 DerivativeStructure[][] m = new DerivativeStructure[3][];
-        m[0] = new DerivativeStructure[3];
-        m[1] = new DerivativeStructure[3];
-        m[2] = new DerivativeStructure[3];
+        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);
@@ -790,24 +752,24 @@ public class RotationDS implements Seria
      * @return a constant vector
      */
     public Rotation toRotation() {
-        return new Rotation(q0.getValue(), q1.getValue(), q2.getValue(), q3.getValue(), false);
+        return new Rotation(q0.getReal(), q1.getReal(), q2.getReal(), q3.getReal(), false);
     }
 
     /** 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 Vector3DDS applyTo(final Vector3DDS u) {
+    public FieldVector3D<T> applyTo(final FieldVector3D<T> u) {
 
-        final DerivativeStructure x = u.getX();
-        final DerivativeStructure y = u.getY();
-        final DerivativeStructure z = u.getZ();
+        final T x = u.getX();
+        final T y = u.getY();
+        final T z = u.getZ();
 
-        final DerivativeStructure s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
+        final T s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
 
-        return new Vector3DDS(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));
+        return new FieldVector3D<T>(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));
 
     }
 
@@ -815,17 +777,17 @@ public class RotationDS implements Seria
      * @param u vector to apply the rotation to
      * @return a new vector which is the image of u by the rotation
      */
-    public Vector3DDS applyTo(final Vector3D u) {
+    public FieldVector3D<T> applyTo(final Vector3D u) {
 
         final double x = u.getX();
         final double y = u.getY();
         final double z = u.getZ();
 
-        final DerivativeStructure s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
+        final T s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
 
-        return new Vector3DDS(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));
+        return new FieldVector3D<T>(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));
 
     }
 
@@ -834,13 +796,13 @@ public class RotationDS implements Seria
      * @param out an array with three items to put result to (it can be the same
      * array as in)
      */
-    public void applyTo(final DerivativeStructure[] in, final DerivativeStructure[] out) {
+    public void applyTo(final T[] in, final T[] out) {
 
-        final DerivativeStructure x = in[0];
-        final DerivativeStructure y = in[1];
-        final DerivativeStructure z = in[2];
+        final T x = in[0];
+        final T y = in[1];
+        final T z = in[2];
 
-        final DerivativeStructure s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
+        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);
@@ -852,13 +814,13 @@ public class RotationDS implements Seria
      * @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 DerivativeStructure[] out) {
+    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 DerivativeStructure s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
+        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);
@@ -871,17 +833,17 @@ public class RotationDS implements Seria
      * @param u vector to apply the rotation to
      * @return a new vector which is the image of u by the rotation
      */
-    public static Vector3DDS applyTo(final Rotation r, final Vector3DDS u) {
+    public static <T extends ExtendedFieldElement<T>> FieldVector3D<T> applyTo(final Rotation r, final FieldVector3D<T> u) {
 
-        final DerivativeStructure x = u.getX();
-        final DerivativeStructure y = u.getY();
-        final DerivativeStructure z = u.getZ();
+        final T x = u.getX();
+        final T y = u.getY();
+        final T z = u.getZ();
 
-        final DerivativeStructure s = x.multiply(r.getQ1()).add(y.multiply(r.getQ2())).add(z.multiply(r.getQ3()));
+        final T s = x.multiply(r.getQ1()).add(y.multiply(r.getQ2())).add(z.multiply(r.getQ3()));
 
-        return new Vector3DDS(x.multiply(r.getQ0()).subtract(z.multiply(r.getQ2()).subtract(y.multiply(r.getQ3()))).multiply(r.getQ0()).add(s.multiply(r.getQ1())).multiply(2).subtract(x),
-                              y.multiply(r.getQ0()).subtract(x.multiply(r.getQ3()).subtract(z.multiply(r.getQ1()))).multiply(r.getQ0()).add(s.multiply(r.getQ2())).multiply(2).subtract(y),
-                              z.multiply(r.getQ0()).subtract(y.multiply(r.getQ1()).subtract(x.multiply(r.getQ2()))).multiply(r.getQ0()).add(s.multiply(r.getQ3())).multiply(2).subtract(z));
+        return new FieldVector3D<T>(x.multiply(r.getQ0()).subtract(z.multiply(r.getQ2()).subtract(y.multiply(r.getQ3()))).multiply(r.getQ0()).add(s.multiply(r.getQ1())).multiply(2).subtract(x),
+                                    y.multiply(r.getQ0()).subtract(x.multiply(r.getQ3()).subtract(z.multiply(r.getQ1()))).multiply(r.getQ0()).add(s.multiply(r.getQ2())).multiply(2).subtract(y),
+                                    z.multiply(r.getQ0()).subtract(y.multiply(r.getQ1()).subtract(x.multiply(r.getQ2()))).multiply(r.getQ0()).add(s.multiply(r.getQ3())).multiply(2).subtract(z));
 
     }
 
@@ -889,18 +851,18 @@ public class RotationDS implements Seria
      * @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 Vector3DDS applyInverseTo(final Vector3DDS u) {
+    public FieldVector3D<T> applyInverseTo(final FieldVector3D<T> u) {
 
-        final DerivativeStructure x = u.getX();
-        final DerivativeStructure y = u.getY();
-        final DerivativeStructure z = u.getZ();
-
-        final DerivativeStructure s  = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
-        final DerivativeStructure m0 = q0.negate();
-
-        return new Vector3DDS(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));
+        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<T>(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));
 
     }
 
@@ -908,18 +870,18 @@ public class RotationDS implements Seria
      * @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 Vector3DDS applyInverseTo(final Vector3D u) {
+    public FieldVector3D<T> applyInverseTo(final Vector3D u) {
 
         final double x = u.getX();
         final double y = u.getY();
         final double z = u.getZ();
 
-        final DerivativeStructure s  = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
-        final DerivativeStructure m0 = q0.negate();
+        final T s  = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
+        final T m0 = q0.negate();
 
-        return new Vector3DDS(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));
+        return new FieldVector3D<T>(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));
 
     }
 
@@ -928,14 +890,14 @@ public class RotationDS implements Seria
      * @param out an array with three items to put result to (it can be the same
      * array as in)
      */
-    public void applyInverseTo(final DerivativeStructure[] in, final DerivativeStructure[] out) {
+    public void applyInverseTo(final T[] in, final T[] out) {
 
-        final DerivativeStructure x = in[0];
-        final DerivativeStructure y = in[1];
-        final DerivativeStructure z = in[2];
+        final T x = in[0];
+        final T y = in[1];
+        final T z = in[2];
 
-        final DerivativeStructure s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
-        final DerivativeStructure m0 = q0.negate();
+        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);
@@ -947,14 +909,14 @@ public class RotationDS implements Seria
      * @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 DerivativeStructure[] out) {
+    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 DerivativeStructure s = q1.multiply(x).add(q2.multiply(y)).add(q3.multiply(z));
-        final DerivativeStructure m0 = q0.negate();
+        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);
@@ -967,18 +929,18 @@ public class RotationDS implements Seria
      * @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 static Vector3DDS applyInverseTo(final Rotation r, final Vector3DDS u) {
+    public static <T extends ExtendedFieldElement<T>> FieldVector3D<T> applyInverseTo(final Rotation r, final FieldVector3D<T> u) {
 
-        final DerivativeStructure x = u.getX();
-        final DerivativeStructure y = u.getY();
-        final DerivativeStructure z = u.getZ();
+        final T x = u.getX();
+        final T y = u.getY();
+        final T z = u.getZ();
 
-        final DerivativeStructure s  = x.multiply(r.getQ1()).add(y.multiply(r.getQ2())).add(z.multiply(r.getQ3()));
+        final T s  = x.multiply(r.getQ1()).add(y.multiply(r.getQ2())).add(z.multiply(r.getQ3()));
         final double m0 = -r.getQ0();
 
-        return new Vector3DDS(x.multiply(m0).subtract(z.multiply(r.getQ2()).subtract(y.multiply(r.getQ3()))).multiply(m0).add(s.multiply(r.getQ1())).multiply(2).subtract(x),
-                              y.multiply(m0).subtract(x.multiply(r.getQ3()).subtract(z.multiply(r.getQ1()))).multiply(m0).add(s.multiply(r.getQ2())).multiply(2).subtract(y),
-                              z.multiply(m0).subtract(y.multiply(r.getQ1()).subtract(x.multiply(r.getQ2()))).multiply(m0).add(s.multiply(r.getQ3())).multiply(2).subtract(z));
+        return new FieldVector3D<T>(x.multiply(m0).subtract(z.multiply(r.getQ2()).subtract(y.multiply(r.getQ3()))).multiply(m0).add(s.multiply(r.getQ1())).multiply(2).subtract(x),
+                                    y.multiply(m0).subtract(x.multiply(r.getQ3()).subtract(z.multiply(r.getQ1()))).multiply(m0).add(s.multiply(r.getQ2())).multiply(2).subtract(y),
+                                    z.multiply(m0).subtract(y.multiply(r.getQ1()).subtract(x.multiply(r.getQ2()))).multiply(m0).add(s.multiply(r.getQ3())).multiply(2).subtract(z));
 
     }
 
@@ -991,12 +953,12 @@ public class RotationDS implements Seria
      * @param r rotation to apply the rotation to
      * @return a new rotation which is the composition of r by the instance
      */
-    public RotationDS applyTo(final RotationDS r) {
-        return new RotationDS(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);
+    public FieldRotation<T> applyTo(final FieldRotation<T> r) {
+        return new FieldRotation<T>(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.
@@ -1008,12 +970,12 @@ public class RotationDS implements Seria
      * @param r rotation to apply the rotation to
      * @return a new rotation which is the composition of r by the instance
      */
-    public RotationDS applyTo(final Rotation r) {
-        return new RotationDS(q0.multiply(r.getQ0()).subtract(q1.multiply(r.getQ1()).add(q2.multiply(r.getQ2())).add(q3.multiply(r.getQ3()))),
-                              q0.multiply(r.getQ1()).add(q1.multiply(r.getQ0())).add(q3.multiply(r.getQ2()).subtract(q2.multiply(r.getQ3()))),
-                              q0.multiply(r.getQ2()).add(q2.multiply(r.getQ0())).add(q1.multiply(r.getQ3()).subtract(q3.multiply(r.getQ1()))),
-                              q0.multiply(r.getQ3()).add(q3.multiply(r.getQ0())).add(q2.multiply(r.getQ1()).subtract(q1.multiply(r.getQ2()))),
-                              false);
+    public FieldRotation<T> applyTo(final Rotation r) {
+        return new FieldRotation<T>(q0.multiply(r.getQ0()).subtract(q1.multiply(r.getQ1()).add(q2.multiply(r.getQ2())).add(q3.multiply(r.getQ3()))),
+                                    q0.multiply(r.getQ1()).add(q1.multiply(r.getQ0())).add(q3.multiply(r.getQ2()).subtract(q2.multiply(r.getQ3()))),
+                                    q0.multiply(r.getQ2()).add(q2.multiply(r.getQ0())).add(q1.multiply(r.getQ3()).subtract(q3.multiply(r.getQ1()))),
+                                    q0.multiply(r.getQ3()).add(q3.multiply(r.getQ0())).add(q2.multiply(r.getQ1()).subtract(q1.multiply(r.getQ2()))),
+                                    false);
     }
 
     /** Apply a rotation to another rotation.
@@ -1026,12 +988,12 @@ public class RotationDS implements Seria
      * @param rInner rotation to apply the rotation to
      * @return a new rotation which is the composition of r by the instance
      */
-    public static RotationDS applyTo(final Rotation r1, final RotationDS rInner) {
-        return new RotationDS(rInner.q0.multiply(r1.getQ0()).subtract(rInner.q1.multiply(r1.getQ1()).add(rInner.q2.multiply(r1.getQ2())).add(rInner.q3.multiply(r1.getQ3()))),
-                              rInner.q1.multiply(r1.getQ0()).add(rInner.q0.multiply(r1.getQ1())).add(rInner.q2.multiply(r1.getQ3()).subtract(rInner.q3.multiply(r1.getQ2()))),
-                              rInner.q2.multiply(r1.getQ0()).add(rInner.q0.multiply(r1.getQ2())).add(rInner.q3.multiply(r1.getQ1()).subtract(rInner.q1.multiply(r1.getQ3()))),
-                              rInner.q3.multiply(r1.getQ0()).add(rInner.q0.multiply(r1.getQ3())).add(rInner.q1.multiply(r1.getQ2()).subtract(rInner.q2.multiply(r1.getQ1()))),
-                              false);
+    public static <T extends ExtendedFieldElement<T>> FieldRotation<T> applyTo(final Rotation r1, final FieldRotation<T> rInner) {
+        return new FieldRotation<T>(rInner.q0.multiply(r1.getQ0()).subtract(rInner.q1.multiply(r1.getQ1()).add(rInner.q2.multiply(r1.getQ2())).add(rInner.q3.multiply(r1.getQ3()))),
+                                    rInner.q1.multiply(r1.getQ0()).add(rInner.q0.multiply(r1.getQ1())).add(rInner.q2.multiply(r1.getQ3()).subtract(rInner.q3.multiply(r1.getQ2()))),
+                                    rInner.q2.multiply(r1.getQ0()).add(rInner.q0.multiply(r1.getQ2())).add(rInner.q3.multiply(r1.getQ1()).subtract(rInner.q1.multiply(r1.getQ3()))),
+                                    rInner.q3.multiply(r1.getQ0()).add(rInner.q0.multiply(r1.getQ3())).add(rInner.q1.multiply(r1.getQ2()).subtract(rInner.q2.multiply(r1.getQ1()))),
+                                    false);
     }
 
     /** Apply the inverse of the instance to another rotation.
@@ -1045,12 +1007,12 @@ public class RotationDS implements Seria
      * @return a new rotation which is the composition of r by the inverse
      * of the instance
      */
-    public RotationDS applyInverseTo(final RotationDS r) {
-        return new RotationDS(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);
+    public FieldRotation<T> applyInverseTo(final FieldRotation<T> r) {
+        return new FieldRotation<T>(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.
@@ -1064,12 +1026,12 @@ public class RotationDS implements Seria
      * @return a new rotation which is the composition of r by the inverse
      * of the instance
      */
-    public RotationDS applyInverseTo(final Rotation r) {
-        return new RotationDS(q0.multiply(r.getQ0()).add(q1.multiply(r.getQ1()).add(q2.multiply(r.getQ2())).add(q3.multiply(r.getQ3()))).negate(),
-                              q1.multiply(r.getQ0()).add(q3.multiply(r.getQ2()).subtract(q2.multiply(r.getQ3()))).subtract(q0.multiply(r.getQ1())),
-                              q2.multiply(r.getQ0()).add(q1.multiply(r.getQ3()).subtract(q3.multiply(r.getQ1()))).subtract(q0.multiply(r.getQ2())),
-                              q3.multiply(r.getQ0()).add(q2.multiply(r.getQ1()).subtract(q1.multiply(r.getQ2()))).subtract(q0.multiply(r.getQ3())),
-                              false);
+    public FieldRotation<T> applyInverseTo(final Rotation r) {
+        return new FieldRotation<T>(q0.multiply(r.getQ0()).add(q1.multiply(r.getQ1()).add(q2.multiply(r.getQ2())).add(q3.multiply(r.getQ3()))).negate(),
+                                    q1.multiply(r.getQ0()).add(q3.multiply(r.getQ2()).subtract(q2.multiply(r.getQ3()))).subtract(q0.multiply(r.getQ1())),
+                                    q2.multiply(r.getQ0()).add(q1.multiply(r.getQ3()).subtract(q3.multiply(r.getQ1()))).subtract(q0.multiply(r.getQ2())),
+                                    q3.multiply(r.getQ0()).add(q2.multiply(r.getQ1()).subtract(q1.multiply(r.getQ2()))).subtract(q0.multiply(r.getQ3())),
+                                    false);
     }
 
     /** Apply the inverse of a rotation to another rotation.
@@ -1084,12 +1046,12 @@ public class RotationDS implements Seria
      * @return a new rotation which is the composition of r by the inverse
      * of the instance
      */
-    public static RotationDS applyInverseTo(final Rotation rOuter, final RotationDS rInner) {
-        return new RotationDS(rInner.q0.multiply(rOuter.getQ0()).add(rInner.q1.multiply(rOuter.getQ1()).add(rInner.q2.multiply(rOuter.getQ2())).add(rInner.q3.multiply(rOuter.getQ3()))).negate(),
-                              rInner.q0.multiply(rOuter.getQ1()).add(rInner.q2.multiply(rOuter.getQ3()).subtract(rInner.q3.multiply(rOuter.getQ2()))).subtract(rInner.q1.multiply(rOuter.getQ0())),
-                              rInner.q0.multiply(rOuter.getQ2()).add(rInner.q3.multiply(rOuter.getQ1()).subtract(rInner.q1.multiply(rOuter.getQ3()))).subtract(rInner.q2.multiply(rOuter.getQ0())),
-                              rInner.q0.multiply(rOuter.getQ3()).add(rInner.q1.multiply(rOuter.getQ2()).subtract(rInner.q2.multiply(rOuter.getQ1()))).subtract(rInner.q3.multiply(rOuter.getQ0())),
-                              false);
+    public static <T extends ExtendedFieldElement<T>> FieldRotation<T> applyInverseTo(final Rotation rOuter, final FieldRotation<T> rInner) {
+        return new FieldRotation<T>(rInner.q0.multiply(rOuter.getQ0()).add(rInner.q1.multiply(rOuter.getQ1()).add(rInner.q2.multiply(rOuter.getQ2())).add(rInner.q3.multiply(rOuter.getQ3()))).negate(),
+                                    rInner.q0.multiply(rOuter.getQ1()).add(rInner.q2.multiply(rOuter.getQ3()).subtract(rInner.q3.multiply(rOuter.getQ2()))).subtract(rInner.q1.multiply(rOuter.getQ0())),
+                                    rInner.q0.multiply(rOuter.getQ2()).add(rInner.q3.multiply(rOuter.getQ1()).subtract(rInner.q1.multiply(rOuter.getQ3()))).subtract(rInner.q2.multiply(rOuter.getQ0())),
+                                    rInner.q0.multiply(rOuter.getQ3()).add(rInner.q1.multiply(rOuter.getQ2()).subtract(rInner.q2.multiply(rOuter.getQ1()))).subtract(rInner.q3.multiply(rOuter.getQ0())),
+                                    false);
     }
 
     /** Perfect orthogonality on a 3X3 matrix.
@@ -1102,38 +1064,37 @@ public class RotationDS implements Seria
      * @exception NotARotationMatrixException if the matrix cannot be
      * orthogonalized with the given threshold after 10 iterations
      */
-    private DerivativeStructure[][] orthogonalizeMatrix(final DerivativeStructure[][] m,
-                                                        final double threshold)
+    private T[][] orthogonalizeMatrix(final T[][] m, final double threshold)
         throws NotARotationMatrixException {
 
-        DerivativeStructure x00 = m[0][0];
-        DerivativeStructure x01 = m[0][1];
-        DerivativeStructure x02 = m[0][2];
-        DerivativeStructure x10 = m[1][0];
-        DerivativeStructure x11 = m[1][1];
-        DerivativeStructure x12 = m[1][2];
-        DerivativeStructure x20 = m[2][0];
-        DerivativeStructure x21 = m[2][1];
-        DerivativeStructure x22 = m[2][2];
+        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 DerivativeStructure[][] o = new DerivativeStructure[3][3];
+        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 DerivativeStructure mx00 = m[0][0].multiply(x00).add(m[1][0].multiply(x10)).add(m[2][0].multiply(x20));
-            final DerivativeStructure mx10 = m[0][1].multiply(x00).add(m[1][1].multiply(x10)).add(m[2][1].multiply(x20));
-            final DerivativeStructure mx20 = m[0][2].multiply(x00).add(m[1][2].multiply(x10)).add(m[2][2].multiply(x20));
-            final DerivativeStructure mx01 = m[0][0].multiply(x01).add(m[1][0].multiply(x11)).add(m[2][0].multiply(x21));
-            final DerivativeStructure mx11 = m[0][1].multiply(x01).add(m[1][1].multiply(x11)).add(m[2][1].multiply(x21));
-            final DerivativeStructure mx21 = m[0][2].multiply(x01).add(m[1][2].multiply(x11)).add(m[2][2].multiply(x21));
-            final DerivativeStructure mx02 = m[0][0].multiply(x02).add(m[1][0].multiply(x12)).add(m[2][0].multiply(x22));
-            final DerivativeStructure mx12 = m[0][1].multiply(x02).add(m[1][1].multiply(x12)).add(m[2][1].multiply(x22));
-            final DerivativeStructure mx22 = m[0][2].multiply(x02).add(m[1][2].multiply(x12)).add(m[2][2].multiply(x22));
+            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));
@@ -1147,15 +1108,15 @@ public class RotationDS implements Seria
             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].getValue() - m[0][0].getValue();
-            final double corr01 = o[0][1].getValue() - m[0][1].getValue();
-            final double corr02 = o[0][2].getValue() - m[0][2].getValue();
-            final double corr10 = o[1][0].getValue() - m[1][0].getValue();
-            final double corr11 = o[1][1].getValue() - m[1][1].getValue();
-            final double corr12 = o[1][2].getValue() - m[1][2].getValue();
-            final double corr20 = o[2][0].getValue() - m[2][0].getValue();
-            final double corr21 = o[2][1].getValue() - m[2][1].getValue();
-            final double corr22 = o[2][2].getValue() - m[2][2].getValue();
+            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 +
@@ -1211,7 +1172,7 @@ public class RotationDS implements Seria
      * @param r2 second rotation
      * @return <i>distance</i> between r1 and r2
      */
-    public static DerivativeStructure distance(final RotationDS r1, final RotationDS r2) {
+    public static <T extends ExtendedFieldElement<T>> T distance(final FieldRotation<T> r1, final FieldRotation<T> r2) {
         return r1.applyInverseTo(r2).getAngle();
     }
 

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/FieldRotation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/FieldRotation.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message