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

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

Introduction

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

Prototype

public static double dotProduct(Vector3D v1, Vector3D v2) 

Source Link

Document

Compute the dot-product of two vectors.

Usage

From source file:fr.cs.examples.frames.Frames1.java

public static void main(String[] args) {
    try {//from w w  w .  ja  v a  2s. c o  m

        // configure Orekit
        Autoconfiguration.configureOrekit();

        //  Initial state definition : date, orbit
        TimeScale utc = TimeScalesFactory.getUTC();
        AbsoluteDate initialDate = new AbsoluteDate(2008, 10, 01, 0, 0, 00.000, utc);
        double mu = 3.986004415e+14; // gravitation coefficient
        Frame inertialFrame = FramesFactory.getEME2000(); // inertial frame for orbit definition
        Vector3D posisat = new Vector3D(-6142438.668, 3492467.560, -25767.25680);
        Vector3D velosat = new Vector3D(505.8479685, 942.7809215, 7435.922231);
        PVCoordinates pvsat = new PVCoordinates(posisat, velosat);
        Orbit initialOrbit = new CartesianOrbit(pvsat, inertialFrame, initialDate, mu);

        // Propagator : consider a simple keplerian motion
        Propagator kepler = new KeplerianPropagator(initialOrbit);

        // The local orbital frame (LOF) is related to the orbit propagated by the kepler propagator.
        LocalOrbitalFrame lof = new LocalOrbitalFrame(inertialFrame, LOFType.QSW, kepler, "QSW");

        // Earth and frame
        Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
        BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
                Constants.WGS84_EARTH_FLATTENING, earthFrame);

        // Station
        final double longitude = FastMath.toRadians(45.);
        final double latitude = FastMath.toRadians(25.);
        final double altitude = 0.;
        final GeodeticPoint station = new GeodeticPoint(latitude, longitude, altitude);
        final TopocentricFrame staF = new TopocentricFrame(earth, station, "station");

        System.out.println("          time           doppler (m/s)");

        // Stop date
        final AbsoluteDate finalDate = new AbsoluteDate(initialDate, 6000, utc);

        // Loop
        AbsoluteDate extrapDate = initialDate;
        while (extrapDate.compareTo(finalDate) <= 0) {

            // We can simply get the position and velocity of station in LOF frame at any time
            PVCoordinates pv = staF.getTransformTo(lof, extrapDate).transformPVCoordinates(PVCoordinates.ZERO);

            // And then calculate the doppler signal
            double doppler = Vector3D.dotProduct(pv.getPosition(), pv.getVelocity())
                    / pv.getPosition().getNorm();

            System.out.format(Locale.US, "%s   %9.3f%n", extrapDate, doppler);

            extrapDate = new AbsoluteDate(extrapDate, 600, utc);

        }

    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}

From source file:Engine.Player.java

