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

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

Introduction

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

Prototype

public Vector3D subtract(final Vector<Euclidean3D> v) 

Source Link

Usage

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  . jav  a  2 s .com
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.LofOffsetPointingTest.java

@Test
public void testSpin() throws OrekitException {

    AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789),
            TimeScalesFactory.getUTC());
    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);

    final AttitudeProvider law = new LofOffsetPointing(orbit.getFrame(), earthSpheric,
            new LofOffset(orbit.getFrame(), LOFType.VVLH, RotationOrder.XYX, 0.1, 0.2, 0.3), Vector3D.PLUS_K);

    Propagator propagator = new KeplerianPropagator(orbit, law);

    double h = 0.01;
    SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h));
    SpacecraftState s0 = propagator.propagate(date);
    SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h));

    // 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.assertEquals(0.0, 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.assertEquals(0.0, errorAnglePlus, 1.0e-6 * evolutionAnglePlus);

    Vector3D spin0 = s0.getAttitude().getSpin();
    Vector3D reference = AngularCoordinates.estimateRate(sMinus.getAttitude().getRotation(),
            sPlus.getAttitude().getRotation(), 2 * h);
    Assert.assertTrue(spin0.getNorm() > 1.0e-3);
    Assert.assertEquals(0.0, spin0.subtract(reference).getNorm(), 1.0e-10);

}

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

@Test
public void testSpin() throws OrekitException {

    final AttitudeProvider law = new LofOffset(orbit.getFrame(), LOFType.VVLH, RotationOrder.XYX, 0.1, 0.2,
            0.3);//from w  w w  . jav  a  2s .  c o m

    AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789),
            TimeScalesFactory.getUTC());
    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 = 0.01;
    SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h));
    SpacecraftState s0 = propagator.propagate(date);
    SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h));

    // 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.assertEquals(0.0, 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.assertEquals(0.0, errorAnglePlus, 1.0e-6 * evolutionAnglePlus);

    Vector3D spin0 = s0.getAttitude().getSpin();
    Vector3D reference = AngularCoordinates.estimateRate(sMinus.getAttitude().getRotation(),
            sPlus.getAttitude().getRotation(), 2 * h);
    Assert.assertEquals(0.0, spin0.subtract(reference).getNorm(), 1.0e-10);

}

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

@Test
public void testSpin() throws OrekitException {

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

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

    //  Satellite on any position
    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, mu);

    Propagator propagator = new KeplerianPropagator(orbit, law, mu, 2500.0);

    double h = 0.1;
    SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h));
    SpacecraftState s0 = propagator.propagate(date);
    SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h));

    // 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.assertEquals(0.0, errorAngleMinus, 4.0e-9 * evolutionAngleMinus);
    double errorAnglePlus = Rotation.distance(s0.getAttitude().getRotation(),
            sPlus.shiftedBy(-h).getAttitude().getRotation());
    double evolutionAnglePlus = Rotation.distance(s0.getAttitude().getRotation(),
            sPlus.getAttitude().getRotation());
    Assert.assertEquals(0.0, errorAnglePlus, 8.0e-9 * evolutionAnglePlus);

    Vector3D spin0 = s0.getAttitude().getSpin();
    Rotation rM = sMinus.getAttitude().getRotation();
    Rotation rP = sPlus.getAttitude().getRotation();
    Vector3D reference = AngularCoordinates.estimateRate(rM, rP, 2 * h);
    Assert.assertTrue(Rotation.distance(rM, rP) > 2.0e-4);
    Assert.assertEquals(0.0, spin0.subtract(reference).getNorm(), 2.0e-6);

}

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

@Test
public void testSpin() throws OrekitException {

    Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true);

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

    // Create target pointing attitude provider
    GeodeticPoint geoTarget = new GeodeticPoint(FastMath.toRadians(43.36), FastMath.toRadians(1.26), 600.);
    AttitudeProvider law = new TargetPointing(FramesFactory.getEME2000(), geoTarget, earthShape);

    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 = 0.01;
    SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h));
    SpacecraftState s0 = propagator.propagate(date);
    SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h));

    // 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.assertEquals(0.0, errorAngleMinus, 1.0e-5 * evolutionAngleMinus);
    double errorAnglePlus = Rotation.distance(s0.getAttitude().getRotation(),
            sPlus.shiftedBy(-h).getAttitude().getRotation());
    double evolutionAnglePlus = Rotation.distance(s0.getAttitude().getRotation(),
            sPlus.getAttitude().getRotation());
    Assert.assertEquals(0.0, errorAnglePlus, 1.0e-5 * evolutionAnglePlus);

    Vector3D spin0 = s0.getAttitude().getSpin();
    Vector3D reference = AngularCoordinates.estimateRate(sMinus.getAttitude().getRotation(),
            sPlus.getAttitude().getRotation(), 2 * h);
    Assert.assertEquals(0.0, spin0.subtract(reference).getNorm(), 1.1e-10);

}

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

