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

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

Introduction

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

Prototype

public double getX() 

Source Link

Document

Get the abscissa of the vector.

Usage

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

/** {@inheritDoc} */
public GeodeticPoint getIntersectionPoint(final Line line, final Vector3D close, final Frame frame,
        final AbsoluteDate date) throws OrekitException {

    // transform line and close to body frame
    final Transform frameToBodyFrame = frame.getTransformTo(bodyFrame, date);
    final Line lineInBodyFrame = frameToBodyFrame.transformLine(line);
    final Vector3D closeInBodyFrame = frameToBodyFrame.transformPosition(close);
    final double closeAbscissa = lineInBodyFrame.toSubSpace(closeInBodyFrame).getX();

    // compute some miscellaneous variables outside of the loop
    final Vector3D point = lineInBodyFrame.getOrigin();
    final double x = point.getX();
    final double y = point.getY();
    final double z = point.getZ();
    final double z2 = z * z;
    final double r2 = x * x + y * y;

    final Vector3D direction = lineInBodyFrame.getDirection();
    final double dx = direction.getX();
    final double dy = direction.getY();
    final double dz = direction.getZ();
    final double cz2 = dx * dx + dy * dy;

    // abscissa of the intersection as a root of a 2nd degree polynomial :
    // a k^2 - 2 b k + c = 0
    final double a = 1.0 - e2 * cz2;
    final double b = -(g2 * (x * dx + y * dy) + z * dz);
    final double c = g2 * (r2 - ae2) + z2;
    final double b2 = b * b;
    final double ac = a * c;
    if (b2 < ac) {
        return null;
    }/*from  w  w w .  j ava  2  s  .  c  o m*/
    final double s = FastMath.sqrt(b2 - ac);
    final double k1 = (b < 0) ? (b - s) / a : c / (b + s);
    final double k2 = c / (a * k1);

    // select the right point
    final double k = (FastMath.abs(k1 - closeAbscissa) < FastMath.abs(k2 - closeAbscissa)) ? k1 : k2;
    final Vector3D intersection = lineInBodyFrame.toSpace(new Vector1D(k));
    final double ix = intersection.getX();
    final double iy = intersection.getY();
    final double iz = intersection.getZ();

    final double lambda = FastMath.atan2(iy, ix);
    final double phi = FastMath.atan2(iz, g2 * FastMath.sqrt(ix * ix + iy * iy));
    return new GeodeticPoint(phi, lambda, 0.0);

}

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

/** {@inheritDoc} */
public Vector3D projectToGround(final Vector3D point, final AbsoluteDate date, final Frame frame)
        throws OrekitException {

    // transform point to body frame
    final Transform toBody = frame.getTransformTo(bodyFrame, date);
    final Vector3D p = toBody.transformPosition(point);
    final double z = p.getZ();
    final double r = FastMath.hypot(p.getX(), p.getY());

    // set up the 2D meridian ellipse
    final Ellipse meridian = new Ellipse(Vector3D.ZERO, new Vector3D(p.getX() / r, p.getY() / r, 0),
            Vector3D.PLUS_K, getA(), getC(), bodyFrame);

    // find the closest point in the meridian plane
    final Vector3D groundPoint = meridian.toSpace(meridian.projectToEllipse(new Vector2D(r, z)));

    // transform point back to initial frame
    return toBody.getInverse().transformPosition(groundPoint);

}

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