public ArrayList<DPolygon> GetPolygons(double x, double y) {
    /*Cube head = new Cube(- halfHeadSize + x, - halfHeadSize + y, ViewFrom[2] - halfHeadSize + epsBody,
    halfHeadSize * 2.0, halfHeadSize * 2.0, halfHeadSize * 2.0, Color.YELLOW, PlayerId);
    head.Polys[2].DrawablePolygon.texture = GenerateTerrain.img;
            /*from  w  w  w . j  a va  2 s.  c o  m*/
            
    Cube neck = new Cube(- halfNeckSize + x, - halfNeckSize + y, ViewFrom[2] - headSize + halfNeckSize,
        halfNeckSize * 2.0, halfNeckSize * 2.0, halfNeckSize, Color.PINK, PlayerId);
    Cube corpus = new Cube(- halfCorupsXSize + x, - halfCorupsYSize + y, ViewFrom[2] - corpusZSize - headSize + halfNeckSize - epsBody,
        halfCorupsXSize * 2.0, halfCorupsYSize * 2.0, 2 * halfCorpusZSize, Color.BLUE, PlayerId);
            
    Cube legs = new Cube(- halfLegSizeX + x, - halfLegSizeY + y, ViewFrom[2] - legZSize - corpusZSize - headSize + halfNeckSize - epsBody - epsBody,
        2 * halfLegSizeX, 2 * halfLegSizeY, legZSize, Color.MAGENTA, PlayerId);
            
    Cube hands = new Cube(- halfHandsXSize + x, - halfHandsYSize + y, ViewFrom[2] - handsZSize - headSize + halfNeckSize - epsBody,
        halfHandsXSize * 2.0, halfHandsYSize * 2.0, handsZSize, Color.CYAN, PlayerId);
            
            
            
    ArrayList<DPolygon> all = new ArrayList<DPolygon>();
            
    rot += 0.01;
            
    head.rotation = rot;
    head.setRotAdd();
    head.updatePoly();
            
    neck.rotation = rot;
    neck.updatePoly();
            
    corpus.rotation = rot;
    corpus.updatePoly();
            
    legs.rotation = rot;
    legs.updatePoly();
            
    hands.rotation = rot;
    hands.updatePoly();
            
            
    AddArrayToArrayList(all, head.GetPolygons());
    AddArrayToArrayList(all, neck.GetPolygons());
    AddArrayToArrayList(all, corpus.GetPolygons());
    AddArrayToArrayList(all, hands.GetPolygons());
    AddArrayToArrayList(all, legs.GetPolygons());*/

    //rot = Math.PI*0.75;
    //rot += 0.01;

    /*if (MoveDirection != null)
    {
    //0
    if (Math.abs(MoveDirection.getX()) < 0.1 && MoveDirection.getY() > 0.1) rot = 0;
    //1/4
    if (MoveDirection.getX() > 0.1 && MoveDirection.getY() > 0.1) rot = -Math.PI / 4.0;
    //1/2
    if (MoveDirection.getX() > 0.1 && Math.abs(MoveDirection.getY()) < 0.1) rot = -Math.PI / 2.0;
    //3/4
    if (MoveDirection.getX() > 0.1 && MoveDirection.getY() < 0.1) rot = -3.0 * Math.PI / 4.0;
    //1
    if (Math.abs(MoveDirection.getX()) < 0.1 && MoveDirection.getY() < 0.1) rot = -Math.PI;
    //5/4
    if (MoveDirection.getX() < 0.1 && MoveDirection.getY() < 0.1) rot = -5.0 * Math.PI / 4.0;
    //3/2
    if (MoveDirection.getX() < 0.1 && Math.abs(MoveDirection.getY()) < 0.1) rot = -3.0 * Math.PI / 2.0;
    //7/4
    if (MoveDirection.getX() < 0.1 && MoveDirection.getY() > 0.1) rot = -7.0 * Math.PI / 4.0;
            
    rot += 2 *  Math.PI / 4;
    }*/
    if (PositionIFace != null) {
        rot = Math.PI / 4.0;

        Vector3D v1 = new Vector3D(PositionIFace.getX(), PositionIFace.getY(), 0);
        Vector3D v2 = new Vector3D(ViewFrom[0], ViewFrom[1], 0);
        Vector3D v3 = (v1.subtract(v2)).normalize();

        Vector3D cross = Vector3D.crossProduct(v3, new Vector3D(1, 0, 0));
        double dot = Vector3D.dotProduct(v3, new Vector3D(1, 0, 0));

        double angle = Math.atan2(cross.getZ(), dot);
        rot += -angle;
    }

    double xx = -halfHeadSize + x;
    double yy = -halfHeadSize + y;
    double[] r = rotatePoint(xx, yy, xx, yy, rot - Math.PI * 0.75);

    Cube head = new Cube(r[0], r[1], ViewFrom[2] - halfHeadSize + epsBody, halfHeadSize * 2.0,
            halfHeadSize * 2.0, halfHeadSize * 2.0, Color.YELLOW, PlayerId);

    head.Polys[2].DrawablePolygon.texture = GenerateTerrain.img;

    Cube neck = new Cube(-halfNeckSize + x, -halfNeckSize + y, ViewFrom[2] - headSize + halfNeckSize,
            halfNeckSize * 2.0, halfNeckSize * 2.0, halfNeckSize, Color.PINK, PlayerId);
    Cube corpus = new Cube(-halfCorupsXSize + x, -halfCorupsYSize + y,
            ViewFrom[2] - corpusZSize - headSize + halfNeckSize - epsBody, halfCorupsXSize * 2.0,
            halfCorupsYSize * 2.0, 2 * halfCorpusZSize, Color.BLUE, PlayerId);

    Cube legs = new Cube(-halfLegSizeX + x, -halfLegSizeY + y,
            ViewFrom[2] - legZSize - corpusZSize - headSize + halfNeckSize - epsBody - epsBody,
            2 * halfLegSizeX, 2 * halfLegSizeY, legZSize, Color.MAGENTA, PlayerId);

    xx = -halfHandsXSize + x;
    yy = -halfHandsYSize + y;//- halfHandsYSize + (halfHandsYSize / 2.0) + y;
    r = rotatePoint(xx, yy, x - 0.5, y - halfHandsYSize, rot - Math.PI * 0.75);

    Cube handLeft = new Cube(r[0], r[1], ViewFrom[2] - handsZSize - headSize + halfNeckSize - epsBody, 1,
            halfHandsYSize * 2.0, handsZSize, Color.CYAN, PlayerId);

    xx = halfHandsXSize + x - 1;
    yy = -halfHandsYSize + y;//- halfHandsYSize + (halfHandsYSize / 2.0) + y;
    r = rotatePoint(xx, yy, x - 0.5, y - halfHandsYSize, rot - Math.PI * 0.75);

    Cube handRight = new Cube(r[0], r[1], ViewFrom[2] - handsZSize - headSize + halfNeckSize - epsBody, 1,
            halfHandsYSize * 2.0, handsZSize, Color.CYAN, PlayerId);

    xx = -2 + x;
    yy = -halfLegSizeY + y;//- halfHandsYSize + (halfHandsYSize / 2.0) + y;
    r = rotatePoint(xx, yy, x - 0.75, y - halfLegSizeY, rot - Math.PI * 0.75);

    Cube legLeft = new Cube(r[0], r[1],
            ViewFrom[2] - legZSize - corpusZSize - headSize + halfNeckSize - epsBody - epsBody, 1.5,
            halfLegSizeY * 2.0, legZSize, Color.CYAN, PlayerId);

    xx = 2 + x - 1.5;
    yy = -halfLegSizeY + y;//- halfHandsYSize + (halfHandsYSize / 2.0) + y;
    r = rotatePoint(xx, yy, x - 0.75, y - halfLegSizeY, rot - Math.PI * 0.75);

    Cube legRight = new Cube(r[0], r[1],
            ViewFrom[2] - legZSize - corpusZSize - headSize + halfNeckSize - epsBody - epsBody, 1.5,
            halfLegSizeY * 2.0, legZSize, Color.CYAN, PlayerId);
    //Cube legs = new Cube(- halfLegSizeX + x, - halfLegSizeY + y, ViewFrom[2] - legZSize - corpusZSize - headSize + halfNeckSize - epsBody - epsBody,
    //      2 * halfLegSizeX, 2 * halfLegSizeY, legZSize, Color.MAGENTA, PlayerId);

    ArrayList<DPolygon> all = new ArrayList<DPolygon>();

    //rot += 0.00;

    head.rotation = rot;
    head.setRotAdd();
    head.updatePoly();

    neck.rotation = rot;
    neck.updatePoly();

    corpus.rotation = rot;
    corpus.updatePoly();

    legs.rotation = rot;
    legs.updatePoly();

    handLeft.rotation = rot;
    handLeft.updatePoly();

    handRight.rotation = rot;
    handRight.updatePoly();

    legLeft.rotation = rot;
    legLeft.updatePoly();

    legRight.rotation = rot;
    legRight.updatePoly();

    AddArrayToArrayList(all, head.GetPolygons());
    AddArrayToArrayList(all, neck.GetPolygons());
    AddArrayToArrayList(all, corpus.GetPolygons());
    AddArrayToArrayList(all, handLeft.GetPolygons());
    AddArrayToArrayList(all, handRight.GetPolygons());
    AddArrayToArrayList(all, legLeft.GetPolygons());
    AddArrayToArrayList(all, legRight.GetPolygons());

    /*
            
            
            
            
            
    //rot = Math.PI*0.75;
    rot += 0.01;
    double xx = - halfHeadSize + x;
    double yy = - halfHeadSize + y;
    double[]r = rotatePoint(xx, yy, xx, yy, rot - Math.PI*0.75);
            
    Cube head = new Cube(r[0], r[1], ViewFrom[2] - halfHeadSize + epsBody,
    halfHeadSize * 2.0, halfHeadSize * 2.0, halfHeadSize * 2.0, Color.YELLOW, PlayerId, x, y, rot - Math.PI*0.75);
            
    head.Polys[2].DrawablePolygon.texture = GenerateTerrain.img;
            
            
    Cube neck = new Cube(- halfNeckSize + x, - halfNeckSize + y, ViewFrom[2] - headSize + halfNeckSize,
        halfNeckSize * 2.0, halfNeckSize * 2.0, halfNeckSize, Color.PINK, PlayerId, x, y, rot - Math.PI*0.75);
    Cube corpus = new Cube(- halfCorupsXSize + x, - halfCorupsYSize + y, ViewFrom[2] - corpusZSize - headSize + halfNeckSize - epsBody,
        halfCorupsXSize * 2.0, halfCorupsYSize * 2.0, 2 * halfCorpusZSize, Color.BLUE, PlayerId, x, y, rot - Math.PI*0.75);
            
    Cube legs = new Cube(- halfLegSizeX + x, - halfLegSizeY + y, ViewFrom[2] - legZSize - corpusZSize - headSize + halfNeckSize - epsBody - epsBody,
        2 * halfLegSizeX, 2 * halfLegSizeY, legZSize, Color.MAGENTA, PlayerId, x, y, rot - Math.PI*0.75);
            
    //xx = - halfHandsXSize + 0.5 + x;
    //yy = - halfHandsYSize + (halfHandsYSize / 2.0) + y;
            
    Cube hands = new Cube(- halfHandsXSize + x, - halfHandsYSize + y, ViewFrom[2] - handsZSize - headSize + halfNeckSize - epsBody,
        1, halfHandsYSize * 2.0, handsZSize, Color.CYAN, PlayerId, x, y, rot - Math.PI*0.75);
            
     ArrayList<DPolygon> all = new ArrayList<DPolygon>();
            
    AddArrayToArrayList(all, head.GetPolygons());
    AddArrayToArrayList(all, neck.GetPolygons());
    AddArrayToArrayList(all, corpus.GetPolygons());
    AddArrayToArrayList(all, hands.GetPolygons());
    AddArrayToArrayList(all, legs.GetPolygons());*/
    return all;
}

