Example usage for org.apache.commons.math3.geometry.euclidean.threed FieldVector3D angle

List of usage examples for org.apache.commons.math3.geometry.euclidean.threed FieldVector3D angle

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.threed FieldVector3D angle.

Prototype

public static <T extends RealFieldElement<T>> T angle(final Vector3D v1, final FieldVector3D<T> v2)
        throws MathArithmeticException 

Source Link

Document

Compute the angular separation between two vectors.

Usage

From source file:org.orekit.utils.TimeStampedFieldAngularCoordinatesTest.java

@Test
public void testRodriguesSpecialCases()
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

    // use reflection to test the private static methods
    Method getter = TimeStampedFieldAngularCoordinates.class.getDeclaredMethod("getModifiedRodrigues",
            new Class<?>[] { TimeStampedFieldAngularCoordinates.class, double[].class, double.class });
    getter.setAccessible(true);/*from  www.  j  a v a 2s.c  o  m*/
    Method factory = TimeStampedFieldAngularCoordinates.class.getDeclaredMethod("createFromModifiedRodrigues",
            new Class<?>[] { RealFieldElement[][].class, TimeStampedFieldAngularCoordinates.class });
    factory.setAccessible(true);

    // identity
    DerivativeStructure[][] identity = (DerivativeStructure[][]) getter.invoke(null, identity(),
            new double[] { 1.0, 0.0, 0.0, 0.0 }, -0.9999);
    @SuppressWarnings("unchecked")
    TimeStampedFieldAngularCoordinates<DerivativeStructure> acId = (TimeStampedFieldAngularCoordinates<DerivativeStructure>) factory
            .invoke(null, identity, identity());
    for (DerivativeStructure element : identity[0]) {
        Assert.assertEquals(0.0, element.getReal(), Precision.SAFE_MIN);
    }
    for (DerivativeStructure element : identity[1]) {
        Assert.assertEquals(0.0, element.getReal(), Precision.SAFE_MIN);
    }
    Assert.assertEquals(0.0, acId.getRotation().getAngle().getReal(), Precision.SAFE_MIN);
    Assert.assertEquals(0.0, acId.getRotationRate().getNorm().getReal(), Precision.SAFE_MIN);

    // PI angle FieldRotation<DerivativeStructure> (which is singular for non-modified Rodrigues vector)
    Random random = new Random(0x2158523e6accb859l);
    double[] previous = new double[] { 1.0, 0.0, 0.0, 0.0 };
    for (int i = 0; i < 100; ++i) {
        FieldVector3D<DerivativeStructure> axis = randomVector(random, 1.0);
        DerivativeStructure[][] piRotation = (DerivativeStructure[][]) getter.invoke(null,
                new TimeStampedFieldAngularCoordinates<DerivativeStructure>(AbsoluteDate.J2000_EPOCH,
                        createRotation(axis, FastMath.PI), createVector(0, 0, 0, 4), createVector(0, 0, 0, 4)),
                previous, -0.9999);
        @SuppressWarnings("unchecked")
        TimeStampedFieldAngularCoordinates<DerivativeStructure> acPi = (TimeStampedFieldAngularCoordinates<DerivativeStructure>) factory
                .invoke(null, piRotation, identity());
        Assert.assertEquals(FastMath.PI, acPi.getRotation().getAngle().getReal(), 1.0e-15);
        Assert.assertEquals(0.0, FieldVector3D.angle(axis, acPi.getRotation().getAxis()).sin().getReal(),
                1.0e-15);
        Assert.assertEquals(0.0, acPi.getRotationRate().getNorm().getReal(), 1.0e-16);
    }

    // 2 PI angle FieldRotation<DerivativeStructure> (which is singular for modified Rodrigues vector)
    Assert.assertNull(getter.invoke(null, identity(), new double[] { -1.0, 0.0, 0.0, 0.0 }, -0.9999));
    Assert.assertNotNull(getter.invoke(null, identity(), new double[] { +1.0, 0.0, 0.0, 0.0 }, -0.9999));

}