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

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

Introduction

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

Prototype

public static Vector3D crossProduct(final Vector3D v1, final Vector3D v2) 

Source Link

Document

Compute the cross-product of two vectors.

Usage

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

@Test
public void testLVLH() throws OrekitException {
    AbsoluteDate date = initDate.shiftedBy(400);
    PVCoordinates pv = provider.getPVCoordinates(date, inertialFrame);
    checkFrame(LOFType.LVLH, date, pv.getPosition(), Vector3D.crossProduct(pv.getMomentum(), pv.getPosition()),
            pv.getMomentum(), pv.getMomentum().negate());
}

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

@Test
public void testVVLH() throws OrekitException {
    AbsoluteDate date = initDate.shiftedBy(400);
    PVCoordinates pv = provider.getPVCoordinates(date, inertialFrame);
    checkFrame(LOFType.VVLH, date, Vector3D.crossProduct(pv.getMomentum(), pv.getPosition()),
            pv.getMomentum().negate(), pv.getPosition().negate(), pv.getMomentum().negate());
}

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

@Test
public void testVNC() throws OrekitException {
    AbsoluteDate date = initDate.shiftedBy(400);
    PVCoordinates pv = provider.getPVCoordinates(date, inertialFrame);
    checkFrame(LOFType.VNC, date, pv.getVelocity(), pv.getMomentum(),
            Vector3D.crossProduct(pv.getVelocity(), pv.getMomentum()), pv.getMomentum().negate());
}

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

/** Compute a composite velocity.
 * @param first first applied transform//  www.  j  a  v a2s . c  om
 * @param second second applied transform
 * @return velocity part of the composite transform
 */
private static Vector3D compositeVelocity(final Transform first, final Transform second) {

    final Vector3D v1 = first.cartesian.getVelocity();
    final Rotation r1 = first.angular.getRotation();
    final Vector3D o1 = first.angular.getRotationRate();
    final Vector3D p2 = second.cartesian.getPosition();
    final Vector3D v2 = second.cartesian.getVelocity();

    final Vector3D crossP = Vector3D.crossProduct(o1, p2);

    return v1.add(r1.applyInverseTo(v2.add(crossP)));

}

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

/** Compute a composite acceleration.
 * @param first first applied transform// ww  w  .  j av a2 s. c  o m
 * @param second second applied transform
 * @return acceleration part of the composite transform
 */
private static Vector3D compositeAcceleration(final Transform first, final Transform second) {

    final Vector3D a1 = first.cartesian.getAcceleration();
    final Rotation r1 = first.angular.getRotation();
    final Vector3D o1 = first.angular.getRotationRate();
    final Vector3D oDot1 = first.angular.getRotationAcceleration();
    final Vector3D p2 = second.cartesian.getPosition();
    final Vector3D v2 = second.cartesian.getVelocity();
    final Vector3D a2 = second.cartesian.getAcceleration();

    final Vector3D crossCrossP = Vector3D.crossProduct(o1, Vector3D.crossProduct(o1, p2));
    final Vector3D crossV = Vector3D.crossProduct(o1, v2);
    final Vector3D crossDotP = Vector3D.crossProduct(oDot1, p2);

    return a1.add(r1.applyInverseTo(new Vector3D(1, a2, 2, crossV, 1, crossCrossP, 1, crossDotP)));

}

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

/** Compute a composite rotation acceleration.
 * @param first first applied transform//  w  w w. j  a va  2 s .  co m
 * @param second second applied transform
 * @return rotation acceleration part of the composite transform
 */
private static Vector3D compositeRotationAcceleration(final Transform first, final Transform second) {

    final Vector3D o1 = first.angular.getRotationRate();
    final Vector3D oDot1 = first.angular.getRotationAcceleration();
    final Rotation r2 = second.angular.getRotation();
    final Vector3D o2 = second.angular.getRotationRate();
    final Vector3D oDot2 = second.angular.getRotationAcceleration();

    return new Vector3D(1, oDot2, 1, r2.applyTo(oDot1), -1, Vector3D.crossProduct(o2, r2.applyTo(o1)));

}

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

/** Get the inverse transform of the instance.
 * @return inverse transform of the instance
 *///from w ww  .j  a va  2 s  . co  m