From source file:org.esa.s2tbx.dataio.s2.l1b.CoordinateUtils.java

public static double distanceToSegment(Vector3D v, Vector3D w, Vector3D p) {
    // Return minimum distance between line segment vw and point p
    final double l2 = Vector3D.distanceSq(v, w); // i.e. |w-v|^2 -  avoid a sqrt
    if (l2 == 0.0)
        return Vector3D.distance(p, v); // v == w case
    // Consider the line extending the segment, parameterized as v + t (w - v).
    // We find projection of point p onto the line.
    // It falls where t = [(p-v) . (w-v)] / |w-v|^2
    double t = Vector3D.dotProduct(p.subtract(v), w.subtract(v)) / l2;
    if (t < 0.0)
        return Vector3D.distance(p, v); // Beyond the 'v' end of the segment
    else if (t > 1.0)
        return Vector3D.distance(p, w); // Beyond the 'w' end of the segment
    Vector3D projection = v.add(w.subtract(v).scalarMultiply(t)); // Projection falls on the segment
    return Vector3D.distance(p, projection);
}

From source file:org.hbird.business.navigation.processors.orekit.DopplerCalculator.java

/**
 * Calculates Doppler using {@link KeplerianPropagator} and {@link CartesianOrbit}.
 * /*ww  w .j  av  a  2s.  co m*/
 * @param coordinates
 * @param date
 * @param locationOnEarth
 * @param inertialFrame
 * @return
 * @throws OrekitException
 */