/** {@inheritDoc} */
public TimeStampedPVCoordinates projectToGround(final TimeStampedPVCoordinates pv, final Frame frame)
        throws OrekitException {

    // transform point to body frame
    final Transform toBody = frame.getTransformTo(bodyFrame, pv.getDate());
    final TimeStampedPVCoordinates pvInBodyFrame = toBody.transformPVCoordinates(pv);
    final Vector3D p = pvInBodyFrame.getPosition();
    final double r = FastMath.hypot(p.getX(), p.getY());

    // set up the 2D ellipse corresponding to first principal curvature along meridian
    final Vector3D meridian = new Vector3D(p.getX() / r, p.getY() / r, 0);
    final Ellipse firstPrincipalCurvature = new Ellipse(Vector3D.ZERO, meridian, Vector3D.PLUS_K, getA(),
            getC(), bodyFrame);/*from  w ww.j av  a 2  s  .c o  m*/

    // project coordinates in the meridian plane
    final TimeStampedPVCoordinates gpFirst = firstPrincipalCurvature.projectToEllipse(pvInBodyFrame);
    final Vector3D gpP = gpFirst.getPosition();
    final double gr = MathArrays.linearCombination(gpP.getX(), meridian.getX(), gpP.getY(), meridian.getY());
    final double gz = gpP.getZ();

    // topocentric frame
    final Vector3D east = new Vector3D(-meridian.getY(), meridian.getX(), 0);
    final Vector3D zenith = new Vector3D(gr * getC() / getA(), meridian, gz * getA() / getC(), Vector3D.PLUS_K)
            .normalize();
    final Vector3D north = Vector3D.crossProduct(zenith, east);

    // set up the ellipse corresponding to second principal curvature in the zenith/east plane
    final Ellipse secondPrincipalCurvature = getPlaneSection(gpP, north);
    final TimeStampedPVCoordinates gpSecond = secondPrincipalCurvature.projectToEllipse(pvInBodyFrame);

    final Vector3D gpV = gpFirst.getVelocity().add(gpSecond.getVelocity());
    final Vector3D gpA = gpFirst.getAcceleration().add(gpSecond.getAcceleration());

    // moving projected point
    final TimeStampedPVCoordinates groundPV = new TimeStampedPVCoordinates(pv.getDate(), gpP, gpV, gpA);

    // transform moving projected point back to initial frame
    return toBody.getInverse().transformPVCoordinates(groundPV);

}

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

/** {@inheritDoc} */
public GeodeticPoint transform(final Vector3D point, final Frame frame, final AbsoluteDate date)
        throws OrekitException {

    // transform point to body frame
    final Vector3D pointInBodyFrame = frame.getTransformTo(bodyFrame, date).transformPosition(point);
    final double r2 = pointInBodyFrame.getX() * pointInBodyFrame.getX()
            + pointInBodyFrame.getY() * pointInBodyFrame.getY();
    final double r = FastMath.sqrt(r2);
    final double z = pointInBodyFrame.getZ();

    // set up the 2D meridian ellipse
    final Ellipse meridian = new Ellipse(Vector3D.ZERO,
            new Vector3D(pointInBodyFrame.getX() / r, pointInBodyFrame.getY() / r, 0), Vector3D.PLUS_K, getA(),
            getC(), bodyFrame);/* w  w w. ja  v a2s.  c  om*/

    // project point on the 2D meridian ellipse
    final Vector2D ellipsePoint = meridian.projectToEllipse(new Vector2D(r, z));

    // relative position of test point with respect to its ellipse sub-point
    final double dr = r - ellipsePoint.getX();
    final double dz = z - ellipsePoint.getY();
    final double insideIfNegative = g2 * (r2 - ae2) + z * z;

    return new GeodeticPoint(FastMath.atan2(ellipsePoint.getY(), g2 * ellipsePoint.getX()),
            FastMath.atan2(pointInBodyFrame.getY(), pointInBodyFrame.getX()),
            FastMath.copySign(FastMath.hypot(dr, dz), insideIfNegative));

}

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

