List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D distance
public static double distance(Vector3D v1, Vector3D v2)
From source file:Engine.AlgebraUtils.java
public static double DistanceBetweenDoubleTables(Vector3D v1, Vector3D v2) { return Vector3D.distance(v1, v2); }
From source file:org.esa.s2tbx.dataio.s2.l1b.CoordinateUtils.java
public static double distanceToSegment(Vector3D v, Vector3D w, Vector3D p) { // Return minimum distance between line segment vw and point p final double l2 = Vector3D.distanceSq(v, w); // i.e. |w-v|^2 - avoid a sqrt if (l2 == 0.0) return Vector3D.distance(p, v); // v == w case // Consider the line extending the segment, parameterized as v + t (w - v). // We find projection of point p onto the line. // It falls where t = [(p-v) . (w-v)] / |w-v|^2 double t = Vector3D.dotProduct(p.subtract(v), w.subtract(v)) / l2; if (t < 0.0) return Vector3D.distance(p, v); // Beyond the 'v' end of the segment else if (t > 1.0) return Vector3D.distance(p, w); // Beyond the 'w' end of the segment Vector3D projection = v.add(w.subtract(v).scalarMultiply(t)); // Projection falls on the segment return Vector3D.distance(p, projection); }
From source file:org.gearvrf.controls.model.Apple.java
public boolean checkValidPosition(Vector3D pos) { Vector3D wormPos = new Vector3D(MainScript.worm.wormParent.getTransform().getPositionX(), MainScript.worm.wormParent.getTransform().getPositionY(), MainScript.worm.wormParent.getTransform().getPositionZ()); if (Vector3D.distance(pos, wormPos) < MAX_APPLES_DISTANCE) return false; for (Apple a : appleList) { if (a == this) continue; Vector3D iteratedApple = new Vector3D(a.getTransform().getPositionX(), 0, a.getTransform().getPositionZ()); float distance = (float) Vector3D.distance(pos, iteratedApple); if (distance < MAX_APPLES_DISTANCE) { return false; }/*from w w w . j a v a 2 s . co m*/ } return true; }
From source file:org.gearvrf.controls.util.MathUtils.java
public static float distance(GVRSceneObject obj1, GVRSceneObject obj2) { Vector3D v1 = new Vector3D(obj1.getTransform().getPositionX(), obj1.getTransform().getPositionY(), obj1.getTransform().getPositionZ()); Vector3D v2 = new Vector3D(obj2.getTransform().getPositionX(), obj2.getTransform().getPositionY(), obj2.getTransform().getPositionZ()); return (float) Vector3D.distance(v1, v2); }
From source file:org.gearvrf.controls.util.MathUtils.java
public static float distance(GVRTransform obj1, GVRTransform obj2) { Vector3D v1 = new Vector3D(obj1.getPositionX(), obj1.getPositionY(), obj1.getPositionZ()); Vector3D v2 = new Vector3D(obj2.getPositionX(), obj2.getPositionY(), obj2.getPositionZ()); return (float) Vector3D.distance(v1, v2); }
From source file:org.gearvrf.controls.util.MathUtils.java
public static float distance(GVRTransform obj1, float[] obj2) { Vector3D v1 = new Vector3D(obj1.getPositionX(), obj1.getPositionY(), obj1.getPositionZ()); Vector3D v2 = new Vector3D(obj2[0], obj2[1], obj2[2]); return (float) Vector3D.distance(v1, v2); }
From source file:org.gearvrf.controls.Worm.java
public void checkWormEatingApple(GVRContext gvrContext) { Vector3D wormPosition = new Vector3D(wormParent.getTransform().getPositionX(), head.getParent().getTransform().getPositionY(), wormParent.getTransform().getPositionZ()); for (Apple a : Apple.appleList) { Vector3D applePosition = new Vector3D(a.getTransform().getPositionX(), a.getTransform().getPositionY(), a.getTransform().getPositionZ()); if (Vector3D.distance(applePosition, wormPosition) < DISTANCE_TO_EAT_APPLE) { a.resetPosition(gvrContext); }/*from www. j a v a2s . co m*/ } }
From source file:org.gearvrf.keyboard.spinner.Spinner.java
private void lookAt(GVRSceneObject currentChar) { GVRCameraRig camera = this.getGVRContext().getMainScene().getMainCameraRig(); Vector3D vectorCamera = new Vector3D(camera.getTransform().getPositionX(), camera.getTransform().getPositionY(), camera.getTransform().getPositionZ()); Vector3D vectorKeyboard = new Vector3D(this.getParent().getParent().getTransform().getPositionX(), this.getParent().getParent().getTransform().getPositionY(), this.getParent().getParent().getTransform().getPositionZ()); float newX = currentChar.getTransform().getPositionX() + currentChar.getParent().getTransform().getPositionX(); float newY = 0; float newZ = (float) Vector3D.distance(vectorKeyboard, vectorCamera); Log.d("lookatspinner", "newX " + newX); Log.d("lookatspinner", "newY " + newY); Log.d("lookatspinner", "newZ " + newZ); Vector3D emulatedSpinner = new Vector3D(newX, newY, newZ * -1); Vector3D emulateCam = new Vector3D(0, 0, 0); float angle = Util.getYRotationAngle(emulatedSpinner, emulateCam); Log.d("lookatspinner", "angle " + angle); // angle =(float) (angle*1.1); Log.d("lookatspinner", "angle new" + angle); getTransform().setRotationByAxis(angle, 0, 1, 0); }
From source file:org.orekit.attitudes.AttitudeTest.java
@Test public void testInterpolation() throws OrekitException { Utils.setDataRoot("regular-data"); final double ehMu = 3.9860047e14; final double ae = 6.378137e6; final double c20 = -1.08263e-3; final double c30 = 2.54e-6; final double c40 = 1.62e-6; final double c50 = 2.3e-7; final double c60 = -5.5e-7; final AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(584.); final Vector3D position = new Vector3D(3220103., 69623., 6449822.); final Vector3D velocity = new Vector3D(6414.7, -2006., -3180.); final CircularOrbit initialOrbit = new CircularOrbit(new PVCoordinates(position, velocity), FramesFactory.getEME2000(), date, ehMu); EcksteinHechlerPropagator propagator = new EcksteinHechlerPropagator(initialOrbit, ae, ehMu, c20, c30, c40, c50, c60);/* ww w .ja v a 2 s . c o m*/ OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true)); propagator.setAttitudeProvider(new BodyCenterPointing(initialOrbit.getFrame(), earth)); final Attitude initialAttitude = propagator.propagate(initialOrbit.getDate()).getAttitude(); // set up a 5 points sample List<Attitude> sample = new ArrayList<Attitude>(); for (double dt = 0; dt < 251.0; dt += 60.0) { sample.add(propagator.propagate(date.shiftedBy(dt)).getAttitude()); } // well inside the sample, interpolation should be better than quadratic shift double maxShiftAngleError = 0; double maxInterpolationAngleError = 0; double maxShiftRateError = 0; double maxInterpolationRateError = 0; for (double dt = 0; dt < 240.0; dt += 1.0) { AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt); Attitude propagated = propagator.propagate(t).getAttitude(); double shiftAngleError = Rotation.distance(propagated.getRotation(), initialAttitude.shiftedBy(dt).getRotation()); double interpolationAngleError = Rotation.distance(propagated.getRotation(), initialAttitude.interpolate(t, sample).getRotation()); double shiftRateError = Vector3D.distance(propagated.getSpin(), initialAttitude.shiftedBy(dt).getSpin()); double interpolationRateError = Vector3D.distance(propagated.getSpin(), initialAttitude.interpolate(t, sample).getSpin()); maxShiftAngleError = FastMath.max(maxShiftAngleError, shiftAngleError); maxInterpolationAngleError = FastMath.max(maxInterpolationAngleError, interpolationAngleError); maxShiftRateError = FastMath.max(maxShiftRateError, shiftRateError); maxInterpolationRateError = FastMath.max(maxInterpolationRateError, interpolationRateError); } Assert.assertTrue(maxShiftAngleError > 4.0e-6); Assert.assertTrue(maxInterpolationAngleError < 1.5e-13); Assert.assertTrue(maxShiftRateError > 6.0e-8); Assert.assertTrue(maxInterpolationRateError < 2.5e-14); // past sample end, interpolation error should increase, but still be far better than quadratic shift maxShiftAngleError = 0; maxInterpolationAngleError = 0; maxShiftRateError = 0; maxInterpolationRateError = 0; for (double dt = 250.0; dt < 300.0; dt += 1.0) { AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt); Attitude propagated = propagator.propagate(t).getAttitude(); double shiftAngleError = Rotation.distance(propagated.getRotation(), initialAttitude.shiftedBy(dt).getRotation()); double interpolationAngleError = Rotation.distance(propagated.getRotation(), initialAttitude.interpolate(t, sample).getRotation()); double shiftRateError = Vector3D.distance(propagated.getSpin(), initialAttitude.shiftedBy(dt).getSpin()); double interpolationRateError = Vector3D.distance(propagated.getSpin(), initialAttitude.interpolate(t, sample).getSpin()); maxShiftAngleError = FastMath.max(maxShiftAngleError, shiftAngleError); maxInterpolationAngleError = FastMath.max(maxInterpolationAngleError, interpolationAngleError); maxShiftRateError = FastMath.max(maxShiftRateError, shiftRateError); maxInterpolationRateError = FastMath.max(maxInterpolationRateError, interpolationRateError); } Assert.assertTrue(maxShiftAngleError > 9.0e-6); Assert.assertTrue(maxInterpolationAngleError < 6.0e-11); Assert.assertTrue(maxShiftRateError > 9.0e-8); Assert.assertTrue(maxInterpolationRateError < 4.0e-12); }
From source file:org.orekit.attitudes.NadirPointingTest.java
/** Test the derivatives of the sliding target *//*from w w w. java 2 s . co m*/ @Test public void testSlidingDerivatives() throws OrekitException { // Elliptic earth shape OneAxisEllipsoid earthShape = new OneAxisEllipsoid(6378136.460, 1 / 298.257222101, itrf); // Create earth center pointing attitude provider NadirPointing nadirAttitudeLaw = new NadirPointing(FramesFactory.getEME2000(), earthShape); // Satellite on any position CircularOrbit circ = new CircularOrbit(7178000.0, 1.e-5, 0., FastMath.toRadians(50.), 0., FastMath.toRadians(90.), PositionAngle.TRUE, FramesFactory.getEME2000(), date, mu); List<TimeStampedPVCoordinates> sample = new ArrayList<TimeStampedPVCoordinates>(); for (double dt = -0.1; dt < 0.1; dt += 0.05) { Orbit o = circ.shiftedBy(dt); sample.add(nadirAttitudeLaw.getTargetPV(o, o.getDate(), o.getFrame())); } TimeStampedPVCoordinates reference = TimeStampedPVCoordinates.interpolate(circ.getDate(), CartesianDerivativesFilter.USE_P, sample); TimeStampedPVCoordinates target = nadirAttitudeLaw.getTargetPV(circ, circ.getDate(), circ.getFrame()); Assert.assertEquals(0.0, Vector3D.distance(reference.getPosition(), target.getPosition()), 1.0e-15 * reference.getPosition().getNorm()); Assert.assertEquals(0.0, Vector3D.distance(reference.getVelocity(), target.getVelocity()), 3.0e-11 * reference.getVelocity().getNorm()); Assert.assertEquals(0.0, Vector3D.distance(reference.getAcceleration(), target.getAcceleration()), 1.0e-5 * reference.getAcceleration().getNorm()); }