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.attitudes.NadirPointingTest.java

/** Vertical test : check that Z satellite axis is collinear to local vertical axis,
which direction is : (cos(lon)*cos(lat), sin(lon)*cos(lat), sin(lat)),
where lon et lat stand for observed point coordinates
(i.e satellite ones, since they are the same by construction,
but that's what is to test.// ww w  . j  a v a 2  s  . c om
 */
@Test
public void testVertical() throws OrekitException {

    // Elliptic earth shape
    OneAxisEllipsoid earthShape = new OneAxisEllipsoid(6378136.460, 1 / 298.257222101, itrf);

    // Create earth center pointing attitude provider
    NadirPointing nadirAttitudeLaw = new NadirPointing(FramesFactory.getEME2000(), earthShape);

    //  Satellite on any position
    CircularOrbit circ = new CircularOrbit(7178000.0, 1.e-5, 0., FastMath.toRadians(50.), 0.,
            FastMath.toRadians(90.), PositionAngle.TRUE, FramesFactory.getEME2000(), date, mu);

    //  Vertical test
    // ***************
    // Get observed ground point position/velocity
    TimeStampedPVCoordinates pvTargetItrf = nadirAttitudeLaw.getTargetPV(circ, date, itrf);

    // Convert to geodetic coordinates
    GeodeticPoint geoTarget = earthShape.transform(pvTargetItrf.getPosition(), itrf, date);

    // Compute local vertical axis
    double xVert = FastMath.cos(geoTarget.getLongitude()) * FastMath.cos(geoTarget.getLatitude());
    double yVert = FastMath.sin(geoTarget.getLongitude()) * FastMath.cos(geoTarget.getLatitude());
    double zVert = FastMath.sin(geoTarget.getLatitude());
    Vector3D targetVertical = new Vector3D(xVert, yVert, zVert);

    // Get attitude rotation state
    Rotation rotSatEME2000 = nadirAttitudeLaw.getAttitude(circ, date, circ.getFrame()).getRotation();

    // Get satellite Z axis in EME2000 frame
    Vector3D zSatEME2000 = rotSatEME2000.applyInverseTo(Vector3D.PLUS_K);
    Vector3D zSatItrf = FramesFactory.getEME2000().getTransformTo(itrf, date).transformVector(zSatEME2000);

    // Check that satellite Z axis is collinear to local vertical axis
    double angle = Vector3D.angle(zSatItrf, targetVertical);
    Assert.assertEquals(0.0, FastMath.sin(angle), Utils.epsilonTest);

}

From source file:org.orekit.attitudes.SpinStabilizedTest.java

@Test
public void testBBQMode() throws OrekitException {
    PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
    AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789),
            TimeScalesFactory.getTAI());
    double rate = 2.0 * FastMath.PI / (12 * 60);
    AttitudeProvider bbq = new SpinStabilized(new CelestialBodyPointed(FramesFactory.getEME2000(), sun,
            Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_K), date, Vector3D.PLUS_K, rate);
    PVCoordinates pv = new PVCoordinates(new Vector3D(28812595.32012577, 5948437.4640250085, 0),
            new Vector3D(0, 0, 3680.853673522056));
    KeplerianOrbit kep = new KeplerianOrbit(pv, FramesFactory.getEME2000(), date, 3.986004415e14);
    Attitude attitude = bbq.getAttitude(kep, date, kep.getFrame());
    Vector3D xDirection = attitude.getRotation().applyInverseTo(Vector3D.PLUS_I);
    Assert.assertEquals(FastMath.atan(1.0 / 5000.0),
            Vector3D.angle(xDirection, sun.getPVCoordinates(date, FramesFactory.getEME2000()).getPosition()),
            2.0e-15);/*from w w w .  jav  a 2s .com*/
    Assert.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-6);

}

From source file:org.orekit.attitudes.SpinStabilizedTest.java

