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

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

Introduction

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

Prototype

public static double angle(Vector3D v1, Vector3D v2) throws MathArithmeticException 

Source Link

Document

Compute the angular separation between two vectors.

Usage

From source file:org.orekit.forces.radiation.SolarRadiationPressure.java

/** Get the useful angles for eclipse computation.
 * @param position the satellite's position in the selected frame.
 * @param frame in which is defined the position
 * @param date the date//from   w  w  w  . ja va 2 s. c  o m
 * @return the 3 angles {(satCentral, satSun), Central body apparent radius, Sun apparent radius}
 * @exception OrekitException if the trajectory is inside the Earth
 */
private double[] getEclipseAngles(final Vector3D position, final Frame frame, final AbsoluteDate date)
        throws OrekitException {
    final double[] angle = new double[3];

    final Vector3D satSunVector = sun.getPVCoordinates(date, frame).getPosition().subtract(position);

    // Sat-Sun / Sat-CentralBody angle
    angle[0] = Vector3D.angle(satSunVector, position.negate());

    // Central body apparent radius
    final double r = position.getNorm();
    if (r <= equatorialRadius) {
        throw new OrekitException(OrekitMessages.TRAJECTORY_INSIDE_BRILLOUIN_SPHERE, r);
    }
    angle[1] = FastMath.asin(equatorialRadius / r);

    // Sun apparent radius
    angle[2] = FastMath.asin(Constants.SUN_RADIUS / satSunVector.getNorm());

    return angle;
}

From source file:org.orekit.frames.FramesFactoryTest.java

private void testCIP(IERSConventions conventions, double threshold) throws OrekitException {
    Utils.setLoaders(conventions, new ArrayList<EOPEntry>());
    Frame cirf = FramesFactory.getCIRF(conventions, false);
    Frame tod = FramesFactory.getTOD(conventions, false);
    AbsoluteDate t0 = new AbsoluteDate(new DateComponents(2003, 06, 21), TimeComponents.H00,
            TimeScalesFactory.getUTC());
    for (double dt = -30 * Constants.JULIAN_DAY; dt < 30 * Constants.JULIAN_DAY; dt += 3600) {
        // CIRF and TOD should both have the Celestial Intermediate Pole as their Z axis
        AbsoluteDate date = t0.shiftedBy(dt);
        Transform t = FramesFactory.getNonInterpolatingTransform(tod, cirf, date);
        Vector3D z = t.transformVector(Vector3D.PLUS_K);
        Assert.assertEquals(0.0, Vector3D.angle(z, Vector3D.PLUS_K), threshold);
    }//from  w w  w  .j a  va 2 s .c om
}

From source file:org.orekit.frames.FramesFactoryTest.java