@Test
public void testGeoCar() throws OrekitException {
    OneAxisEllipsoid model = new OneAxisEllipsoid(6378137.0, 1.0 / 298.257222101,
            FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    GeodeticPoint nsp = new GeodeticPoint(0.852479154923577, 0.0423149994747243, 111.6);
    Vector3D p = model.transform(nsp);
    Assert.assertEquals(4201866.69291890, p.getX(), 1.0e-6);
    Assert.assertEquals(177908.184625686, p.getY(), 1.0e-6);
    Assert.assertEquals(4779203.64408617, p.getZ(), 1.0e-6);
}

From source file:org.orekit.files.ccsds.OPMParserTest.java

private void checkPVEntry(final PVCoordinates expected, final PVCoordinates actual) {
    final Vector3D expectedPos = expected.getPosition();
    final Vector3D expectedVel = expected.getVelocity();

    final Vector3D actualPos = actual.getPosition();
    final Vector3D actualVel = actual.getVelocity();

    final double eps = 1e-12;

    Assert.assertEquals(expectedPos.getX(), actualPos.getX(), eps);
    Assert.assertEquals(expectedPos.getY(), actualPos.getY(), eps);
    Assert.assertEquals(expectedPos.getZ(), actualPos.getZ(), eps);

    Assert.assertEquals(expectedVel.getX(), actualVel.getX(), eps);
    Assert.assertEquals(expectedVel.getY(), actualVel.getY(), eps);
    Assert.assertEquals(expectedVel.getZ(), actualVel.getZ(), eps);
}

From source file:org.orekit.files.sp3.SP3ParserTest.java

private void checkPVEntry(final PVCoordinates expected, final PVCoordinates actual) {
    final Vector3D expectedPos = expected.getPosition();
    final Vector3D expectedVel = expected.getVelocity();

    final Vector3D actualPos = actual.getPosition();
    final Vector3D actualVel = actual.getVelocity();

    // sp3 files can have mm accuracy
    final double eps = 1e-3;

    Assert.assertEquals(expectedPos.getX(), actualPos.getX(), eps);
    Assert.assertEquals(expectedPos.getY(), actualPos.getY(), eps);
    Assert.assertEquals(expectedPos.getZ(), actualPos.getZ(), eps);

    Assert.assertEquals(expectedVel.getX(), actualVel.getX(), eps);
    Assert.assertEquals(expectedVel.getY(), actualVel.getY(), eps);
    Assert.assertEquals(expectedVel.getZ(), actualVel.getZ(), eps);
}

From source file:org.orekit.forces.drag.DragForce.java

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

    // retrieve derivation properties
    final int parameters = mass.getFreeParameters();
    final int order = mass.getOrder();

    // get atmosphere properties in atmosphere own frame
    final Frame atmFrame = atmosphere.getFrame();
    final Transform toBody = frame.getTransformTo(atmFrame, date);
    final FieldVector3D<DerivativeStructure> posBodyDS = toBody.transformPosition(position);
    final Vector3D posBody = posBodyDS.toVector3D();
    final double rho = atmosphere.getDensity(date, posBody, atmFrame);
    final Vector3D vAtmBody = atmosphere.getVelocity(date, posBody, atmFrame);

    // we consider that at first order the atmosphere velocity in atmosphere frame
    // does not depend on local position; however atmosphere velocity in inertial
    // frame DOES depend on position since the transform between the frames depends
    // on it, due to central body rotation rate and velocity composition.
    // So we use the transform to get the correct partial derivatives on vAtm
    final FieldVector3D<DerivativeStructure> vAtmBodyDS = new FieldVector3D<DerivativeStructure>(
            new DerivativeStructure(parameters, order, vAtmBody.getX()),
            new DerivativeStructure(parameters, order, vAtmBody.getY()),
            new DerivativeStructure(parameters, order, vAtmBody.getZ()));
    final FieldPVCoordinates<DerivativeStructure> pvAtmBody = new FieldPVCoordinates<DerivativeStructure>(
            posBodyDS, vAtmBodyDS);/*from ww  w.j a va 2s .  c  o  m*/
    final FieldPVCoordinates<DerivativeStructure> pvAtm = toBody.getInverse().transformPVCoordinates(pvAtmBody);

    // now we can compute relative velocity, it takes into account partial derivatives with respect to position
    final FieldVector3D<DerivativeStructure> relativeVelocity = pvAtm.getVelocity().subtract(velocity);

    // compute acceleration with all its partial derivatives
    return spacecraft.dragAcceleration(date, frame, position, rotation, mass, rho, relativeVelocity);

}

From source file:org.orekit.forces.drag.DTM2000.java

/** Get the local density.
 * @param date current date/*from w  w w  .  jav  a 2 s . c  o  m*/
 * @param position current position in frame
 * @param frame the frame in which is defined the position
 * @return local density (kg/m)
 * @exception OrekitException if date is out of range of solar activity model
 * or if some frame conversion cannot be performed
 */