@Test
public void testSpin() throws OrekitException {

    AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789),
            TimeScalesFactory.getUTC());
    double rate = 2.0 * FastMath.PI / (12 * 60);
    AttitudeProvider law = new SpinStabilized(new InertialProvider(Rotation.IDENTITY), date, Vector3D.PLUS_K,
            rate);/*from w ww  . j a  v  a  2s. co m*/
    KeplerianOrbit orbit = new KeplerianOrbit(7178000.0, 1.e-4, FastMath.toRadians(50.),
            FastMath.toRadians(10.), FastMath.toRadians(20.), FastMath.toRadians(30.), PositionAngle.MEAN,
            FramesFactory.getEME2000(), date, 3.986004415e14);

    Propagator propagator = new KeplerianPropagator(orbit, law);

    double h = 10.0;
    SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h));
    SpacecraftState s0 = propagator.propagate(date);
    SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h));
    Vector3D spin0 = s0.getAttitude().getSpin();

    // check spin is consistent with attitude evolution
    double errorAngleMinus = Rotation.distance(sMinus.shiftedBy(h).getAttitude().getRotation(),
            s0.getAttitude().getRotation());
    double evolutionAngleMinus = Rotation.distance(sMinus.getAttitude().getRotation(),
            s0.getAttitude().getRotation());
    Assert.assertTrue(errorAngleMinus <= 1.0e-6 * evolutionAngleMinus);
    double errorAnglePlus = Rotation.distance(s0.getAttitude().getRotation(),
            sPlus.shiftedBy(-h).getAttitude().getRotation());
    double evolutionAnglePlus = Rotation.distance(s0.getAttitude().getRotation(),
            sPlus.getAttitude().getRotation());
    Assert.assertTrue(errorAnglePlus <= 1.0e-6 * evolutionAnglePlus);

    // compute spin axis using finite differences
    Rotation rM = sMinus.getAttitude().getRotation();
    Rotation rP = sPlus.getAttitude().getRotation();
    Vector3D reference = AngularCoordinates.estimateRate(rM, rP, 2 * h);

    Assert.assertEquals(2 * FastMath.PI / reference.getNorm(), 2 * FastMath.PI / spin0.getNorm(), 0.05);
    Assert.assertEquals(0.0, FastMath.toDegrees(Vector3D.angle(reference, spin0)), 1.0e-10);
    Assert.assertEquals(0.0, FastMath.toDegrees(Vector3D.angle(Vector3D.PLUS_K, spin0)), 1.0e-10);

}

From source file:org.orekit.bodies.EllipseTest.java

@Test
public void testMeridianShape() throws OrekitException {
    OneAxisEllipsoid model = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
            Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    Ellipse e = model.getPlaneSection(new Vector3D(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, 0, 0),
            Vector3D.PLUS_J);//from w ww. j a v a 2  s  . c  o  m
    Assert.assertEquals(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, e.getA(),
            1.0e-15 * Constants.WGS84_EARTH_EQUATORIAL_RADIUS);
    Assert.assertEquals(Constants.WGS84_EARTH_EQUATORIAL_RADIUS * (1 - Constants.WGS84_EARTH_FLATTENING),
            e.getB(), 1.0e-15 * Constants.WGS84_EARTH_EQUATORIAL_RADIUS);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_J, e.getU()), 1.0e-15);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_K, e.getU()), 1.0e-15);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_I, e.getV()), 1.0e-15);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_J, e.getV()), 1.0e-15);
}

From source file:org.orekit.forces.BoxAndSolarArraySpacecraftTest.java

@Test
public void testBestPointing() throws OrekitException {

    AbsoluteDate initialDate = propagator.getInitialState().getDate();
    CelestialBody sun = CelestialBodyFactory.getSun();
    BoxAndSolarArraySpacecraft s = new BoxAndSolarArraySpacecraft(1.5, 3.5, 2.5, sun, 20.0, Vector3D.PLUS_J,
            0.0, 0.0, 0.0);//  ww  w.ja  va 2  s .co  m
    for (double dt = 0; dt < 4000; dt += 60) {

        SpacecraftState state = propagator.propagate(initialDate.shiftedBy(dt));

        Vector3D sunInert = sun.getPVCoordinates(initialDate, state.getFrame()).getPosition();
        Vector3D momentum = state.getPVCoordinates().getMomentum();
        double sunElevation = FastMath.PI / 2 - Vector3D.angle(sunInert, momentum);
        Assert.assertEquals(15.1, FastMath.toDegrees(sunElevation), 0.1);

        Vector3D n = s.getNormal(state.getDate(), state.getFrame(), state.getPVCoordinates().getPosition(),
                state.getAttitude().getRotation());
        Assert.assertEquals(0.0, n.getY(), 1.0e-10);

        // normal misalignment should be entirely due to sun being out of orbital plane
        Vector3D sunSat = state.getAttitude().getRotation().applyTo(sunInert);
        double misAlignment = Vector3D.angle(sunSat, n);
        Assert.assertEquals(sunElevation, misAlignment, 1.0e-3);

    }
}

From source file:org.orekit.forces.BoxAndSolarArraySpacecraftTest.java