@Test
public void testEOPConversion() throws OrekitException {

    // real data from buletinb-298.txt

    // first use case: don't propagate the dx, dy correction to TOD, set dPsi, dEpsilon to 0.0
    final List<EOPEntry> forced = Utils.buildEOPList(IERSConventions.IERS_2010,
            new double[][] { { 56202, 0.3726886, 0.0008843, 0.168556, 0.332869, 0.0, 0.0, -0.000118, 0.000091 },
                    { 56203, 0.3719108, 0.0007204, 0.168261, 0.331527, 0.0, 0.0, -0.000140, 0.000111 },
                    { 56204, 0.3712561, 0.0006217, 0.168218, 0.330668, 0.0, 0.0, -0.000165, 0.000148 },
                    { 56205, 0.3706736, 0.0005530, 0.167775, 0.329688, 0.0, 0.0, -0.000188, 0.000189 },
                    { 56206, 0.3701593, 0.0005139, 0.166829, 0.328457, 0.0, 0.0, -0.000180, 0.000203 } });

    Utils.setLoaders(IERSConventions.IERS_2010, forced);
    Frame cirf = FramesFactory.getCIRF(IERSConventions.IERS_2010, false);
    Frame todNoCorrection = FramesFactory.getTOD(IERSConventions.IERS_2010, false);

    // second use case: convert dx, dy data into dDPsi, dDEpsilon
    final List<EOPEntry> converted = Utils.buildEOPList(IERSConventions.IERS_2010, new double[][] {
            { 56202, 0.3726886, 0.0008843, 0.168556, 0.332869, Double.NaN, Double.NaN, -0.000118, 0.000091 },
            { 56203, 0.3719108, 0.0007204, 0.168261, 0.331527, Double.NaN, Double.NaN, -0.000140, 0.000111 },
            { 56204, 0.3712561, 0.0006217, 0.168218, 0.330668, Double.NaN, Double.NaN, -0.000165, 0.000148 },
            { 56205, 0.3706736, 0.0005530, 0.167775, 0.329688, Double.NaN, Double.NaN, -0.000188, 0.000189 },
            { 56206, 0.3701593, 0.0005139, 0.166829, 0.328457, Double.NaN, Double.NaN, -0.000180, 0.000203 } });
    Utils.setLoaders(IERSConventions.IERS_2010, converted);
    Frame todConvertedCorrection = FramesFactory.getTOD(IERSConventions.IERS_2010, false);

    for (AbsoluteDate date = forced.get(0).getDate(); date
            .compareTo(forced.get(forced.size() - 1).getDate()) < 0; date = date.shiftedBy(3600)) {
        Transform tNoCorrection = FramesFactory.getNonInterpolatingTransform(todNoCorrection, cirf, date);

        // when we forget the correction on TOD,
        // its Z axis is slightly offset from CIRF Z axis
        Vector3D zNoCorrection = tNoCorrection.transformVector(Vector3D.PLUS_K);
        Assert.assertTrue(Vector3D.angle(zNoCorrection, Vector3D.PLUS_K) > 7.2e-10);
        Transform tConverted = FramesFactory.getNonInterpolatingTransform(todConvertedCorrection, cirf, date);
        // when we convert the correction and apply it to TOD,
        // its Z axis is much better aligned with CIRF Z axis
        Vector3D zConverted = tConverted.transformVector(Vector3D.PLUS_K);
        Assert.assertTrue(Vector3D.angle(zConverted, Vector3D.PLUS_K) < 6e-12);

    }/*from   www . j a  v  a  2 s  . c om*/

}

From source file:org.orekit.frames.ITRFProviderWithoutTidalEffectsTest.java

@Test
public void testRoughRotation() throws OrekitException {

    AbsoluteDate date1 = new AbsoluteDate(new DateComponents(2006, 02, 24), new TimeComponents(15, 38, 00),
            TimeScalesFactory.getUTC());
    Frame itrf2008 = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
    Transform t0 = itrf2008.getTransformTo(FramesFactory.getEME2000(), date1);

    double dt = 10.0;
    AbsoluteDate date2 = date1.shiftedBy(dt);
    Transform t1 = itrf2008.getTransformTo(FramesFactory.getEME2000(), date2);
    Transform evolution = new Transform(date2, t0.getInverse(), t1);

    Vector3D p = new Vector3D(6000, 6000, 0);
    Assert.assertEquals(0.0, evolution.transformPosition(Vector3D.ZERO).getNorm(), 1.0e-15);
    Assert.assertEquals(0.0, evolution.transformVector(p).getZ(), 0.003);
    Assert.assertEquals(2 * FastMath.PI * dt / 86164,
            Vector3D.angle(t0.transformVector(p), t1.transformVector(p)), 1.0e-9);

}

From source file:org.orekit.frames.ITRFProviderWithoutTidalEffectsTest.java