public static double calculateDoppler(PVCoordinates coordinates, AbsoluteDate date,
        TopocentricFrame locationOnEarth, Frame inertialFrame) throws OrekitException {
    Orbit initialOrbit = new CartesianOrbit(coordinates, inertialFrame, date, Constants.MU);
    Propagator propagator = new KeplerianPropagator(initialOrbit);
    LocalOrbitalFrame lof = new LocalOrbitalFrame(inertialFrame, LOFType.QSW, propagator, "QSW");
    PVCoordinates pv = locationOnEarth.getTransformTo(lof, date).transformPVCoordinates(PVCoordinates.ZERO);
    return Vector3D.dotProduct(pv.getPosition(), pv.getVelocity()) / pv.getPosition().getNorm();
}

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

@Test
public void testSpin() throws OrekitException {
    double rate = 2 * FastMath.PI / (12 * 60);
    Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(),
            new Rotation(0.48, 0.64, 0.36, 0.48, false), new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO);
    Assert.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-10);
    double dt = 10.0;
    Attitude shifted = attitude.shiftedBy(dt);
    Assert.assertEquals(rate, shifted.getSpin().getNorm(), 1.0e-10);
    Assert.assertEquals(rate * dt, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-10);

    Vector3D shiftedX = shifted.getRotation().applyInverseTo(Vector3D.PLUS_I);
    Vector3D shiftedY = shifted.getRotation().applyInverseTo(Vector3D.PLUS_J);
    Vector3D shiftedZ = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K);
    Vector3D originalX = attitude.getRotation().applyInverseTo(Vector3D.PLUS_I);
    Vector3D originalY = attitude.getRotation().applyInverseTo(Vector3D.PLUS_J);
    Vector3D originalZ = attitude.getRotation().applyInverseTo(Vector3D.PLUS_K);
    Assert.assertEquals(FastMath.cos(rate * dt), Vector3D.dotProduct(shiftedX, originalX), 1.0e-10);
    Assert.assertEquals(FastMath.sin(rate * dt), Vector3D.dotProduct(shiftedX, originalY), 1.0e-10);
    Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedX, originalZ), 1.0e-10);
    Assert.assertEquals(-FastMath.sin(rate * dt), Vector3D.dotProduct(shiftedY, originalX), 1.0e-10);
    Assert.assertEquals(FastMath.cos(rate * dt), Vector3D.dotProduct(shiftedY, originalY), 1.0e-10);
    Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedY, originalZ), 1.0e-10);
    Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedZ, originalX), 1.0e-10);
    Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedZ, originalY), 1.0e-10);
    Assert.assertEquals(1.0, Vector3D.dotProduct(shiftedZ, originalZ), 1.0e-10);

    Vector3D forward = AngularCoordinates.estimateRate(attitude.getRotation(), shifted.getRotation(), dt);
    Assert.assertEquals(0.0, forward.subtract(attitude.getSpin()).getNorm(), 1.0e-10);

    Vector3D reversed = AngularCoordinates.estimateRate(shifted.getRotation(), attitude.getRotation(), dt);
    Assert.assertEquals(0.0, reversed.add(attitude.getSpin()).getNorm(), 1.0e-10);

}

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