@Test
public void testCorrectFixedRate() throws OrekitException {

    AbsoluteDate initialDate = propagator.getInitialState().getDate();
    CelestialBody sun = CelestialBodyFactory.getSun();
    BoxAndSolarArraySpacecraft s = new BoxAndSolarArraySpacecraft(1.5, 3.5, 2.5, sun, 20.0, Vector3D.PLUS_J,
            initialDate, new Vector3D(0.46565509814462996, 0.0, 0.884966287251619),
            propagator.getInitialState().getKeplerianMeanMotion(), 0.0, 0.0, 0.0);

    for (double dt = 0; dt < 4000; dt += 60) {

        SpacecraftState state = propagator.propagate(initialDate.shiftedBy(dt));

        Vector3D sunInert = sun.getPVCoordinates(initialDate, state.getFrame()).getPosition();
        Vector3D momentum = state.getPVCoordinates().getMomentum();
        double sunElevation = FastMath.PI / 2 - Vector3D.angle(sunInert, momentum);
        Assert.assertEquals(15.1, FastMath.toDegrees(sunElevation), 0.1);

        Vector3D n = s.getNormal(state.getDate(), state.getFrame(), state.getPVCoordinates().getPosition(),
                state.getAttitude().getRotation());
        Assert.assertEquals(0.0, n.getY(), 1.0e-10);

        // normal misalignment should be entirely due to sun being out of orbital plane
        Vector3D sunSat = state.getAttitude().getRotation().applyTo(sunInert);
        double misAlignment = Vector3D.angle(sunSat, n);
        Assert.assertEquals(sunElevation, misAlignment, 1.0e-3);

    }// w w  w.  j av a2 s. c  om
}

From source file:org.orekit.forces.BoxAndSolarArraySpacecraftTest.java

@Test
public void testTooSlowFixedRate() throws OrekitException {

    AbsoluteDate initialDate = propagator.getInitialState().getDate();
    CelestialBody sun = CelestialBodyFactory.getSun();
    BoxAndSolarArraySpacecraft s = new BoxAndSolarArraySpacecraft(1.5, 3.5, 2.5, sun, 20.0, Vector3D.PLUS_J,
            initialDate, new Vector3D(0.46565509814462996, 0.0, 0.884966287251619),
            0.1 * propagator.getInitialState().getKeplerianMeanMotion(), 0.0, 0.0, 0.0);

    double maxDelta = 0;
    for (double dt = 0; dt < 4000; dt += 60) {

        SpacecraftState state = propagator.propagate(initialDate.shiftedBy(dt));

        Vector3D sunInert = sun.getPVCoordinates(initialDate, state.getFrame()).getPosition();
        Vector3D momentum = state.getPVCoordinates().getMomentum();
        double sunElevation = FastMath.PI / 2 - Vector3D.angle(sunInert, momentum);
        Assert.assertEquals(15.1, FastMath.toDegrees(sunElevation), 0.1);

        Vector3D n = s.getNormal(state.getDate(), state.getFrame(), state.getPVCoordinates().getPosition(),
                state.getAttitude().getRotation());
        Assert.assertEquals(0.0, n.getY(), 1.0e-10);

        // normal misalignment should become very large as solar array rotation is plain wrong
        Vector3D sunSat = state.getAttitude().getRotation().applyTo(sunInert);
        double misAlignment = Vector3D.angle(sunSat, n);
        maxDelta = FastMath.max(maxDelta, FastMath.abs(sunElevation - misAlignment));

    }/* w  ww. j av a  2 s  .  c  om*/
    Assert.assertTrue(FastMath.toDegrees(maxDelta) > 120.0);

}

From source file:org.orekit.forces.BoxAndSolarArraySpacecraftTest.java

