List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D
public Vector3D(double x, double y, double z)
From source file:org.orekit.models.earth.GeoMagneticField.java
/** Computes Geomagnetic Field Elements X, Y and Z in spherical coordinate * system using spherical harmonic summation. * The vector Magnetic field is given by -grad V, where V is geomagnetic * scalar potential. The gradient in spherical coordinates is given by: * <pre>// w ww . j a v a 2s . c om * dV ^ 1 dV ^ 1 dV ^ * grad V = -- r + - -- t + -------- -- p * dr r dt r sin(t) dp * </pre> * @param sph the spherical coordinates * @param vars the spherical harmonic variables * @param legendre the legendre function * @return the magnetic field vector in spherical coordinates */ private Vector3D summation(final SphericalCoordinates sph, final SphericalHarmonicVars vars, final LegendreFunction legendre) { int index; double Bx = 0.0; double By = 0.0; double Bz = 0.0; for (int n = 1; n <= maxN; n++) { for (int m = 0; m <= n; m++) { index = n * (n + 1) / 2 + m; /** * <pre> * nMax (n+2) n m m m * Bz = -SUM (n + 1) * (a/r) * SUM [g cos(m p) + h sin(m p)] P (sin(phi)) * n=1 m=0 n n n * </pre> * Equation 12 in the WMM Technical report. Derivative with respect to radius. */ Bz -= vars.relativeRadiusPower[n] * (g[index] * vars.cmLambda[m] + h[index] * vars.smLambda[m]) * (1d + n) * legendre.mP[index]; /** * <pre> * nMax (n+2) n m m m * By = SUM (a/r) * SUM [g cos(m p) + h sin(m p)] dP (sin(phi)) * n=1 m=0 n n n * </pre> * Equation 11 in the WMM Technical report. Derivative with respect to longitude, divided by radius. */ By += vars.relativeRadiusPower[n] * (g[index] * vars.smLambda[m] - h[index] * vars.cmLambda[m]) * (double) m * legendre.mP[index]; /** * <pre> * nMax (n+2) n m m m * Bx = - SUM (a/r) * SUM [g cos(m p) + h sin(m p)] dP (sin(phi)) * n=1 m=0 n n n * </pre> * Equation 10 in the WMM Technical report. Derivative with respect to latitude, divided by radius. */ Bx -= vars.relativeRadiusPower[n] * (g[index] * vars.cmLambda[m] + h[index] * vars.smLambda[m]) * legendre.mPDeriv[index]; } } final double cosPhi = FastMath.cos(sph.phi); if (FastMath.abs(cosPhi) > 1.0e-10) { By = By / cosPhi; } else { // special calculation for component - By - at geographic poles. // To avoid using this function, make sure that the latitude is not // exactly +/-90. By = summationSpecial(sph, vars); } return new Vector3D(Bx, By, Bz); }
From source file:org.orekit.models.earth.tessellation.AlongTrackAiming.java
/** {@inheritDoc} */ @Override/*from w ww. j a va2 s . com*/ public Vector3D alongTileDirection(final Vector3D point, final GeodeticPoint gp) throws OrekitException { final double lStart = halfTrack.get(0).getFirst().getLatitude(); final double lEnd = halfTrack.get(halfTrack.size() - 1).getFirst().getLatitude(); // check the point can be reached if (gp.getLatitude() < FastMath.min(lStart, lEnd) || gp.getLatitude() > FastMath.max(lStart, lEnd)) { throw new OrekitException(OrekitMessages.OUT_OF_RANGE_LATITUDE, FastMath.toDegrees(gp.getLatitude()), FastMath.toDegrees(FastMath.min(lStart, lEnd)), FastMath.toDegrees(FastMath.max(lStart, lEnd))); } // bracket the point in the half track sample int iInf = 0; int iSup = halfTrack.size() - 1; while (iSup - iInf > 1) { final int iMiddle = (iSup + iInf) / 2; if ((lStart < lEnd) ^ (halfTrack.get(iMiddle).getFirst().getLatitude() > gp.getLatitude())) { // the specified latitude is in the second half iInf = iMiddle; } else { // the specified latitude is in the first half iSup = iMiddle; } } // ensure we can get points at iStart, iStart + 1, iStart + 2 and iStart + 3 final int iStart = FastMath.max(0, FastMath.min(iInf - 1, halfTrack.size() - 4)); // interpolate ground sliding point at specified latitude final HermiteInterpolator interpolator = new HermiteInterpolator(); for (int i = iStart; i < iStart + 4; ++i) { final Vector3D position = halfTrack.get(i).getSecond().getPosition(); final Vector3D velocity = halfTrack.get(i).getSecond().getVelocity(); interpolator.addSamplePoint(halfTrack.get(i).getFirst().getLatitude(), new double[] { position.getX(), position.getY(), position.getZ(), velocity.getX(), velocity.getY(), velocity.getZ() }); } final DerivativeStructure[] p = interpolator.value(new DerivativeStructure(1, 1, 0, gp.getLatitude())); // extract interpolated ground position/velocity final Vector3D position = new Vector3D(p[0].getValue(), p[1].getValue(), p[2].getValue()); final Vector3D velocity = new Vector3D(p[3].getValue(), p[4].getValue(), p[5].getValue()); // adjust longitude to match the specified one final Rotation rotation = new Rotation(Vector3D.PLUS_K, position, Vector3D.PLUS_K, point); final Vector3D fixedVelocity = rotation.applyTo(velocity); // the tile direction is aligned with sliding point velocity return fixedVelocity.normalize(); }
From source file:org.orekit.orbits.CartesianParametersTest.java
@Test public void testCartesianToCartesian() { Vector3D position = new Vector3D(-29536113.0, 30329259.0, -100125.0); Vector3D velocity = new Vector3D(-2194.0, -2141.0, -8.0); PVCoordinates pvCoordinates = new PVCoordinates(position, velocity); double mu = 3.9860047e14; CartesianOrbit p = new CartesianOrbit(pvCoordinates, FramesFactory.getEME2000(), date, mu); Assert.assertEquals(p.getPVCoordinates().getPosition().getX(), pvCoordinates.getPosition().getX(), Utils.epsilonTest * FastMath.abs(pvCoordinates.getPosition().getX())); Assert.assertEquals(p.getPVCoordinates().getPosition().getY(), pvCoordinates.getPosition().getY(), Utils.epsilonTest * FastMath.abs(pvCoordinates.getPosition().getY())); Assert.assertEquals(p.getPVCoordinates().getPosition().getZ(), pvCoordinates.getPosition().getZ(), Utils.epsilonTest * FastMath.abs(pvCoordinates.getPosition().getZ())); Assert.assertEquals(p.getPVCoordinates().getVelocity().getX(), pvCoordinates.getVelocity().getX(), Utils.epsilonTest * FastMath.abs(pvCoordinates.getVelocity().getX())); Assert.assertEquals(p.getPVCoordinates().getVelocity().getY(), pvCoordinates.getVelocity().getY(), Utils.epsilonTest * FastMath.abs(pvCoordinates.getVelocity().getY())); Assert.assertEquals(p.getPVCoordinates().getVelocity().getZ(), pvCoordinates.getVelocity().getZ(), Utils.epsilonTest * FastMath.abs(pvCoordinates.getVelocity().getZ())); }
From source file:org.orekit.orbits.CartesianParametersTest.java
@Test public void testCartesianToEquinoctial() { Vector3D position = new Vector3D(-29536113.0, 30329259.0, -100125.0); Vector3D velocity = new Vector3D(-2194.0, -2141.0, -8.0); PVCoordinates pvCoordinates = new PVCoordinates(position, velocity); CartesianOrbit p = new CartesianOrbit(pvCoordinates, FramesFactory.getEME2000(), date, mu); Assert.assertEquals(42255170.0028257, p.getA(), Utils.epsilonTest * p.getA()); Assert.assertEquals(0.592732497856475e-03, p.getEquinoctialEx(), Utils.epsilonE * FastMath.abs(p.getE())); Assert.assertEquals(-0.206274396964359e-02, p.getEquinoctialEy(), Utils.epsilonE * FastMath.abs(p.getE())); Assert.assertEquals(/* w ww . ja v a2 s . c o m*/ FastMath.sqrt(FastMath.pow(0.592732497856475e-03, 2) + FastMath.pow(-0.206274396964359e-02, 2)), p.getE(), Utils.epsilonAngle * FastMath.abs(p.getE())); Assert.assertEquals(MathUtils.normalizeAngle( 2 * FastMath.asin(FastMath.sqrt( (FastMath.pow(0.128021863908325e-03, 2) + FastMath.pow(-0.352136186881817e-02, 2)) / 4.)), p.getI()), p.getI(), Utils.epsilonAngle * FastMath.abs(p.getI())); Assert.assertEquals(MathUtils.normalizeAngle(0.234498139679291e+01, p.getLM()), p.getLM(), Utils.epsilonAngle * FastMath.abs(p.getLM())); }
From source file:org.orekit.orbits.CartesianParametersTest.java
@Test public void testCartesianToKeplerian() { Vector3D position = new Vector3D(-26655470.0, 29881667.0, -113657.0); Vector3D velocity = new Vector3D(-1125.0, -1122.0, 195.0); PVCoordinates pvCoordinates = new PVCoordinates(position, velocity); double mu = 3.9860047e14; CartesianOrbit p = new CartesianOrbit(pvCoordinates, FramesFactory.getEME2000(), date, mu); KeplerianOrbit kep = new KeplerianOrbit(p); Assert.assertEquals(22979265.3030773, p.getA(), Utils.epsilonTest * p.getA()); Assert.assertEquals(0.743502611664700, p.getE(), Utils.epsilonE * FastMath.abs(p.getE())); Assert.assertEquals(0.122182096220906, p.getI(), Utils.epsilonAngle * FastMath.abs(p.getI())); double pa = kep.getPerigeeArgument(); Assert.assertEquals(MathUtils.normalizeAngle(3.09909041016672, pa), pa, Utils.epsilonAngle * FastMath.abs(pa)); double raan = kep.getRightAscensionOfAscendingNode(); Assert.assertEquals(MathUtils.normalizeAngle(2.32231010979999, raan), raan, Utils.epsilonAngle * FastMath.abs(raan)); double m = kep.getMeanAnomaly(); Assert.assertEquals(MathUtils.normalizeAngle(3.22888977629034, m), m, Utils.epsilonAngle * FastMath.abs(FastMath.abs(m))); }
From source file:org.orekit.orbits.CartesianParametersTest.java
@Test public void testPositionVelocityNorms() { Vector3D position = new Vector3D(-29536113.0, 30329259.0, -100125.0); Vector3D velocity = new Vector3D(-2194.0, -2141.0, -8.0); PVCoordinates pvCoordinates = new PVCoordinates(position, velocity); CartesianOrbit p = new CartesianOrbit(pvCoordinates, FramesFactory.getEME2000(), date, mu); double e = p.getE(); double v = new KeplerianOrbit(p).getTrueAnomaly(); double ksi = 1 + e * FastMath.cos(v); double nu = e * FastMath.sin(v); double epsilon = FastMath.sqrt((1 - e) * (1 + e)); double a = p.getA(); double na = FastMath.sqrt(mu / a); // validation of: r = a .(1 - e2) / (1 + e.cos(v)) Assert.assertEquals(a * epsilon * epsilon / ksi, p.getPVCoordinates().getPosition().getNorm(), Utils.epsilonTest * FastMath.abs(p.getPVCoordinates().getPosition().getNorm())); // validation of: V = sqrt(mu.(1+2e.cos(v)+e2)/a.(1-e2) ) Assert.assertEquals(na * FastMath.sqrt(ksi * ksi + nu * nu) / epsilon, p.getPVCoordinates().getVelocity().getNorm(), Utils.epsilonTest * FastMath.abs(p.getPVCoordinates().getVelocity().getNorm())); }
From source file:org.orekit.orbits.CartesianParametersTest.java
@Test public void testGeometry() { Vector3D position = new Vector3D(-29536113.0, 30329259.0, -100125.0); Vector3D velocity = new Vector3D(-2194.0, -2141.0, -8.0); PVCoordinates pvCoordinates = new PVCoordinates(position, velocity); Vector3D momentum = pvCoordinates.getMomentum().normalize(); EquinoctialOrbit p = new EquinoctialOrbit(pvCoordinates, FramesFactory.getEME2000(), date, mu); double apogeeRadius = p.getA() * (1 + p.getE()); double perigeeRadius = p.getA() * (1 - p.getE()); for (double lv = 0; lv <= 2 * FastMath.PI; lv += 2 * FastMath.PI / 100.) { p = new EquinoctialOrbit(p.getA(), p.getEquinoctialEx(), p.getEquinoctialEy(), p.getHx(), p.getHy(), lv, PositionAngle.TRUE, p.getFrame(), date, mu); position = p.getPVCoordinates().getPosition(); // test if the norm of the position is in the range [perigee radius, apogee radius] // Warning: these tests are without absolute value by choice Assert.assertTrue((position.getNorm() - apogeeRadius) <= (apogeeRadius * Utils.epsilonTest)); Assert.assertTrue((position.getNorm() - perigeeRadius) >= (-perigeeRadius * Utils.epsilonTest)); // Assert.assertTrue(position.getNorm() <= apogeeRadius); // Assert.assertTrue(position.getNorm() >= perigeeRadius); position = position.normalize(); velocity = p.getPVCoordinates().getVelocity().normalize(); // at this stage of computation, all the vectors (position, velocity and momemtum) are normalized here // test of orthogonality between position and momentum Assert.assertTrue(FastMath.abs(Vector3D.dotProduct(position, momentum)) < Utils.epsilonTest); // test of orthogonality between velocity and momentum Assert.assertTrue(FastMath.abs(Vector3D.dotProduct(velocity, momentum)) < Utils.epsilonTest); }//ww w. ja v a 2 s .com }
From source file:org.orekit.orbits.CartesianParametersTest.java
@Test public void testNumericalIssue25() throws OrekitException { Vector3D position = new Vector3D(3782116.14107698, 416663.11924914, 5875541.62103057); Vector3D velocity = new Vector3D(-6349.7848910501, 288.4061811651, 4066.9366759691); CartesianOrbit orbit = new CartesianOrbit(new PVCoordinates(position, velocity), FramesFactory.getEME2000(), new AbsoluteDate("2004-01-01T23:00:00.000", TimeScalesFactory.getUTC()), 3.986004415E14); Assert.assertEquals(0.0, orbit.getE(), 2.0e-14); }
From source file:org.orekit.orbits.CartesianParametersTest.java
@Test public void testSerialization() throws IOException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException { Vector3D position = new Vector3D(-29536113.0, 30329259.0, -100125.0); Vector3D velocity = new Vector3D(-2194.0, -2141.0, -8.0); PVCoordinates pvCoordinates = new PVCoordinates(position, velocity); CartesianOrbit orbit = new CartesianOrbit(pvCoordinates, FramesFactory.getEME2000(), date, mu); Assert.assertEquals(42255170.003, orbit.getA(), 1.0e-3); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(orbit);/*from w ww. j a va2s . c o m*/ Assert.assertTrue(bos.size() > 250); Assert.assertTrue(bos.size() < 350); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bis); CartesianOrbit deserialized = (CartesianOrbit) ois.readObject(); PVCoordinates dpv = new PVCoordinates(orbit.getPVCoordinates(), deserialized.getPVCoordinates()); Assert.assertEquals(0.0, dpv.getPosition().getNorm(), 1.0e-10); Assert.assertEquals(0.0, dpv.getVelocity().getNorm(), 1.0e-10); Assert.assertEquals(orbit.getDate(), deserialized.getDate()); Assert.assertEquals(orbit.getMu(), deserialized.getMu(), 1.0e-10); }
From source file:org.orekit.orbits.CartesianParametersTest.java
@Test public void testShiftElliptic() { Vector3D position = new Vector3D(-29536113.0, 30329259.0, -100125.0); Vector3D velocity = new Vector3D(-2194.0, -2141.0, -8.0); PVCoordinates pvCoordinates = new PVCoordinates(position, velocity); CartesianOrbit orbit = new CartesianOrbit(pvCoordinates, FramesFactory.getEME2000(), date, mu); testShift(orbit, new KeplerianOrbit(orbit), 1.0e-13); }