/** {@inheritDoc} */
public Attitude getAttitude(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame)
        throws OrekitException {

    final PVCoordinates satPV = pvProv.getPVCoordinates(date, celestialFrame);

    // compute celestial references at the specified date
    final PVCoordinates bodyPV = pointedBody.getPVCoordinates(date, celestialFrame);
    final PVCoordinates pointing = new PVCoordinates(satPV, bodyPV);
    final Vector3D pointingP = pointing.getPosition();
    final double r2 = Vector3D.dotProduct(pointingP, pointingP);

    // evaluate instant rotation axis due to sat and body motion only (no phasing yet)
    final Vector3D rotAxisCel = new Vector3D(1 / r2, Vector3D.crossProduct(pointingP, pointing.getVelocity()));

    // fix instant rotation to take phasing constraint into account
    // (adding a rotation around pointing axis ensuring the motion of the phasing axis
    //  is constrained in the pointing-phasing plane)
    final Vector3D v1 = Vector3D.crossProduct(rotAxisCel, phasingCel);
    final Vector3D v2 = Vector3D.crossProduct(pointingP, phasingCel);
    final double compensation = -Vector3D.dotProduct(v1, v2) / v2.getNormSq();
    final Vector3D phasedRotAxisCel = new Vector3D(1.0, rotAxisCel, compensation, pointingP);

    // compute transform from celestial frame to satellite frame
    final Rotation celToSatRotation = new Rotation(pointingP, phasingCel, pointingSat, phasingSat);

    // build transform combining rotation and instant rotation axis
    Transform transform = new Transform(date, celToSatRotation, celToSatRotation.applyTo(phasedRotAxisCel));
    if (frame != celestialFrame) {
        // prepend transform from specified frame to celestial frame
        transform = new Transform(date, frame.getTransformTo(celestialFrame, date), transform);
    }// w  w w  .j  a v a  2s  .  com

    // build the attitude
    return new Attitude(date, frame, transform.getRotation(), transform.getRotationRate(),
            transform.getRotationAcceleration());

}

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