@Test
public void testWithoutReflection() throws OrekitException {

    AbsoluteDate initialDate = propagator.getInitialState().getDate();
    CelestialBody sun = CelestialBodyFactory.getSun();
    BoxAndSolarArraySpacecraft s = new BoxAndSolarArraySpacecraft(1.5, 3.5, 2.5, sun, 20.0, Vector3D.PLUS_J,
            1.0, 1.0, 0.0);//from   w w w .java2 s . co m

    Vector3D earthRot = new Vector3D(0.0, 0.0, 7.292115e-4);
    for (double dt = 0; dt < 4000; dt += 60) {

        AbsoluteDate date = initialDate.shiftedBy(dt);
        SpacecraftState state = propagator.propagate(date);

        // simple Earth fixed atmosphere
        Vector3D p = state.getPVCoordinates().getPosition();
        Vector3D v = state.getPVCoordinates().getVelocity();
        Vector3D vAtm = Vector3D.crossProduct(earthRot, p);
        Vector3D relativeVelocity = vAtm.subtract(v);

        Vector3D drag = s.dragAcceleration(state.getDate(), state.getFrame(),
                state.getPVCoordinates().getPosition(), state.getAttitude().getRotation(), state.getMass(),
                0.001, relativeVelocity);
        Assert.assertEquals(0.0, Vector3D.angle(relativeVelocity, drag), 1.0e-10);

        Vector3D sunDirection = sun.getPVCoordinates(date, state.getFrame()).getPosition().normalize();
        Vector3D flux = new Vector3D(-4.56e-6, sunDirection);
        Vector3D radiation = s.radiationPressureAcceleration(state.getDate(), state.getFrame(),
                state.getPVCoordinates().getPosition(), state.getAttitude().getRotation(), state.getMass(),
                flux);
        Assert.assertEquals(0.0, Vector3D.angle(flux, radiation), 1.0e-9);

    }

}

From source file:org.orekit.forces.BoxAndSolarArraySpacecraftTest.java

@Test
public void testPlaneSpecularReflection() throws OrekitException {

    AbsoluteDate initialDate = propagator.getInitialState().getDate();
    CelestialBody sun = CelestialBodyFactory.getSun();
    BoxAndSolarArraySpacecraft s = new BoxAndSolarArraySpacecraft(0, 0, 0, sun, 20.0, Vector3D.PLUS_J, 0.0, 0.0,
            1.0);/*from www  .  j a  va  2s  .c om*/

    for (double dt = 0; dt < 4000; dt += 60) {

        AbsoluteDate date = initialDate.shiftedBy(dt);
        SpacecraftState state = propagator.propagate(date);

        Vector3D sunDirection = sun.getPVCoordinates(date, state.getFrame()).getPosition().normalize();
        Vector3D flux = new Vector3D(-4.56e-6, sunDirection);
        Vector3D acceleration = s.radiationPressureAcceleration(state.getDate(), state.getFrame(),
                state.getPVCoordinates().getPosition(), state.getAttitude().getRotation(), state.getMass(),
                flux);
        Vector3D normal = state.getAttitude().getRotation().applyInverseTo(s.getNormal(state.getDate(),
                state.getFrame(), state.getPVCoordinates().getPosition(), state.getAttitude().getRotation()));

        // solar array normal is slightly misaligned with Sun direction due to Sun being out of orbital plane
        Assert.assertEquals(15.1, FastMath.toDegrees(Vector3D.angle(sunDirection, normal)), 0.11);

        // radiation pressure is exactly opposed to solar array normal as there is only specular reflection
        Assert.assertEquals(180.0, FastMath.toDegrees(Vector3D.angle(acceleration, normal)), 1.0e-3);

    }

}

From source file:org.orekit.forces.BoxAndSolarArraySpacecraftTest.java

@Test
public void testPlaneAbsorption() throws OrekitException {

    AbsoluteDate initialDate = propagator.getInitialState().getDate();
    CelestialBody sun = CelestialBodyFactory.getSun();
    BoxAndSolarArraySpacecraft s = new BoxAndSolarArraySpacecraft(0, 0, 0, sun, 20.0, Vector3D.PLUS_J, 0.0, 1.0,
            0.0);//  w  w  w.ja v a 2 s .co m

    for (double dt = 0; dt < 4000; dt += 60) {

        AbsoluteDate date = initialDate.shiftedBy(dt);
        SpacecraftState state = propagator.propagate(date);

        Vector3D sunDirection = sun.getPVCoordinates(date, state.getFrame()).getPosition().normalize();
        Vector3D flux = new Vector3D(-4.56e-6, sunDirection);
        Vector3D acceleration = s.radiationPressureAcceleration(state.getDate(), state.getFrame(),
                state.getPVCoordinates().getPosition(), state.getAttitude().getRotation(), state.getMass(),
                flux);
        Vector3D normal = state.getAttitude().getRotation().applyInverseTo(s.getNormal(state.getDate(),
                state.getFrame(), state.getPVCoordinates().getPosition(), state.getAttitude().getRotation()));

        // solar array normal is slightly misaligned with Sun direction due to Sun being out of orbital plane
        Assert.assertEquals(15.1, FastMath.toDegrees(Vector3D.angle(sunDirection, normal)), 0.11);

        // radiation pressure is exactly opposed to Sun direction as there is only absorption
        Assert.assertEquals(180.0, FastMath.toDegrees(Vector3D.angle(acceleration, sunDirection)), 1.0e-3);

    }

}