public double getDensity(final AbsoluteDate date, final Vector3D position, final Frame frame)
        throws OrekitException {

    // check if data are available :
    if ((date.compareTo(inputParams.getMaxDate()) > 0) || (date.compareTo(inputParams.getMinDate()) < 0)) {
        throw new OrekitException(OrekitMessages.NO_SOLAR_ACTIVITY_AT_DATE, date, inputParams.getMinDate(),
                inputParams.getMaxDate());
    }

    // compute day number in current year
    final Calendar cal = new GregorianCalendar();
    cal.setTime(date.toDate(TimeScalesFactory.getUTC()));
    final int day = cal.get(Calendar.DAY_OF_YEAR);
    // compute geodetic position
    final GeodeticPoint inBody = earth.transform(position, frame, date);
    final double alti = inBody.getAltitude();
    final double lon = inBody.getLongitude();
    final double lat = inBody.getLatitude();

    // compute local solar time

    final Vector3D sunPos = sun.getPVCoordinates(date, frame).getPosition();
    final double hl = FastMath.PI
            + FastMath.atan2(sunPos.getX() * position.getY() - sunPos.getY() * position.getX(),
                    sunPos.getX() * position.getX() + sunPos.getY() * position.getY());

    // get current solar activity data and compute
    return getDensity(day, alti, lon, lat, hl, inputParams.getInstantFlux(date), inputParams.getMeanFlux(date),
            inputParams.getThreeHourlyKP(date), inputParams.get24HoursKp(date));

}

From source file:org.orekit.forces.drag.HarrisPriester.java

/** Get the local density.
 * @param sunInEarth position of the Sun in Earth frame (m)
 * @param posInEarth target position in Earth frame (m)
 * @return the local density (kg/m)//from  ww  w .  j a  va  2s . com
 * @exception OrekitException if altitude is below the model minimal altitude
 */
public double getDensity(final Vector3D sunInEarth, final Vector3D posInEarth) throws OrekitException {

    final double posAlt = getHeight(posInEarth);
    // Check for height boundaries
    if (posAlt < getMinAlt()) {
        throw new OrekitException(OrekitMessages.ALTITUDE_BELOW_ALLOWED_THRESHOLD, posAlt, getMinAlt());
    }
    if (posAlt > getMaxAlt()) {
        return 0.;
    }

    // Diurnal bulge apex direction
    final Vector3D sunDir = sunInEarth.normalize();
    final Vector3D bulDir = new Vector3D(sunDir.getX() * COSLAG - sunDir.getY() * SINLAG,
            sunDir.getX() * SINLAG + sunDir.getY() * COSLAG, sunDir.getZ());

    // Cosine of angle Psi between the diurnal bulge apex and the satellite
    final double cosPsi = bulDir.normalize().dotProduct(posInEarth.normalize());
    // (1 + cos(Psi))/2 = cos(Psi/2)
    final double c2Psi2 = (1. + cosPsi) / 2.;
    final double cPsi2 = FastMath.sqrt(c2Psi2);
    final double cosPow = (cPsi2 > MIN_COS) ? c2Psi2 * FastMath.pow(cPsi2, n - 2) : 0.;

    // Search altitude index in density table
    int ia = 0;
    while (ia < tabAltRho.length - 2 && posAlt > tabAltRho[ia + 1][0]) {
        ia++;
    }

    // Fractional satellite height
    final double dH = (tabAltRho[ia][0] - posAlt) / (tabAltRho[ia][0] - tabAltRho[ia + 1][0]);

    // Min exponential density interpolation
    final double rhoMin = tabAltRho[ia][1] * FastMath.pow(tabAltRho[ia + 1][1] / tabAltRho[ia][1], dH);

    if (Precision.equals(cosPow, 0.)) {
        return rhoMin;
    } else {
        // Max exponential density interpolation
        final double rhoMax = tabAltRho[ia][2] * FastMath.pow(tabAltRho[ia + 1][2] / tabAltRho[ia][2], dH);
        return rhoMin + (rhoMax - rhoMin) * cosPow;
    }

}