@Test
public void testSunPointing() throws OrekitException {
    PVCoordinatesProvider sun = CelestialBodyFactory.getSun();

    final Frame frame = FramesFactory.getGCRF();
    AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789),
            TimeScalesFactory.getTAI());
    AttitudeProvider sunPointing = new CelestialBodyPointed(frame, sun, Vector3D.PLUS_K, Vector3D.PLUS_I,
            Vector3D.PLUS_K);/*from  w  w w.  jav a 2s  . c o  m*/
    PVCoordinates pv = new PVCoordinates(new Vector3D(28812595.32120171334, 5948437.45881852374, 0.0),
            new Vector3D(0, 0, 3680.853673522056));
    Orbit orbit = new KeplerianOrbit(pv, frame, date, 3.986004415e14);
    Attitude attitude = sunPointing.getAttitude(orbit, date, frame);
    Vector3D xDirection = attitude.getRotation().applyInverseTo(Vector3D.PLUS_I);
    Vector3D zDirection = attitude.getRotation().applyInverseTo(Vector3D.PLUS_K);
    Assert.assertEquals(0, Vector3D.dotProduct(zDirection, Vector3D.crossProduct(xDirection, Vector3D.PLUS_K)),
            1.0e-15);

    // the following statement checks we take parallax into account
    // Sun-Earth-Sat are in quadrature, with distance (Earth, Sat) == distance(Sun, Earth) / 5000
    Assert.assertEquals(FastMath.atan(1.0 / 5000.0),
            Vector3D.angle(xDirection, sun.getPVCoordinates(date, frame).getPosition()), 1.0e-15);

    double h = 0.1;
    Attitude aMinus = sunPointing.getAttitude(orbit.shiftedBy(-h), date.shiftedBy(-h), frame);
    Attitude a0 = sunPointing.getAttitude(orbit, date, frame);
    Attitude aPlus = sunPointing.getAttitude(orbit.shiftedBy(h), date.shiftedBy(h), frame);

    // check spin is consistent with attitude evolution
    double errorAngleMinus = Rotation.distance(aMinus.shiftedBy(h).getRotation(), a0.getRotation());
    double evolutionAngleMinus = Rotation.distance(aMinus.getRotation(), a0.getRotation());
    Assert.assertEquals(0.0, errorAngleMinus, 1.0e-6 * evolutionAngleMinus);
    double errorAnglePlus = Rotation.distance(a0.getRotation(), aPlus.shiftedBy(-h).getRotation());
    double evolutionAnglePlus = Rotation.distance(a0.getRotation(), aPlus.getRotation());
    Assert.assertEquals(0.0, errorAnglePlus, 1.0e-6 * evolutionAnglePlus);

}

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