/** Test that compensation rotation axis is Zsat, yaw axis
 *///w ww .j  av  a  2  s  .co  m
@Test
public void testCompensAxis() throws OrekitException {

    //  Attitude laws
    // **************
    // Target pointing attitude provider over satellite nadir at date, without yaw compensation
    NadirPointing nadirLaw = new NadirPointing(circOrbit.getFrame(), earthShape);

    // Target pointing attitude provider with yaw compensation
    YawCompensation yawCompensLaw = new YawCompensation(circOrbit.getFrame(), nadirLaw);

    // Get attitude rotations from non yaw compensated / yaw compensated laws
    Rotation rotNoYaw = nadirLaw.getAttitude(circOrbit, date, circOrbit.getFrame()).getRotation();
    Rotation rotYaw = yawCompensLaw.getAttitude(circOrbit, date, circOrbit.getFrame()).getRotation();

    // Compose rotations composition
    Rotation compoRot = rotYaw.applyTo(rotNoYaw.revert());
    Vector3D yawAxis = compoRot.getAxis();

    // Check axis
    Assert.assertEquals(0., yawAxis.subtract(Vector3D.PLUS_K).getNorm(), Utils.epsilonTest);

}

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

@Test
public void testSpin() throws OrekitException {

    NadirPointing nadirLaw = new NadirPointing(circOrbit.getFrame(), earthShape);

    // Target pointing attitude provider with yaw compensation
    YawCompensation law = new YawCompensation(circOrbit.getFrame(), nadirLaw);

    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.shiftedBy(-300.0), 3.986004415e14);

    Propagator propagator = new KeplerianPropagator(orbit, law);

    double h = 0.01;
    SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h));
    SpacecraftState s0 = propagator.propagate(date);
    SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h));

    // 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.assertEquals(0.0, errorAngleMinus, 7.5e-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.assertEquals(0.0, errorAnglePlus, 2.0e-5 * evolutionAnglePlus);

    Vector3D spin0 = s0.getAttitude().getSpin();
    Vector3D reference = AngularCoordinates.estimateRate(sMinus.getAttitude().getRotation(),
            sPlus.getAttitude().getRotation(), 2 * h);
    Assert.assertTrue(spin0.getNorm() > 1.0e-3);
    Assert.assertEquals(0.0, spin0.subtract(reference).getNorm(), 2.0e-8);

}

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

@Test
public void testSpin() throws OrekitException {

    NadirPointing nadirLaw = new NadirPointing(circOrbit.getFrame(), earthShape);

    // Target pointing attitude provider with yaw compensation
    AttitudeProvider law = new YawSteering(circOrbit.getFrame(), nadirLaw, CelestialBodyFactory.getSun(),
            Vector3D.MINUS_I);//w ww  .  j a v a2  s.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.shiftedBy(-300.0), 3.986004415e14);

    Propagator propagator = new KeplerianPropagator(orbit, law);

    double h = 0.01;
    SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h));
    SpacecraftState s0 = propagator.propagate(date);
    SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h));

    // 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.assertEquals(0.0, errorAngleMinus, 1.0e-9 * evolutionAngleMinus);
    double errorAnglePlus = Rotation.distance(s0.getAttitude().getRotation(),
            sPlus.shiftedBy(-h).getAttitude().getRotation());
    double evolutionAnglePlus = Rotation.distance(s0.getAttitude().getRotation(),
            sPlus.getAttitude().getRotation());
    Assert.assertEquals(0.0, errorAnglePlus, 1.0e-9 * evolutionAnglePlus);

    Vector3D spin0 = s0.getAttitude().getSpin();
    Vector3D reference = AngularCoordinates.estimateRate(sMinus.getAttitude().getRotation(),
            sPlus.getAttitude().getRotation(), 2 * h);
    Assert.assertTrue(spin0.getNorm() > 1.0e-3);
    Assert.assertEquals(0.0, spin0.subtract(reference).getNorm(), 4.0e-13);

}

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

private double bodyDistance(CelestialBody body1, CelestialBody body2, AbsoluteDate date, Frame frame)
        throws OrekitException {
    Vector3D body1Position = body1.getPVCoordinates(date, frame).getPosition();
    Vector3D body2Position = body2.getPVCoordinates(date, frame).getPosition();
    Vector3D bodyPositionDifference = body1Position.subtract(body2Position);
    return bodyPositionDifference.getNorm();
}

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

/** Project a point to the ellipse plane.
 * @param p point defined with respect to 3D frame
 * @return point defined with respect to ellipse
 * @see #toSpace(Vector2D)//from  w  w w. ja v  a2  s . c o  m
 */
public Vector2D toPlane(final Vector3D p) {
    final Vector3D delta = p.subtract(center);
    return new Vector2D(Vector3D.dotProduct(delta, u), Vector3D.dotProduct(delta, v));
}