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

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

Introduction

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

Prototype

public static <T extends RealFieldElement<T>> T dotProduct(final Vector3D v1, final FieldVector3D<T> v2) 

Source Link

Document

Compute the dot-product of two vectors.

Usage

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

/** Get solar array normal in spacecraft frame.
 * @param date current date/*ww  w .  ja  va 2 s  .c  o  m*/
 * @param frame inertial reference frame for state (both orbit and attitude)
 * @param position position of spacecraft in reference frame
 * @param rotation orientation (attitude) of the spacecraft with respect to reference frame
 * @return solar array normal in spacecraft frame
 * @exception OrekitException if sun direction cannot be computed in best lightning
 * configuration
 */
public synchronized FieldVector3D<DerivativeStructure> getNormal(final AbsoluteDate date, final Frame frame,
        final FieldVector3D<DerivativeStructure> position, final FieldRotation<DerivativeStructure> rotation)
        throws OrekitException {

    final DerivativeStructure one = position.getX().getField().getOne();

    if (referenceDate != null) {
        // use a simple rotation at fixed rate
        final DerivativeStructure alpha = one.multiply(rotationRate * date.durationFrom(referenceDate));
        return new FieldVector3D<DerivativeStructure>(alpha.cos(), saX, alpha.sin(), saY);
    }

    // compute orientation for best lightning
    final FieldVector3D<DerivativeStructure> sunInert = position
            .subtract(sun.getPVCoordinates(date, frame).getPosition()).negate().normalize();
    final FieldVector3D<DerivativeStructure> sunSpacecraft = rotation.applyTo(sunInert);
    final DerivativeStructure d = FieldVector3D.dotProduct(sunSpacecraft, saZ);
    final DerivativeStructure f = d.multiply(d).subtract(1).negate();
    if (f.getValue() < Precision.EPSILON) {
        // extremely rare case: the sun is along solar array rotation axis
        // (there will not be much output power ...)
        // we set up an arbitrary normal
        return new FieldVector3D<DerivativeStructure>(one, saZ.orthogonal());
    }

    final DerivativeStructure s = f.sqrt().reciprocal();
    return new FieldVector3D<DerivativeStructure>(s, sunSpacecraft)
            .subtract(new FieldVector3D<DerivativeStructure>(s.multiply(d), saZ));

}

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

/** {@inheritDoc} */
public FieldVector3D<DerivativeStructure> dragAcceleration(final AbsoluteDate date, final Frame frame,
        final FieldVector3D<DerivativeStructure> position, final FieldRotation<DerivativeStructure> rotation,
        final DerivativeStructure mass, final double density,
        final FieldVector3D<DerivativeStructure> relativeVelocity) throws OrekitException {

    // relative velocity in spacecraft frame
    final FieldVector3D<DerivativeStructure> v = rotation.applyTo(relativeVelocity);

    // solar array contribution
    final FieldVector3D<DerivativeStructure> solarArrayFacet = new FieldVector3D<DerivativeStructure>(
            solarArrayArea, getNormal(date, frame, position, rotation));
    DerivativeStructure sv = FieldVector3D.dotProduct(v, solarArrayFacet).abs();

    // body facets contribution
    for (final Facet facet : facets) {
        final DerivativeStructure dot = FieldVector3D.dotProduct(v, facet.getNormal());
        if (dot.getValue() < 0) {
            // the facet intercepts the incoming flux
            sv = sv.subtract(dot.multiply(facet.getArea()));
        }//  w  w  w  . j  av  a 2  s  . c o m
    }

    return new FieldVector3D<DerivativeStructure>(sv.multiply(density * dragCoeff / 2.0).divide(mass),
            relativeVelocity);

}

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

/** {@inheritDoc} */
public FieldVector3D<DerivativeStructure> radiationPressureAcceleration(final AbsoluteDate date,
        final Frame frame, final FieldVector3D<DerivativeStructure> position,
        final FieldRotation<DerivativeStructure> rotation, final DerivativeStructure mass,
        final FieldVector3D<DerivativeStructure> flux) throws OrekitException {

    if (flux.getNormSq().getValue() < Precision.SAFE_MIN) {
        // null illumination (we are probably in umbra)
        return new FieldVector3D<DerivativeStructure>(0.0, flux);
    }//from w ww.  ja v  a2 s .  co m

    // radiation flux in spacecraft frame
    final FieldVector3D<DerivativeStructure> fluxSat = rotation.applyTo(flux);

    // solar array contribution
    FieldVector3D<DerivativeStructure> normal = getNormal(date, frame, position, rotation);
    DerivativeStructure dot = FieldVector3D.dotProduct(normal, fluxSat);
    if (dot.getValue() > 0) {
        // the solar array is illuminated backward,
        // fix signs to compute contribution correctly
        dot = dot.negate();
        normal = normal.negate();
    }
    FieldVector3D<DerivativeStructure> force = facetRadiationAcceleration(normal, solarArrayArea, fluxSat, dot);

    // body facets contribution
    for (final Facet bodyFacet : facets) {
        normal = new FieldVector3D<DerivativeStructure>(mass.getField().getOne(), bodyFacet.getNormal());
        dot = FieldVector3D.dotProduct(normal, fluxSat);
        if (dot.getValue() < 0) {
            // the facet intercepts the incoming flux
            force = force.add(facetRadiationAcceleration(normal, bodyFacet.getArea(), fluxSat, dot));
        }
    }

    // convert to inertial frame
    return rotation.applyInverseTo(new FieldVector3D<DerivativeStructure>(mass.reciprocal(), force));

}