/** {@inheritDoc} */
public Attitude getAttitude(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame)
        throws OrekitException {

    // satellite-target relative vector
    final PVCoordinates pva = pvProv.getPVCoordinates(date, inertialFrame);
    final TimeStampedPVCoordinates delta = new TimeStampedPVCoordinates(date, pva,
            getTargetPV(pvProv, date, inertialFrame));

    // spacecraft and target should be away from each other to define a pointing direction
    if (delta.getPosition().getNorm() == 0.0) {
        throw new OrekitException(OrekitMessages.SATELLITE_COLLIDED_WITH_TARGET);
    }//from  w  w w  . j  av a2  s .  co  m

    // attitude definition:
    // line of sight    -> +z satellite axis,
    // orbital velocity -> (z, +x) half plane
    final Vector3D p = pva.getPosition();
    final Vector3D v = pva.getVelocity();
    final Vector3D a = pva.getAcceleration();
    final double r2 = p.getNormSq();
    final double r = FastMath.sqrt(r2);
    final Vector3D keplerianJerk = new Vector3D(-3 * Vector3D.dotProduct(p, v) / r2, a, -a.getNorm() / r, v);
    final PVCoordinates velocity = new PVCoordinates(v, a, keplerianJerk);

    final PVCoordinates los = delta.normalize();
    final PVCoordinates normal = PVCoordinates.crossProduct(delta, velocity).normalize();

    AngularCoordinates ac = new AngularCoordinates(los, normal, PLUS_K, PLUS_J, 1.0e-9);

    if (frame != inertialFrame) {
        // prepend transform from specified frame to inertial frame
        ac = ac.addOffset(frame.getTransformTo(inertialFrame, date).getAngular());
    }

    // build the attitude
    return new Attitude(date, frame, ac);

}

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

/** Compute line of sight intersection with body.
 * @param scToBody transform from spacecraft frame to body frame
 * @return intersection point in body frame (only the position is set!)
 * @exception OrekitException if line of sight does not intersect body
 *//*from  w ww .j av a2 s.  c  om*/
private TimeStampedPVCoordinates losIntersectionWithBody(final Transform scToBody) throws OrekitException {

    // compute satellite pointing axis and position/velocity in body frame
    final Vector3D pointingBodyFrame = scToBody.transformVector(satPointingVector);
    final Vector3D pBodyFrame = scToBody.transformPosition(Vector3D.ZERO);

    // Line from satellite following pointing direction
    // we use arbitrarily the Earth radius as a scaling factor, it could be anything else
    final Line pointingLine = new Line(pBodyFrame,
            pBodyFrame.add(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, pointingBodyFrame), 1.0e-10);

    // Intersection with body shape
    final GeodeticPoint gpIntersection = shape.getIntersectionPoint(pointingLine, pBodyFrame,
            shape.getBodyFrame(), scToBody.getDate());
    final Vector3D pIntersection = (gpIntersection == null) ? null : shape.transform(gpIntersection);

    // Check there is an intersection and it is not in the reverse pointing direction
    if ((pIntersection == null)
            || (Vector3D.dotProduct(pIntersection.subtract(pBodyFrame), pointingBodyFrame) < 0)) {
        throw new OrekitException(OrekitMessages.ATTITUDE_POINTING_LAW_DOES_NOT_POINT_TO_GROUND);
    }

    return new TimeStampedPVCoordinates(scToBody.getDate(), pIntersection, Vector3D.ZERO, Vector3D.ZERO);

}

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

/** Test is the lof offset is the one expected
 *///from   ww  w .  ja va2  s  . c om
@Test
public void testZero() throws OrekitException, CardanEulerSingularityException {

    //  Satellite position

    // Lof aligned attitude provider
    final LofOffset lofAlignedLaw = new LofOffset(orbit.getFrame(), LOFType.VVLH);
    final Rotation lofOffsetRot = lofAlignedLaw.getAttitude(orbit, date, orbit.getFrame()).getRotation();

    // Check that
    final Vector3D momentumEME2000 = pvSatEME2000.getMomentum();
    final Vector3D momentumLof = lofOffsetRot.applyTo(momentumEME2000);
    final double cosinus = FastMath.cos(Vector3D.dotProduct(momentumLof, Vector3D.PLUS_K));
    Assert.assertEquals(1., cosinus, Utils.epsilonAngle);

}