List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D subtract
public Vector3D subtract(final Vector<Euclidean3D> v)
From source file:org.orekit.bodies.EllipsoidTest.java
@Test public void testRandomNormalSections() throws IOException { RandomGenerator random = new Well19937a(0x573c54d152aeafe4l); for (int i = 0; i < 100; ++i) { double a = 10 * random.nextDouble(); double b = 10 * random.nextDouble(); double c = 10 * random.nextDouble(); double size = FastMath.max(FastMath.max(a, b), c); final Ellipsoid ellipsoid = new Ellipsoid(FramesFactory.getEME2000(), a, b, c); for (int j = 0; j < 50; ++j) { double phi = FastMath.PI * (random.nextDouble() - 0.5); double lambda = 2 * FastMath.PI * random.nextDouble(); double cPhi = FastMath.cos(phi); double sPhi = FastMath.sin(phi); double cLambda = FastMath.cos(lambda); double sLambda = FastMath.sin(lambda); Vector3D surfacePoint = new Vector3D(ellipsoid.getA() * cPhi * cLambda, ellipsoid.getB() * cPhi * sLambda, ellipsoid.getC() * sPhi); Vector3D t1 = new Vector3D(-ellipsoid.getA() * cPhi * sLambda, ellipsoid.getB() * cPhi * cLambda, 0) .normalize();/*from ww w. j a va 2 s. c om*/ Vector3D t2 = new Vector3D(-ellipsoid.getA() * sPhi * cLambda, -ellipsoid.getB() * sPhi * sLambda, ellipsoid.getC() * cPhi).normalize(); final double azimuth = 2 * FastMath.PI * random.nextDouble(); double cAzimuth = FastMath.cos(azimuth); double sAzimuth = FastMath.sin(azimuth); Vector3D tAz = new Vector3D(cAzimuth, t1, sAzimuth, t2); final Ellipse ps = ellipsoid.getPlaneSection(surfacePoint, tAz); Assert.assertEquals(0.0, errorOnEllipsoid(ps, ellipsoid), 1.0e-12 * size); Assert.assertEquals(0.0, errorOnPlane(ps, surfacePoint, tAz), 1.0e-10 * size); double cos = Vector3D.dotProduct(surfacePoint.subtract(ps.getCenter()), ps.getU()) / ps.getA(); double sin = Vector3D.dotProduct(surfacePoint.subtract(ps.getCenter()), ps.getV()) / ps.getB(); final Vector3D rebuilt = ps.pointAt(FastMath.atan2(sin, cos)); Assert.assertEquals(0, Vector3D.distance(surfacePoint, rebuilt), 1.0e-11 * size); } } }
From source file:org.orekit.bodies.EllipsoidTest.java
private double errorOnPlane(Ellipse ps, Vector3D planePoint, Vector3D planeNormal) { double max = 0; for (double theta = 0; theta < 2 * FastMath.PI; theta += 0.1) { Vector3D p = ps.pointAt(theta); max = FastMath.max(max,/* w w w. j a va2s . com*/ FastMath.abs(Vector3D.dotProduct(p.subtract(planePoint).normalize(), planeNormal))); } return max; }
From source file:org.orekit.bodies.JPLEphemeridesLoaderTest.java
private void checkDerivative(String supportedNames, AbsoluteDate date) throws OrekitException, ParseException { JPLEphemeridesLoader loader = new JPLEphemeridesLoader(supportedNames, JPLEphemeridesLoader.EphemerisType.MERCURY); CelestialBody body = loader.loadCelestialBody(CelestialBodyFactory.MERCURY); double h = 20; // eight points finite differences estimation of the velocity Frame eme2000 = FramesFactory.getEME2000(); Vector3D pm4h = body.getPVCoordinates(date.shiftedBy(-4 * h), eme2000).getPosition(); Vector3D pm3h = body.getPVCoordinates(date.shiftedBy(-3 * h), eme2000).getPosition(); Vector3D pm2h = body.getPVCoordinates(date.shiftedBy(-2 * h), eme2000).getPosition(); Vector3D pm1h = body.getPVCoordinates(date.shiftedBy(-h), eme2000).getPosition(); Vector3D pp1h = body.getPVCoordinates(date.shiftedBy(h), eme2000).getPosition(); Vector3D pp2h = body.getPVCoordinates(date.shiftedBy(2 * h), eme2000).getPosition(); Vector3D pp3h = body.getPVCoordinates(date.shiftedBy(3 * h), eme2000).getPosition(); Vector3D pp4h = body.getPVCoordinates(date.shiftedBy(4 * h), eme2000).getPosition(); Vector3D d4 = pp4h.subtract(pm4h); Vector3D d3 = pp3h.subtract(pm3h); Vector3D d2 = pp2h.subtract(pm2h); Vector3D d1 = pp1h.subtract(pm1h); double c = 1.0 / (840 * h); Vector3D estimatedV = new Vector3D(-3 * c, d4, 32 * c, d3, -168 * c, d2, 672 * c, d1); Vector3D loadedV = body.getPVCoordinates(date, eme2000).getVelocity(); Assert.assertEquals(0, loadedV.subtract(estimatedV).getNorm(), 5.0e-11 * loadedV.getNorm()); }
From source file:org.orekit.bodies.OneAxisEllipsoidTest.java
@Test public void testGroundProjectionTaylor() throws OrekitException { Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true); Frame eme2000 = FramesFactory.getEME2000(); OneAxisEllipsoid model = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, itrf); TimeStampedPVCoordinates initPV = new TimeStampedPVCoordinates(AbsoluteDate.J2000_EPOCH.shiftedBy(584.), new Vector3D(3220103., 69623., 6449822.), new Vector3D(6414.7, -2006., -3180.), Vector3D.ZERO); Orbit orbit = new EquinoctialOrbit(initPV, eme2000, Constants.EIGEN5C_EARTH_MU); TimeStampedPVCoordinates pv0 = orbit.getPVCoordinates(orbit.getDate(), model.getBodyFrame()); PVCoordinatesProvider groundTaylor = model.projectToGround(pv0, model.getBodyFrame()) .toTaylorProvider(model.getBodyFrame()); TimeStampedPVCoordinates g0 = groundTaylor.getPVCoordinates(orbit.getDate(), model.getBodyFrame()); Vector3D zenith = pv0.getPosition().subtract(g0.getPosition()).normalize(); Vector3D acrossTrack = Vector3D.crossProduct(zenith, g0.getVelocity()).normalize(); Vector3D alongTrack = Vector3D.crossProduct(acrossTrack, zenith).normalize(); for (double dt = -1; dt < 1; dt += 0.01) { AbsoluteDate date = orbit.getDate().shiftedBy(dt); Vector3D taylorP = groundTaylor.getPVCoordinates(date, model.getBodyFrame()).getPosition(); Vector3D refP = model.projectToGround(orbit.getPVCoordinates(date, model.getBodyFrame()).getPosition(), date, model.getBodyFrame()); Vector3D delta = taylorP.subtract(refP); Assert.assertEquals(0.0, Vector3D.dotProduct(delta, alongTrack), 0.0015); Assert.assertEquals(0.0, Vector3D.dotProduct(delta, acrossTrack), 0.0007); Assert.assertEquals(0.0, Vector3D.dotProduct(delta, zenith), 0.00002); }/*from w ww .ja va 2 s . c om*/ }
From source file:org.orekit.bodies.OneAxisEllipsoidTest.java
private void checkCartesianToEllipsoidic(double ae, double f, double x, double y, double z, double longitude, double latitude, double altitude) throws OrekitException { AbsoluteDate date = AbsoluteDate.J2000_EPOCH; Frame frame = FramesFactory.getITRF(IERSConventions.IERS_2010, true); OneAxisEllipsoid model = new OneAxisEllipsoid(ae, f, frame); GeodeticPoint gp = model.transform(new Vector3D(x, y, z), frame, date); Assert.assertEquals(longitude, MathUtils.normalizeAngle(gp.getLongitude(), longitude), 1.0e-10); Assert.assertEquals(latitude, gp.getLatitude(), 1.0e-10); Assert.assertEquals(altitude, gp.getAltitude(), 1.0e-10 * FastMath.abs(ae)); Vector3D rebuiltNadir = Vector3D.crossProduct(gp.getSouth(), gp.getWest()); Assert.assertEquals(0, rebuiltNadir.subtract(gp.getNadir()).getNorm(), 1.0e-15); }
From source file:org.orekit.forces.AbstractForceModelTest.java
protected void checkParameterDerivative(SpacecraftState state, ForceModel forceModel, String name, double hFactor, double tol) throws OrekitException { try {/*from w w w. jav a 2 s . c o m*/ forceModel.accelerationDerivatives(state, "not a parameter"); Assert.fail("an exception should have been thrown"); } catch (UnknownParameterException upe) { // expected } catch (OrekitException oe) { // expected Assert.assertEquals(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, oe.getSpecifier()); } FieldVector3D<DerivativeStructure> accDer = forceModel.accelerationDerivatives(state, name); Vector3D derivative = new Vector3D(accDer.getX().getPartialDerivative(1), accDer.getY().getPartialDerivative(1), accDer.getZ().getPartialDerivative(1)); AccelerationRetriever accelerationRetriever = new AccelerationRetriever(); double p0 = forceModel.getParameter(name); double hParam = hFactor * forceModel.getParameter(name); forceModel.setParameter(name, p0 - 1 * hParam); Assert.assertEquals(p0 - 1 * hParam, forceModel.getParameter(name), 1.0e-10); forceModel.addContribution(state, accelerationRetriever); final Vector3D gammaM1h = accelerationRetriever.getAcceleration(); forceModel.setParameter(name, p0 + 1 * hParam); Assert.assertEquals(p0 + 1 * hParam, forceModel.getParameter(name), 1.0e-10); forceModel.addContribution(state, accelerationRetriever); final Vector3D gammaP1h = accelerationRetriever.getAcceleration(); final Vector3D reference = new Vector3D(1 / (2 * hParam), gammaP1h.subtract(gammaM1h)); final Vector3D delta = derivative.subtract(reference); Assert.assertEquals(0, delta.getNorm(), tol * reference.getNorm()); }
From source file:org.orekit.forces.BoxAndSolarArraySpacecraftTest.java
@Test public void testWithoutReflection() throws OrekitException { AbsoluteDate initialDate = propagator.getInitialState().getDate(); CelestialBody sun = CelestialBodyFactory.getSun(); BoxAndSolarArraySpacecraft s = new BoxAndSolarArraySpacecraft(1.5, 3.5, 2.5, sun, 20.0, Vector3D.PLUS_J, 1.0, 1.0, 0.0);//from www.j a v a 2s . c o m Vector3D earthRot = new Vector3D(0.0, 0.0, 7.292115e-4); for (double dt = 0; dt < 4000; dt += 60) { AbsoluteDate date = initialDate.shiftedBy(dt); SpacecraftState state = propagator.propagate(date); // simple Earth fixed atmosphere Vector3D p = state.getPVCoordinates().getPosition(); Vector3D v = state.getPVCoordinates().getVelocity(); Vector3D vAtm = Vector3D.crossProduct(earthRot, p); Vector3D relativeVelocity = vAtm.subtract(v); Vector3D drag = s.dragAcceleration(state.getDate(), state.getFrame(), state.getPVCoordinates().getPosition(), state.getAttitude().getRotation(), state.getMass(), 0.001, relativeVelocity); Assert.assertEquals(0.0, Vector3D.angle(relativeVelocity, drag), 1.0e-10); Vector3D sunDirection = sun.getPVCoordinates(date, state.getFrame()).getPosition().normalize(); Vector3D flux = new Vector3D(-4.56e-6, sunDirection); Vector3D radiation = s.radiationPressureAcceleration(state.getDate(), state.getFrame(), state.getPVCoordinates().getPosition(), state.getAttitude().getRotation(), state.getMass(), flux); Assert.assertEquals(0.0, Vector3D.angle(flux, radiation), 1.0e-9); } }
From source file:org.orekit.forces.drag.DragForce.java
/** Compute the contribution of the drag to the perturbing acceleration. * @param s the current state information : date, kinematics, attitude * @param adder object where the contribution should be added * @exception OrekitException if some specific error occurs *//*from w w w. j a v a2 s .c om*/ public void addContribution(final SpacecraftState s, final TimeDerivativesEquations adder) throws OrekitException { final AbsoluteDate date = s.getDate(); final Frame frame = s.getFrame(); final Vector3D position = s.getPVCoordinates().getPosition(); final double rho = atmosphere.getDensity(date, position, frame); final Vector3D vAtm = atmosphere.getVelocity(date, position, frame); final Vector3D relativeVelocity = vAtm.subtract(s.getPVCoordinates().getVelocity()); // Addition of calculated acceleration to adder adder.addAcceleration(spacecraft.dragAcceleration(date, frame, position, s.getAttitude().getRotation(), s.getMass(), rho, relativeVelocity), frame); }
From source file:org.orekit.forces.drag.DragForce.java
/** {@inheritDoc} */ public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s, final String paramName) throws OrekitException { complainIfNotSupported(paramName);//from w ww . ja v a 2s .c o m final AbsoluteDate date = s.getDate(); final Frame frame = s.getFrame(); final Vector3D position = s.getPVCoordinates().getPosition(); final double rho = atmosphere.getDensity(date, position, frame); final Vector3D vAtm = atmosphere.getVelocity(date, position, frame); final Vector3D relativeVelocity = vAtm.subtract(s.getPVCoordinates().getVelocity()); // compute acceleration with all its partial derivatives return spacecraft.dragAcceleration(date, frame, position, s.getAttitude().getRotation(), s.getMass(), rho, relativeVelocity, paramName); }
From source file:org.orekit.forces.drag.SimpleExponentialAtmosphereTest.java
@Test public void testExpAtmosphere() throws OrekitException { Vector3D posInEME2000 = new Vector3D(10000, Vector3D.PLUS_I); AbsoluteDate date = AbsoluteDate.J2000_EPOCH; Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true); SimpleExponentialAtmosphere atm = new SimpleExponentialAtmosphere( new OneAxisEllipsoid(Utils.ae, 1.0 / 298.257222101, itrf), 0.0004, 42000.0, 7500.0); Vector3D vel = atm.getVelocity(date, posInEME2000, FramesFactory.getEME2000()); Transform toBody = FramesFactory.getEME2000().getTransformTo(itrf, date); Vector3D test = Vector3D.crossProduct(toBody.getRotationRate(), posInEME2000); test = test.subtract(vel); Assert.assertEquals(0, test.getNorm(), 2.9e-5); }