From source file:org.orekit.utils.FieldAngularCoordinatesTest.java

@Test
public void testSpin() throws OrekitException {
    double rate = 2 * FastMath.PI / (12 * 60);
    FieldAngularCoordinates<DerivativeStructure> angularCoordinates = new FieldAngularCoordinates<DerivativeStructure>(
            createRotation(0.48, 0.64, 0.36, 0.48, false),
            new FieldVector3D<DerivativeStructure>(rate, createVector(0, 0, 1, 4)), createVector(0, 0, 0, 4));
    Assert.assertEquals(rate, angularCoordinates.getRotationRate().getNorm().getReal(), 1.0e-10);
    double dt = 10.0;
    FieldAngularCoordinates<DerivativeStructure> shifted = angularCoordinates.shiftedBy(dt);
    Assert.assertEquals(rate, shifted.getRotationRate().getNorm().getReal(), 1.0e-10);
    Assert.assertEquals(rate * dt,//from  w ww  .  j  a v a2 s  .  c om
            FieldRotation.distance(angularCoordinates.getRotation(), shifted.getRotation()).getReal(), 1.0e-10);

    FieldVector3D<DerivativeStructure> shiftedX = shifted.getRotation()
            .applyInverseTo(createVector(1, 0, 0, 4));
    FieldVector3D<DerivativeStructure> shiftedY = shifted.getRotation()
            .applyInverseTo(createVector(0, 1, 0, 4));
    FieldVector3D<DerivativeStructure> shiftedZ = shifted.getRotation()
            .applyInverseTo(createVector(0, 0, 1, 4));
    FieldVector3D<DerivativeStructure> originalX = angularCoordinates.getRotation()
            .applyInverseTo(createVector(1, 0, 0, 4));
    FieldVector3D<DerivativeStructure> originalY = angularCoordinates.getRotation()
            .applyInverseTo(createVector(0, 1, 0, 4));
    FieldVector3D<DerivativeStructure> originalZ = angularCoordinates.getRotation()
            .applyInverseTo(createVector(0, 0, 1, 4));
    Assert.assertEquals(FastMath.cos(rate * dt), FieldVector3D.dotProduct(shiftedX, originalX).getReal(),
            1.0e-10);
    Assert.assertEquals(FastMath.sin(rate * dt), FieldVector3D.dotProduct(shiftedX, originalY).getReal(),
            1.0e-10);
    Assert.assertEquals(0.0, FieldVector3D.dotProduct(shiftedX, originalZ).getReal(), 1.0e-10);
    Assert.assertEquals(-FastMath.sin(rate * dt), FieldVector3D.dotProduct(shiftedY, originalX).getReal(),
            1.0e-10);
    Assert.assertEquals(FastMath.cos(rate * dt), FieldVector3D.dotProduct(shiftedY, originalY).getReal(),
            1.0e-10);
    Assert.assertEquals(0.0, FieldVector3D.dotProduct(shiftedY, originalZ).getReal(), 1.0e-10);
    Assert.assertEquals(0.0, FieldVector3D.dotProduct(shiftedZ, originalX).getReal(), 1.0e-10);
    Assert.assertEquals(0.0, FieldVector3D.dotProduct(shiftedZ, originalY).getReal(), 1.0e-10);
    Assert.assertEquals(1.0, FieldVector3D.dotProduct(shiftedZ, originalZ).getReal(), 1.0e-10);

    FieldVector3D<DerivativeStructure> forward = FieldAngularCoordinates
            .estimateRate(angularCoordinates.getRotation(), shifted.getRotation(), dt);
    Assert.assertEquals(0.0, forward.subtract(angularCoordinates.getRotationRate()).getNorm().getReal(),
            1.0e-10);

    FieldVector3D<DerivativeStructure> reversed = FieldAngularCoordinates.estimateRate(shifted.getRotation(),
            angularCoordinates.getRotation(), dt);
    Assert.assertEquals(0.0, reversed.add(angularCoordinates.getRotationRate()).getNorm().getReal(), 1.0e-10);

}

From source file:org.orekit.utils.FieldPVCoordinates.java

/** Normalize the position part of the instance.
 * <p>//from  ww w . java  2 s  .  co m
 * The computed coordinates first component (position) will be a
 * normalized vector, the second component (velocity) will be the
 * derivative of the first component (hence it will generally not
 * be normalized), and the third component (acceleration) will be the
 * derivative of the second component (hence it will generally not
 * be normalized).
 * </p>
 * @return a new instance, with first component normalized and
 * remaining component computed to have consistent derivatives
 */
