List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D angle
public static double angle(Vector3D v1, Vector3D v2) throws MathArithmeticException
From source file:org.orekit.orbits.CartesianOrbit.java
/** {@inheritDoc} */ public double getI() { return Vector3D.angle(Vector3D.PLUS_K, getPVCoordinates().getMomentum()); }
From source file:org.orekit.orbits.CircularOrbit.java
/** Constructor from cartesian parameters. * * <p> The acceleration provided in {@code pvCoordinates} is accessible using * {@link #getPVCoordinates()} and {@link #getPVCoordinates(Frame)}. All other methods * use {@code mu} and the position to compute the acceleration, including * {@link #shiftedBy(double)} and {@link #getPVCoordinates(AbsoluteDate, Frame)}. * * @param pvCoordinates the {@link PVCoordinates} in inertial frame * @param frame the frame in which are defined the {@link PVCoordinates} * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame}) * @param mu central attraction coefficient (m/s) * @exception IllegalArgumentException if frame is not a {@link * Frame#isPseudoInertial pseudo-inertial frame} *//*from w w w. ja v a 2 s .c om*/ public CircularOrbit(final TimeStampedPVCoordinates pvCoordinates, final Frame frame, final double mu) throws IllegalArgumentException { super(pvCoordinates, frame, mu); // compute semi-major axis final Vector3D pvP = pvCoordinates.getPosition(); final Vector3D pvV = pvCoordinates.getVelocity(); final double r = pvP.getNorm(); final double V2 = pvV.getNormSq(); final double rV2OnMu = r * V2 / mu; if (rV2OnMu > 2) { throw new OrekitIllegalArgumentException(OrekitMessages.HYPERBOLIC_ORBIT_NOT_HANDLED_AS, getClass().getName()); } a = r / (2 - rV2OnMu); // compute inclination final Vector3D momentum = pvCoordinates.getMomentum(); i = Vector3D.angle(momentum, Vector3D.PLUS_K); // compute right ascension of ascending node final Vector3D node = Vector3D.crossProduct(Vector3D.PLUS_K, momentum); raan = FastMath.atan2(node.getY(), node.getX()); // 2D-coordinates in the canonical frame final double cosRaan = FastMath.cos(raan); final double sinRaan = FastMath.sin(raan); final double cosI = FastMath.cos(i); final double sinI = FastMath.sin(i); final double xP = pvP.getX(); final double yP = pvP.getY(); final double zP = pvP.getZ(); final double x2 = (xP * cosRaan + yP * sinRaan) / a; final double y2 = ((yP * cosRaan - xP * sinRaan) * cosI + zP * sinI) / a; // compute eccentricity vector final double eSE = Vector3D.dotProduct(pvP, pvV) / FastMath.sqrt(mu * a); final double eCE = rV2OnMu - 1; final double e2 = eCE * eCE + eSE * eSE; final double f = eCE - e2; final double g = FastMath.sqrt(1 - e2) * eSE; final double aOnR = a / r; final double a2OnR2 = aOnR * aOnR; ex = a2OnR2 * (f * x2 + g * y2); ey = a2OnR2 * (f * y2 - g * x2); // compute latitude argument final double beta = 1 / (1 + FastMath.sqrt(1 - ex * ex - ey * ey)); alphaV = eccentricToTrue(FastMath.atan2(y2 + ey + eSE * beta * ex, x2 + ex - eSE * beta * ey)); serializePV = true; }
From source file:org.orekit.orbits.KeplerianOrbit.java
/** Constructor from cartesian parameters. * * <p> The acceleration provided in {@code pvCoordinates} is accessible using * {@link #getPVCoordinates()} and {@link #getPVCoordinates(Frame)}. All other methods * use {@code mu} and the position to compute the acceleration, including * {@link #shiftedBy(double)} and {@link #getPVCoordinates(AbsoluteDate, Frame)}. * * @param pvCoordinates the PVCoordinates of the satellite * @param frame the frame in which are defined the {@link PVCoordinates} * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame}) * @param mu central attraction coefficient (m/s) * @exception IllegalArgumentException if frame is not a {@link * Frame#isPseudoInertial pseudo-inertial frame} *///from w w w .ja va 2 s .c om public KeplerianOrbit(final TimeStampedPVCoordinates pvCoordinates, final Frame frame, final double mu) throws IllegalArgumentException { super(pvCoordinates, frame, mu); // compute inclination final Vector3D momentum = pvCoordinates.getMomentum(); final double m2 = momentum.getNormSq(); i = Vector3D.angle(momentum, Vector3D.PLUS_K); // compute right ascension of ascending node raan = Vector3D.crossProduct(Vector3D.PLUS_K, momentum).getAlpha(); // preliminary computations for parameters depending on orbit shape (elliptic or hyperbolic) final Vector3D pvP = pvCoordinates.getPosition(); final Vector3D pvV = pvCoordinates.getVelocity(); final double r = pvP.getNorm(); final double V2 = pvV.getNormSq(); final double rV2OnMu = r * V2 / mu; // compute semi-major axis (will be negative for hyperbolic orbits) a = r / (2 - rV2OnMu); final double muA = mu * a; // compute true anomaly if (a > 0) { // elliptic or circular orbit final double eSE = Vector3D.dotProduct(pvP, pvV) / FastMath.sqrt(muA); final double eCE = rV2OnMu - 1; e = FastMath.sqrt(eSE * eSE + eCE * eCE); v = ellipticEccentricToTrue(FastMath.atan2(eSE, eCE)); } else { // hyperbolic orbit final double eSH = Vector3D.dotProduct(pvP, pvV) / FastMath.sqrt(-muA); final double eCH = rV2OnMu - 1; e = FastMath.sqrt(1 - m2 / muA); v = hyperbolicEccentricToTrue(FastMath.log((eCH + eSH) / (eCH - eSH)) / 2); } // compute perigee argument final Vector3D node = new Vector3D(raan, 0.0); final double px = Vector3D.dotProduct(pvP, node); final double py = Vector3D.dotProduct(pvP, Vector3D.crossProduct(momentum, node)) / FastMath.sqrt(m2); pa = FastMath.atan2(py, px) - v; }
From source file:org.orekit.propagation.events.CircularFieldOfViewDetector.java
/** {@inheritDoc} * <p>//from w ww. j a v a 2s . com * The g function value is the difference between FOV half aperture and the * absolute value of the angle between target direction and field of view center. * It is positive inside the FOV and negative outside. * </p> */ public double g(final SpacecraftState s) throws OrekitException { // Compute target position/velocity at date in spacecraft frame */ final Vector3D targetPosInert = new Vector3D(1, targetPVProvider.getPVCoordinates(s.getDate(), s.getFrame()).getPosition(), -1, s.getPVCoordinates().getPosition()); final Vector3D targetPosSat = s.getAttitude().getRotation().applyTo(targetPosInert); // Target is in the field of view if the absolute value that angle is smaller than FOV half aperture. // g function value is the difference between FOV half aperture and the absolute value of the angle between // target direction and field of view center. It is positive inside the FOV and negative outside. return halfAperture - Vector3D.angle(targetPosSat, center); }
From source file:org.orekit.propagation.events.EclipseDetector.java
/** Compute the value of the switching function. * This function becomes negative when entering the region of shadow * and positive when exiting.// ww w.jav a2 s . c o m * @param s the current state information: date, kinematics, attitude * @return value of the switching function * @exception OrekitException if some specific error occurs */ public double g(final SpacecraftState s) throws OrekitException { final Vector3D pted = occulted.getPVCoordinates(s.getDate(), s.getFrame()).getPosition(); final Vector3D ping = occulting.getPVCoordinates(s.getDate(), s.getFrame()).getPosition(); final Vector3D psat = s.getPVCoordinates().getPosition(); final Vector3D ps = pted.subtract(psat); final Vector3D po = ping.subtract(psat); final double angle = Vector3D.angle(ps, po); final double rs = FastMath.asin(occultedRadius / ps.getNorm()); if (Double.isNaN(rs)) { return FastMath.PI; } final double ro = FastMath.asin(occultingRadius / po.getNorm()); if (Double.isNaN(ro)) { return -FastMath.PI; } return totalEclipse ? (angle - ro + rs) : (angle - ro - rs); }
From source file:org.orekit.propagation.SpacecraftStateTest.java
@Test public void testTransform() throws ParseException, OrekitException { double maxDP = 0; double maxDV = 0; double maxDA = 0; for (double t = 0; t < orbit.getKeplerianPeriod(); t += 60) { final SpacecraftState state = propagator.propagate(orbit.getDate().shiftedBy(t)); final Transform transform = state.toTransform().getInverse(); PVCoordinates pv = transform.transformPVCoordinates(PVCoordinates.ZERO); PVCoordinates dPV = new PVCoordinates(pv, state.getPVCoordinates()); Vector3D mZDirection = transform.transformVector(Vector3D.MINUS_K); double alpha = Vector3D.angle(mZDirection, state.getPVCoordinates().getPosition()); maxDP = FastMath.max(maxDP, dPV.getPosition().getNorm()); maxDV = FastMath.max(maxDV, dPV.getVelocity().getNorm()); maxDA = FastMath.max(maxDA, FastMath.toDegrees(alpha)); }// ww w . j ava 2 s . c o m Assert.assertEquals(0.0, maxDP, 1.0e-6); Assert.assertEquals(0.0, maxDV, 1.0e-9); Assert.assertEquals(0.0, maxDA, 1.0e-12); }
From source file:org.orekit.utils.AngularCoordinatesTest.java
@Test public void testRodriguesSpecialCases() { // identity//from www . ja v a 2 s .c om double[][] identity = new AngularCoordinates(Rotation.IDENTITY, Vector3D.ZERO, Vector3D.ZERO) .getModifiedRodrigues(1.0); for (double[] row : identity) { for (double element : row) { Assert.assertEquals(0.0, element, Precision.SAFE_MIN); } } AngularCoordinates acId = AngularCoordinates.createFromModifiedRodrigues(identity); Assert.assertEquals(0.0, acId.getRotation().getAngle(), Precision.SAFE_MIN); Assert.assertEquals(0.0, acId.getRotationRate().getNorm(), Precision.SAFE_MIN); // PI angle rotation (which is singular for non-modified Rodrigues vector) RandomGenerator random = new Well1024a(0x2158523e6accb859l); for (int i = 0; i < 100; ++i) { Vector3D axis = randomVector(random, 1.0); AngularCoordinates original = new AngularCoordinates(new Rotation(axis, FastMath.PI), Vector3D.ZERO, Vector3D.ZERO); AngularCoordinates rebuilt = AngularCoordinates .createFromModifiedRodrigues(original.getModifiedRodrigues(1.0)); Assert.assertEquals(FastMath.PI, rebuilt.getRotation().getAngle(), 1.0e-15); Assert.assertEquals(0.0, FastMath.sin(Vector3D.angle(axis, rebuilt.getRotation().getAxis())), 1.0e-15); Assert.assertEquals(0.0, rebuilt.getRotationRate().getNorm(), 1.0e-16); } }
From source file:ru.jts_dev.gameserver.movement.MovementService.java
public void moveTo(final GameSession session, final GameCharacter character, final Vector3D end) { final Vector3D start = character.getVector3D(); final Line line = new Line(start, end, 1.0D); final double distance = start.distance(end); final Vector3D direction = line.getDirection(); final double angle = Vector3D.angle(start, direction); final double degree = FastMath.toDegrees(angle); //final Rotation rotation = new Rotation(start, end); //final double angle = rotation.getAngle(); logger.info("MovementService angle = {}", angle); logger.info("MovementService degree = {}", degree); character.setVector3D(start);/*from w w w .ja v a 2 s. c om*/ final int clientHeading = rotationUtils.convertAngleToClientHeading((int) degree); //broadcastService.send(session, new StartRotating(character, clientHeading, 0, 200)); character.setAngle(degree); character.setMoving(true); final Runnable moveTask = new MoveTask(session, character, start, end, direction, distance, true); ScheduledFuture<?> future = scheduledExecutorService.schedule(moveTask, MOVE_TASK_INTERVAL_MILLIS, TimeUnit.MILLISECONDS); tasks.put(character.getObjectId(), future); }