@Test
public void testRoughOrientation() throws OrekitException {

    AbsoluteDate date = new AbsoluteDate(2001, 03, 21, 0, 4, 0, TimeScalesFactory.getUTC());
    Frame itrf2008 = FramesFactory.getITRF(IERSConventions.IERS_2010, true);

    Vector3D u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I);
    Assert.assertTrue(Vector3D.angle(u, Vector3D.MINUS_I) < FastMath.toRadians(0.5));

    date = date.shiftedBy(6 * 3600);//  ww w . ja v  a 2s . c om
    u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I);
    Assert.assertTrue(Vector3D.angle(u, Vector3D.MINUS_J) < FastMath.toRadians(0.5));

    date = date.shiftedBy(6 * 3600);
    u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I);
    Assert.assertTrue(Vector3D.angle(u, Vector3D.PLUS_I) < FastMath.toRadians(0.5));

    date = date.shiftedBy(6 * 3600);
    u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I);
    Assert.assertTrue(Vector3D.angle(u, Vector3D.PLUS_J) < FastMath.toRadians(0.5));

}

From source file:org.orekit.frames.LocalOrbitalFrameTest.java

private void checkFrame(LOFType type, AbsoluteDate date, Vector3D expectedXDirection,
        Vector3D expectedYDirection, Vector3D expectedZDirection, Vector3D expectedRotationDirection)
        throws OrekitException {
    LocalOrbitalFrame lof = new LocalOrbitalFrame(FramesFactory.getGCRF(), type, provider, type.name());

    Transform t = lof.getTransformTo(FramesFactory.getGCRF(), date);
    PVCoordinates pv1 = t.transformPVCoordinates(PVCoordinates.ZERO);
    Vector3D p1 = pv1.getPosition();
    Vector3D v1 = pv1.getVelocity();
    PVCoordinates pv2 = provider.getPVCoordinates(date, FramesFactory.getGCRF());
    Vector3D p2 = pv2.getPosition();
    Vector3D v2 = pv2.getVelocity();
    Assert.assertEquals(0, p1.subtract(p2).getNorm(), 1.0e-14 * p1.getNorm());
    Assert.assertEquals(0, v1.subtract(v2).getNorm(), 1.0e-14 * v1.getNorm());

    Vector3D xDirection = t.transformVector(Vector3D.PLUS_I);
    Vector3D yDirection = t.transformVector(Vector3D.PLUS_J);
    Vector3D zDirection = t.transformVector(Vector3D.PLUS_K);
    Assert.assertEquals(0, Vector3D.angle(expectedXDirection, xDirection), 2.0e-15);
    Assert.assertEquals(0, Vector3D.angle(expectedYDirection, yDirection), 1.0e-15);
    Assert.assertEquals(0, Vector3D.angle(expectedZDirection, zDirection), 1.0e-15);
    Assert.assertEquals(0, Vector3D.angle(expectedRotationDirection, t.getRotationRate()), 1.0e-15);

    Assert.assertEquals(initialOrbit.getKeplerianMeanMotion(), t.getRotationRate().getNorm(), 1.0e-7);

}

From source file:org.orekit.frames.TransformTest.java

@Test
public void testRotation() {
    RandomGenerator rnd = new Well19937a(0x73d5554d99427af0l);
    for (int i = 0; i < 10; ++i) {

        Rotation r = randomRotation(rnd);
        Vector3D axis = r.getAxis();
        double angle = r.getAngle();

        Transform transform = new Transform(AbsoluteDate.J2000_EPOCH, r);
        for (int j = 0; j < 10; ++j) {
            Vector3D a = new Vector3D(rnd.nextDouble(), rnd.nextDouble(), rnd.nextDouble());
            Vector3D b = transform.transformVector(a);
            Assert.assertEquals(Vector3D.angle(axis, a), Vector3D.angle(axis, b), 1.0e-14);
            Vector3D aOrtho = Vector3D.crossProduct(axis, a);
            Vector3D bOrtho = Vector3D.crossProduct(axis, b);
            Assert.assertEquals(angle, Vector3D.angle(aOrtho, bOrtho), 1.0e-14);
            Vector3D c = transform.transformPosition(a);
            Assert.assertEquals(0, c.subtract(b).getNorm(), 1.0e-14);
        }/* w  w  w  .  j av a  2  s.  c om*/

    }
}

From source file:org.orekit.models.earth.tessellation.AlongTrackAimingTest.java