public FieldPVCoordinates<T> normalize() {
    final T inv = position.getNorm().reciprocal();
    final FieldVector3D<T> u = new FieldVector3D<T>(inv, position);
    final FieldVector3D<T> v = new FieldVector3D<T>(inv, velocity);
    final FieldVector3D<T> w = new FieldVector3D<T>(inv, acceleration);
    final T uv = FieldVector3D.dotProduct(u, v);
    final T v2 = FieldVector3D.dotProduct(v, v);
    final T uw = FieldVector3D.dotProduct(u, w);
    final FieldVector3D<T> uDot = new FieldVector3D<T>(inv.getField().getOne(), v, uv.multiply(-1), u);
    final FieldVector3D<T> uDotDot = new FieldVector3D<T>(inv.getField().getOne(), w, uv.multiply(-2), v,
            uv.multiply(uv).multiply(3).subtract(v2).subtract(uw), u);
    return new FieldPVCoordinates<T>(u, uDot, uDotDot);
}

From source file:org.orekit.utils.TimeStampedFieldAngularCoordinatesTest.java

@Test
public void testSpin() throws OrekitException {
    double rate = 2 * FastMath.PI / (12 * 60);
    TimeStampedFieldAngularCoordinates<DerivativeStructure> angularCoordinates = new TimeStampedFieldAngularCoordinates<DerivativeStructure>(
            AbsoluteDate.J2000_EPOCH, createRotation(0.48, 0.64, 0.36, 0.48, false),
            new FieldVector3D<DerivativeStructure>(rate, createVector(0, 0, 1, 4)), createVector(0, 0, 0, 4));
    Assert.assertEquals(rate, angularCoordinates.getRotationRate().getNorm().getReal(), 1.0e-10);
    double dt = 10.0;
    TimeStampedFieldAngularCoordinates<DerivativeStructure> shifted = angularCoordinates.shiftedBy(dt);
    Assert.assertEquals(rate, shifted.getRotationRate().getNorm().getReal(), 1.0e-10);
    Assert.assertEquals(rate * dt,/*from   w  w w. j  a v  a2s .  co  m*/
            FieldRotation.distance(angularCoordinates.getRotation(), shifted.getRotation()).getReal(), 1.0e-10);

    FieldVector3D<DerivativeStructure> shiftedX = shifted.getRotation()
            .applyInverseTo(createVector(1, 0, 0, 4));
    FieldVector3D<DerivativeStructure> shiftedY = shifted.getRotation()
            .applyInverseTo(createVector(0, 1, 0, 4));
    FieldVector3D<DerivativeStructure> shiftedZ = shifted.getRotation()
            .applyInverseTo(createVector(0, 0, 1, 4));
    FieldVector3D<DerivativeStructure> originalX = angularCoordinates.getRotation()
            .applyInverseTo(createVector(1, 0, 0, 4));
    FieldVector3D<DerivativeStructure> originalY = angularCoordinates.getRotation()
            .applyInverseTo(createVector(0, 1, 0, 4));
    FieldVector3D<DerivativeStructure> originalZ = angularCoordinates.getRotation()
            .applyInverseTo(createVector(0, 0, 1, 4));
    Assert.assertEquals(FastMath.cos(rate * dt), FieldVector3D.dotProduct(shiftedX, originalX).getReal(),
            1.0e-10);
    Assert.assertEquals(FastMath.sin(rate * dt), FieldVector3D.dotProduct(shiftedX, originalY).getReal(),
            1.0e-10);
    Assert.assertEquals(0.0, FieldVector3D.dotProduct(shiftedX, originalZ).getReal(), 1.0e-10);
    Assert.assertEquals(-FastMath.sin(rate * dt), FieldVector3D.dotProduct(shiftedY, originalX).getReal(),
            1.0e-10);
    Assert.assertEquals(FastMath.cos(rate * dt), FieldVector3D.dotProduct(shiftedY, originalY).getReal(),
            1.0e-10);
    Assert.assertEquals(0.0, FieldVector3D.dotProduct(shiftedY, originalZ).getReal(), 1.0e-10);
    Assert.assertEquals(0.0, FieldVector3D.dotProduct(shiftedZ, originalX).getReal(), 1.0e-10);
    Assert.assertEquals(0.0, FieldVector3D.dotProduct(shiftedZ, originalY).getReal(), 1.0e-10);
    Assert.assertEquals(1.0, FieldVector3D.dotProduct(shiftedZ, originalZ).getReal(), 1.0e-10);

    FieldVector3D<DerivativeStructure> forward = FieldAngularCoordinates
            .estimateRate(angularCoordinates.getRotation(), shifted.getRotation(), dt);
    Assert.assertEquals(0.0, forward.subtract(angularCoordinates.getRotationRate()).getNorm().getReal(),
            1.0e-10);

    FieldVector3D<DerivativeStructure> reversed = FieldAngularCoordinates.estimateRate(shifted.getRotation(),
            angularCoordinates.getRotation(), dt);
    Assert.assertEquals(0.0, reversed.add(angularCoordinates.getRotationRate()).getNorm().getReal(), 1.0e-10);

}