public Transform getInverse() {

    final Rotation r = angular.getRotation();
    final Vector3D o = angular.getRotationRate();
    final Vector3D oDot = angular.getRotationAcceleration();
    final Vector3D rp = r.applyTo(cartesian.getPosition());
    final Vector3D rv = r.applyTo(cartesian.getVelocity());
    final Vector3D ra = r.applyTo(cartesian.getAcceleration());

    final Vector3D pInv = rp.negate();
    final Vector3D crossP = Vector3D.crossProduct(o, rp);
    final Vector3D vInv = crossP.subtract(rv);
    final Vector3D crossV = Vector3D.crossProduct(o, rv);
    final Vector3D crossDotP = Vector3D.crossProduct(oDot, rp);
    final Vector3D crossCrossP = Vector3D.crossProduct(o, crossP);
    final Vector3D aInv = new Vector3D(-1, ra, 2, crossV, 1, crossDotP, -1, crossCrossP);

    return new Transform(date, new PVCoordinates(pInv, vInv, aInv), angular.revert());

}

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);
        }/*from ww  w  .j  av a 2s.c o  m*/

    }
}

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

@Test
public void testShiftDerivatives() {

    RandomGenerator random = new Well19937a(0x5acda4f605aadce7l);
    for (int i = 0; i < 10; ++i) {
        Transform t = randomTransform(random);

        for (double dt = -10.0; dt < 10.0; dt += 0.125) {

            Transform t0 = t.shiftedBy(dt);
            double v = t0.getVelocity().getNorm();
            double a = t0.getAcceleration().getNorm();
            double omega = t0.getRotationRate().getNorm();
            double omegaDot = t0.getRotationAcceleration().getNorm();

            // numerical derivatives
            double h = 0.01 / omega;
            Transform tm4h = t.shiftedBy(dt - 4 * h);
            Transform tm3h = t.shiftedBy(dt - 3 * h);
            Transform tm2h = t.shiftedBy(dt - 2 * h);
            Transform tm1h = t.shiftedBy(dt - 1 * h);
            Transform tp1h = t.shiftedBy(dt + 1 * h);
            Transform tp2h = t.shiftedBy(dt + 2 * h);
            Transform tp3h = t.shiftedBy(dt + 3 * h);
            Transform tp4h = t.shiftedBy(dt + 4 * h);
            double numXDot = derivative(h, tm4h.getTranslation().getX(), tm3h.getTranslation().getX(),
                    tm2h.getTranslation().getX(), tm1h.getTranslation().getX(), tp1h.getTranslation().getX(),
                    tp2h.getTranslation().getX(), tp3h.getTranslation().getX(), tp4h.getTranslation().getX());
            double numYDot = derivative(h, tm4h.getTranslation().getY(), tm3h.getTranslation().getY(),
                    tm2h.getTranslation().getY(), tm1h.getTranslation().getY(), tp1h.getTranslation().getY(),
                    tp2h.getTranslation().getY(), tp3h.getTranslation().getY(), tp4h.getTranslation().getY());
            double numZDot = derivative(h, tm4h.getTranslation().getZ(), tm3h.getTranslation().getZ(),
                    tm2h.getTranslation().getZ(), tm1h.getTranslation().getZ(), tp1h.getTranslation().getZ(),
                    tp2h.getTranslation().getZ(), tp3h.getTranslation().getZ(), tp4h.getTranslation().getZ());
            double numXDot2 = derivative(h, tm4h.getVelocity().getX(), tm3h.getVelocity().getX(),
                    tm2h.getVelocity().getX(), tm1h.getVelocity().getX(), tp1h.getVelocity().getX(),
                    tp2h.getVelocity().getX(), tp3h.getVelocity().getX(), tp4h.getVelocity().getX());
            double numYDot2 = derivative(h, tm4h.getVelocity().getY(), tm3h.getVelocity().getY(),
                    tm2h.getVelocity().getY(), tm1h.getVelocity().getY(), tp1h.getVelocity().getY(),
                    tp2h.getVelocity().getY(), tp3h.getVelocity().getY(), tp4h.getVelocity().getY());
            double numZDot2 = derivative(h, tm4h.getVelocity().getZ(), tm3h.getVelocity().getZ(),
                    tm2h.getVelocity().getZ(), tm1h.getVelocity().getZ(), tp1h.getVelocity().getZ(),
                    tp2h.getVelocity().getZ(), tp3h.getVelocity().getZ(), tp4h.getVelocity().getZ());
            double numQ0Dot = derivative(h, tm4h.getRotation().getQ0(), tm3h.getRotation().getQ0(),
                    tm2h.getRotation().getQ0(), tm1h.getRotation().getQ0(), tp1h.getRotation().getQ0(),
                    tp2h.getRotation().getQ0(), tp3h.getRotation().getQ0(), tp4h.getRotation().getQ0());
            double numQ1Dot = derivative(h, tm4h.getRotation().getQ1(), tm3h.getRotation().getQ1(),
                    tm2h.getRotation().getQ1(), tm1h.getRotation().getQ1(), tp1h.getRotation().getQ1(),
                    tp2h.getRotation().getQ1(), tp3h.getRotation().getQ1(), tp4h.getRotation().getQ1());
            double numQ2Dot = derivative(h, tm4h.getRotation().getQ2(), tm3h.getRotation().getQ2(),
                    tm2h.getRotation().getQ2(), tm1h.getRotation().getQ2(), tp1h.getRotation().getQ2(),
                    tp2h.getRotation().getQ2(), tp3h.getRotation().getQ2(), tp4h.getRotation().getQ2());
            double numQ3Dot = derivative(h, tm4h.getRotation().getQ3(), tm3h.getRotation().getQ3(),
                    tm2h.getRotation().getQ3(), tm1h.getRotation().getQ3(), tp1h.getRotation().getQ3(),
                    tp2h.getRotation().getQ3(), tp3h.getRotation().getQ3(), tp4h.getRotation().getQ3());
            double numOxDot = derivative(h, tm4h.getRotationRate().getX(), tm3h.getRotationRate().getX(),
                    tm2h.getRotationRate().getX(), tm1h.getRotationRate().getX(), tp1h.getRotationRate().getX(),
                    tp2h.getRotationRate().getX(), tp3h.getRotationRate().getX(),
                    tp4h.getRotationRate().getX());
            double numOyDot = derivative(h, tm4h.getRotationRate().getY(), tm3h.getRotationRate().getY(),
                    tm2h.getRotationRate().getY(), tm1h.getRotationRate().getY(), tp1h.getRotationRate().getY(),
                    tp2h.getRotationRate().getY(), tp3h.getRotationRate().getY(),
                    tp4h.getRotationRate().getY());
            double numOzDot = derivative(h, tm4h.getRotationRate().getZ(), tm3h.getRotationRate().getZ(),
                    tm2h.getRotationRate().getZ(), tm1h.getRotationRate().getZ(), tp1h.getRotationRate().getZ(),
                    tp2h.getRotationRate().getZ(), tp3h.getRotationRate().getZ(),
                    tp4h.getRotationRate().getZ());

            // theoretical derivatives
            double theXDot = t0.getVelocity().getX();
            double theYDot = t0.getVelocity().getY();
            double theZDot = t0.getVelocity().getZ();
            double theXDot2 = t0.getAcceleration().getX();
            double theYDot2 = t0.getAcceleration().getY();
            double theZDot2 = t0.getAcceleration().getZ();
            Rotation r0 = t0.getRotation();
            Vector3D w = t0.getRotationRate();
            Vector3D q = new Vector3D(r0.getQ1(), r0.getQ2(), r0.getQ3());
            Vector3D qw = Vector3D.crossProduct(q, w);
            double theQ0Dot = -0.5 * Vector3D.dotProduct(q, w);
            double theQ1Dot = 0.5 * (r0.getQ0() * w.getX() + qw.getX());
            double theQ2Dot = 0.5 * (r0.getQ0() * w.getY() + qw.getY());
            double theQ3Dot = 0.5 * (r0.getQ0() * w.getZ() + qw.getZ());
            double theOxDot2 = t0.getRotationAcceleration().getX();
            double theOyDot2 = t0.getRotationAcceleration().getY();
            double theOzDot2 = t0.getRotationAcceleration().getZ();

            // check consistency
            Assert.assertEquals(theXDot, numXDot, 1.0e-13 * v);
            Assert.assertEquals(theYDot, numYDot, 1.0e-13 * v);
            Assert.assertEquals(theZDot, numZDot, 1.0e-13 * v);

            Assert.assertEquals(theXDot2, numXDot2, 1.0e-13 * a);
            Assert.assertEquals(theYDot2, numYDot2, 1.0e-13 * a);
            Assert.assertEquals(theZDot2, numZDot2, 1.0e-13 * a);

            Assert.assertEquals(theQ0Dot, numQ0Dot, 1.0e-13 * omega);
            Assert.assertEquals(theQ1Dot, numQ1Dot, 1.0e-13 * omega);
            Assert.assertEquals(theQ2Dot, numQ2Dot, 1.0e-13 * omega);
            Assert.assertEquals(theQ3Dot, numQ3Dot, 1.0e-13 * omega);

            Assert.assertEquals(theOxDot2, numOxDot, 1.0e-12 * omegaDot);
            Assert.assertEquals(theOyDot2, numOyDot, 1.0e-12 * omegaDot);
            Assert.assertEquals(theOzDot2, numOzDot, 1.0e-12 * omegaDot);

        }/*from w ww  .ja va2 s.c om*/
    }
}