@Test
public void testAscending() throws OrekitException {
    final AlongTrackAiming tileAiming = new AlongTrackAiming(ellipsoid, orbit, true);
    for (double latitude = FastMath.toRadians(-50.21); latitude < FastMath
            .toRadians(50.21); latitude += 0.001) {
        final GeodeticPoint gp = new GeodeticPoint(latitude, 0.0, 0.0);
        final Vector3D aiming = tileAiming.alongTileDirection(ellipsoid.transform(gp), gp);
        Assert.assertEquals(1.0, aiming.getNorm(), 1.0e-12);
        final double elevation = 0.5 * FastMath.PI - Vector3D.angle(aiming, gp.getZenith());
        final double azimuth = FastMath.atan2(Vector3D.dotProduct(aiming, gp.getEast()),
                Vector3D.dotProduct(aiming, gp.getNorth()));
        Assert.assertEquals(0.0, FastMath.toDegrees(elevation), 1.0e-6);
        if (FastMath.abs(FastMath.toDegrees(latitude)) > 49.6) {
            Assert.assertTrue(FastMath.toDegrees(azimuth) > 80.0);
        }/*w w w. j  ava2s .co m*/
        if (FastMath.abs(FastMath.toDegrees(latitude)) < 5.0) {
            Assert.assertTrue(FastMath.toDegrees(azimuth) < 37.0);
        }
        Assert.assertTrue(FastMath.toDegrees(azimuth) > 36.7);
    }
}

From source file:org.orekit.models.earth.tessellation.AlongTrackAimingTest.java

@Test
public void testDescending() throws OrekitException {
    final AlongTrackAiming tileAiming = new AlongTrackAiming(ellipsoid, orbit, false);
    for (double latitude = FastMath.toRadians(-50.21); latitude < FastMath
            .toRadians(50.21); latitude += 0.001) {
        final GeodeticPoint gp = new GeodeticPoint(latitude, 0.0, 0.0);
        final Vector3D aiming = tileAiming.alongTileDirection(ellipsoid.transform(gp), gp);
        Assert.assertEquals(1.0, aiming.getNorm(), 1.0e-12);
        final double elevation = 0.5 * FastMath.PI - Vector3D.angle(aiming, gp.getZenith());
        final double azimuth = MathUtils.normalizeAngle(FastMath
                .atan2(Vector3D.dotProduct(aiming, gp.getEast()), Vector3D.dotProduct(aiming, gp.getNorth())),
                FastMath.PI);/*w w w  .  ja  v  a2  s  .  c  o  m*/
        Assert.assertEquals(0.0, FastMath.toDegrees(elevation), 1.0e-6);
        if (FastMath.abs(FastMath.toDegrees(latitude)) > 49.7) {
            Assert.assertTrue(FastMath.toDegrees(azimuth) < 99.0);
        }
        if (FastMath.abs(FastMath.toDegrees(latitude)) < 5.0) {
            Assert.assertTrue(FastMath.toDegrees(azimuth) > 143);
        }
        Assert.assertTrue(FastMath.toDegrees(azimuth) < 143.3);
    }
}

From source file:org.orekit.models.earth.tessellation.Tile.java

/** Interpolate a vector along a unit sphere.
 * @param p0 first base unit vector/*from   w  w w  .ja v  a  2  s.co m*/
 * @param p1 second base unit vector
 * @param r interpolation parameter (0 for p0, 1 for p1)
 * @return interpolated unit vector
 */
private Vector3D interpolate(final Vector3D p0, final Vector3D p1, final double r) {

    // find all interpolation angles
    final double theta = Vector3D.angle(p0, p1);
    final double alpha = r * theta;
    final double thetaMAlpha = (1 - r) * theta;

    final double sinTheta = FastMath.sin(theta);
    final double sinAlpha = FastMath.sin(alpha);
    final double sinThetaMAlpha = FastMath.sin(thetaMAlpha);

    // interpolate
    return new Vector3D(sinThetaMAlpha / sinTheta, p0, sinAlpha / sinTheta, p1);

}