From source file:org.orekit.orbits.CartesianOrbit.java

/** Compute shifted position and velocity in elliptic case.
 * @param dt time shift/*from  w  w w .  j a  v  a 2s .c o m*/
 * @return shifted position and velocity
 */
private PVCoordinates shiftPVElliptic(final double dt) {

    // preliminary computation
    final Vector3D pvP = getPVCoordinates().getPosition();
    final Vector3D pvV = getPVCoordinates().getVelocity();
    final double r = pvP.getNorm();
    final double rV2OnMu = r * pvV.getNormSq() / getMu();
    final double a = getA();
    final double eSE = Vector3D.dotProduct(pvP, pvV) / FastMath.sqrt(getMu() * a);
    final double eCE = rV2OnMu - 1;
    final double e2 = eCE * eCE + eSE * eSE;

    // we can use any arbitrary reference 2D frame in the orbital plane
    // in order to simplify some equations below, we use the current position as the u axis
    final Vector3D u = pvP.normalize();
    final Vector3D v = Vector3D.crossProduct(getPVCoordinates().getMomentum(), u).normalize();

    // the following equations rely on the specific choice of u explained above,
    // some coefficients that vanish to 0 in this case have already been removed here
    final double ex = (eCE - e2) * a / r;
    final double ey = -FastMath.sqrt(1 - e2) * eSE * a / r;
    final double beta = 1 / (1 + FastMath.sqrt(1 - e2));
    final double thetaE0 = FastMath.atan2(ey + eSE * beta * ex, r / a + ex - eSE * beta * ey);
    final double thetaM0 = thetaE0 - ex * FastMath.sin(thetaE0) + ey * FastMath.cos(thetaE0);

    // compute in-plane shifted eccentric argument
    final double thetaM1 = thetaM0 + getKeplerianMeanMotion() * dt;
    final double thetaE1 = meanToEccentric(thetaM1, ex, ey);
    final double cTE = FastMath.cos(thetaE1);
    final double sTE = FastMath.sin(thetaE1);

    // compute shifted in-plane cartesian coordinates
    final double exey = ex * ey;
    final double exCeyS = ex * cTE + ey * sTE;
    final double x = a * ((1 - beta * ey * ey) * cTE + beta * exey * sTE - ex);
    final double y = a * ((1 - beta * ex * ex) * sTE + beta * exey * cTE - ey);
    final double factor = FastMath.sqrt(getMu() / a) / (1 - exCeyS);
    final double xDot = factor * (-sTE + beta * ey * exCeyS);
    final double yDot = factor * (cTE - beta * ex * exCeyS);

    final Vector3D shiftedP = new Vector3D(x, u, y, v);
    final double r2 = x * x + y * y;
    final Vector3D shiftedV = new Vector3D(xDot, u, yDot, v);
    final Vector3D shiftedA = new Vector3D(-getMu() / (r2 * FastMath.sqrt(r2)), shiftedP);
    return new PVCoordinates(shiftedP, shiftedV, shiftedA);

}