List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D
public Vector3D(double a, Vector3D u)
From source file:jtrace.object.Cube.java
/** * Create cube with unit side./*from w ww. j a va2 s .c om*/ */ public Cube() { super(); normals = new Ray[6]; for (int i = 0; i < 6; i++) normals[i] = new Ray(); normals[0].origin = new Vector3D(0.5, Vector3D.PLUS_I); normals[1].origin = new Vector3D(0.5, Vector3D.MINUS_I); normals[2].origin = new Vector3D(0.5, Vector3D.PLUS_J); normals[3].origin = new Vector3D(0.5, Vector3D.MINUS_J); normals[4].origin = new Vector3D(0.5, Vector3D.PLUS_K); normals[5].origin = new Vector3D(0.5, Vector3D.MINUS_K); normals[0].direction = Vector3D.PLUS_I; normals[1].direction = Vector3D.MINUS_I; normals[2].direction = Vector3D.PLUS_J; normals[3].direction = Vector3D.MINUS_J; normals[4].direction = Vector3D.PLUS_K; normals[5].direction = Vector3D.MINUS_K; }
From source file:jtrace.object.Plane.java
@Override public List<Vector3D[]> getWireFrameObjectFrame() { List<Vector3D[]> edges = new ArrayList<>(); Vector3D A = new Vector3D(0.5, planeNorth).add(0.5, planeEast); Vector3D B = new Vector3D(0.5, planeNorth).subtract(0.5, planeEast); Vector3D C = new Vector3D(-0.5, planeNorth).subtract(0.5, planeEast); Vector3D D = new Vector3D(-0.5, planeNorth).add(0.5, planeEast); Vector3D[] edge1 = { A, B };/*from w w w . j a v a 2 s. c om*/ Vector3D[] edge2 = { B, C }; Vector3D[] edge3 = { C, D }; Vector3D[] edge4 = { D, A }; edges.add(edge1); edges.add(edge2); edges.add(edge3); edges.add(edge4); return edges; }
From source file:jtrace.Camera.java
/** * Obtain camera ray to trace through scene. * //w w w .ja v a 2 s . c om * @param width Width of image in pixels. * @param height Height of image in pixels. * @param x X-coordinate of pixel to trace. * @param y Y-coordinate of pixel to trace. * @return */ public Ray getRay(int width, int height, int x, int y) { // Determine angles in each direction. Note the negative // in the expression for the vertical angle - this flips // the image in that direction to account for the matrix // coordinate scheme used in images. double tanThetaUp = -fovUp * (y / (double) height - 0.5); double tanThetaRight = fovRight * (x / (double) width - 0.5); Vector3D raydir = new Vector3D(1.0, direction); raydir = raydir.add(tanThetaUp, up); raydir = raydir.add(tanThetaRight, right); return new Ray(location, raydir.normalize()); }
From source file:jtrace.object.Cube.java
@Override public List<Vector3D[]> getWireFrameObjectFrame() { Vector3D[] vertices = new Vector3D[8]; vertices[0] = new Vector3D(0.5, Vector3D.PLUS_K).add(0.5, Vector3D.PLUS_I).add(0.5, Vector3D.PLUS_J); vertices[1] = new Vector3D(0.5, Vector3D.PLUS_K).subtract(0.5, Vector3D.PLUS_I).add(0.5, Vector3D.PLUS_J); vertices[2] = new Vector3D(0.5, Vector3D.PLUS_K).subtract(0.5, Vector3D.PLUS_I).subtract(0.5, Vector3D.PLUS_J);/* w ww. j a va 2s . c o m*/ vertices[3] = new Vector3D(0.5, Vector3D.PLUS_K).add(0.5, Vector3D.PLUS_I).subtract(0.5, Vector3D.PLUS_J); vertices[4] = new Vector3D(-0.5, Vector3D.PLUS_K).add(0.5, Vector3D.PLUS_I).add(0.5, Vector3D.PLUS_J); vertices[5] = new Vector3D(-0.5, Vector3D.PLUS_K).subtract(0.5, Vector3D.PLUS_I).add(0.5, Vector3D.PLUS_J); vertices[6] = new Vector3D(-0.5, Vector3D.PLUS_K).subtract(0.5, Vector3D.PLUS_I).subtract(0.5, Vector3D.PLUS_J); vertices[7] = new Vector3D(-0.5, Vector3D.PLUS_K).add(0.5, Vector3D.PLUS_I).subtract(0.5, Vector3D.PLUS_J); Vector3D[][] edges = { { vertices[0], vertices[1] }, { vertices[1], vertices[2] }, { vertices[2], vertices[3] }, { vertices[3], vertices[0] }, { vertices[4], vertices[5] }, { vertices[5], vertices[6] }, { vertices[6], vertices[7] }, { vertices[7], vertices[4] }, { vertices[0], vertices[4] }, { vertices[1], vertices[5] }, { vertices[2], vertices[6] }, { vertices[3], vertices[7] } }; return Arrays.asList(edges); }
From source file:org.orekit.attitudes.AttitudeTest.java
@Test public void testShift() throws OrekitException { double rate = 2 * FastMath.PI / (12 * 60); Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(), Rotation.IDENTITY, new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO); Assert.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-10); double dt = 10.0; double alpha = rate * dt; Attitude shifted = attitude.shiftedBy(dt); Assert.assertEquals(rate, shifted.getSpin().getNorm(), 1.0e-10); Assert.assertEquals(alpha, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-10); Vector3D xSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_I); Assert.assertEquals(0.0, xSat.subtract(new Vector3D(FastMath.cos(alpha), FastMath.sin(alpha), 0)).getNorm(), 1.0e-10);/*from w w w . j a va2 s. co m*/ Vector3D ySat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_J); Assert.assertEquals(0.0, ySat.subtract(new Vector3D(-FastMath.sin(alpha), FastMath.cos(alpha), 0)).getNorm(), 1.0e-10); Vector3D zSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K); Assert.assertEquals(0.0, zSat.subtract(Vector3D.PLUS_K).getNorm(), 1.0e-10); }
From source file:org.orekit.attitudes.AttitudeTest.java
@Test public void testSpin() throws OrekitException { double rate = 2 * FastMath.PI / (12 * 60); Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(), new Rotation(0.48, 0.64, 0.36, 0.48, false), new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO); Assert.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-10); double dt = 10.0; Attitude shifted = attitude.shiftedBy(dt); Assert.assertEquals(rate, shifted.getSpin().getNorm(), 1.0e-10); Assert.assertEquals(rate * dt, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-10); Vector3D shiftedX = shifted.getRotation().applyInverseTo(Vector3D.PLUS_I); Vector3D shiftedY = shifted.getRotation().applyInverseTo(Vector3D.PLUS_J); Vector3D shiftedZ = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K); Vector3D originalX = attitude.getRotation().applyInverseTo(Vector3D.PLUS_I); Vector3D originalY = attitude.getRotation().applyInverseTo(Vector3D.PLUS_J); Vector3D originalZ = attitude.getRotation().applyInverseTo(Vector3D.PLUS_K); Assert.assertEquals(FastMath.cos(rate * dt), Vector3D.dotProduct(shiftedX, originalX), 1.0e-10); Assert.assertEquals(FastMath.sin(rate * dt), Vector3D.dotProduct(shiftedX, originalY), 1.0e-10); Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedX, originalZ), 1.0e-10); Assert.assertEquals(-FastMath.sin(rate * dt), Vector3D.dotProduct(shiftedY, originalX), 1.0e-10); Assert.assertEquals(FastMath.cos(rate * dt), Vector3D.dotProduct(shiftedY, originalY), 1.0e-10); Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedY, originalZ), 1.0e-10); Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedZ, originalX), 1.0e-10); Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedZ, originalY), 1.0e-10); Assert.assertEquals(1.0, Vector3D.dotProduct(shiftedZ, originalZ), 1.0e-10); Vector3D forward = AngularCoordinates.estimateRate(attitude.getRotation(), shifted.getRotation(), dt); Assert.assertEquals(0.0, forward.subtract(attitude.getSpin()).getNorm(), 1.0e-10); Vector3D reversed = AngularCoordinates.estimateRate(shifted.getRotation(), attitude.getRotation(), dt); Assert.assertEquals(0.0, reversed.add(attitude.getSpin()).getNorm(), 1.0e-10); }
From source file:org.orekit.attitudes.BodyCenterPointing.java
/** {@inheritDoc} */ @Override/*ww w. j a v a2 s . c om*/ protected TimeStampedPVCoordinates getTargetPV(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame) throws OrekitException { // spacecraft coordinates in body frame final TimeStampedPVCoordinates scInBodyFrame = pvProv.getPVCoordinates(date, getBodyFrame()); // central projection to ground (NOT the classical nadir point) final double u = scInBodyFrame.getPosition().getX() / ellipsoid.getA(); final double v = scInBodyFrame.getPosition().getY() / ellipsoid.getB(); final double w = scInBodyFrame.getPosition().getZ() / ellipsoid.getC(); final double d2 = u * u + v * v + w * w; final double d = FastMath.sqrt(d2); final double ratio = 1.0 / d; final Vector3D projectedP = new Vector3D(ratio, scInBodyFrame.getPosition()); // velocity final double uDot = scInBodyFrame.getVelocity().getX() / ellipsoid.getA(); final double vDot = scInBodyFrame.getVelocity().getY() / ellipsoid.getB(); final double wDot = scInBodyFrame.getVelocity().getZ() / ellipsoid.getC(); final double dDot = MathArrays.linearCombination(u, uDot, v, vDot, w, wDot) / d; final double ratioDot = -dDot / d2; final Vector3D projectedV = new Vector3D(ratio, scInBodyFrame.getVelocity(), ratioDot, scInBodyFrame.getPosition()); // acceleration final double uDotDot = scInBodyFrame.getAcceleration().getX() / ellipsoid.getA(); final double vDotDot = scInBodyFrame.getAcceleration().getY() / ellipsoid.getB(); final double wDotDot = scInBodyFrame.getAcceleration().getZ() / ellipsoid.getC(); final double dDotDot = (MathArrays.linearCombination(u, uDotDot, v, vDotDot, w, wDotDot) + uDot * uDot + vDot * vDot + wDot * wDot - dDot * dDot) / d; final double ratioDotDot = (2 * dDot * dDot - d * dDotDot) / (d * d2); final Vector3D projectedA = new Vector3D(ratio, scInBodyFrame.getAcceleration(), 2 * ratioDot, scInBodyFrame.getVelocity(), ratioDotDot, scInBodyFrame.getPosition()); final TimeStampedPVCoordinates projected = new TimeStampedPVCoordinates(date, projectedP, projectedV, projectedA); return getBodyFrame().getTransformTo(frame, date).transformPVCoordinates(projected); }
From source file:org.orekit.attitudes.CelestialBodyPointed.java
/** {@inheritDoc} */ public Attitude getAttitude(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame) throws OrekitException { final PVCoordinates satPV = pvProv.getPVCoordinates(date, celestialFrame); // compute celestial references at the specified date final PVCoordinates bodyPV = pointedBody.getPVCoordinates(date, celestialFrame); final PVCoordinates pointing = new PVCoordinates(satPV, bodyPV); final Vector3D pointingP = pointing.getPosition(); final double r2 = Vector3D.dotProduct(pointingP, pointingP); // evaluate instant rotation axis due to sat and body motion only (no phasing yet) final Vector3D rotAxisCel = new Vector3D(1 / r2, Vector3D.crossProduct(pointingP, pointing.getVelocity())); // fix instant rotation to take phasing constraint into account // (adding a rotation around pointing axis ensuring the motion of the phasing axis // is constrained in the pointing-phasing plane) final Vector3D v1 = Vector3D.crossProduct(rotAxisCel, phasingCel); final Vector3D v2 = Vector3D.crossProduct(pointingP, phasingCel); final double compensation = -Vector3D.dotProduct(v1, v2) / v2.getNormSq(); final Vector3D phasedRotAxisCel = new Vector3D(1.0, rotAxisCel, compensation, pointingP); // compute transform from celestial frame to satellite frame final Rotation celToSatRotation = new Rotation(pointingP, phasingCel, pointingSat, phasingSat); // build transform combining rotation and instant rotation axis Transform transform = new Transform(date, celToSatRotation, celToSatRotation.applyTo(phasedRotAxisCel)); if (frame != celestialFrame) { // prepend transform from specified frame to celestial frame transform = new Transform(date, frame.getTransformTo(celestialFrame, date), transform); }/*from w w w. j a v a2s . c o m*/ // build the attitude return new Attitude(date, frame, transform.getRotation(), transform.getRotationRate(), transform.getRotationAcceleration()); }
From source file:org.orekit.attitudes.FixedRateTest.java
@Test public void testNonZeroRate() throws OrekitException { final AbsoluteDate date = new AbsoluteDate(new DateComponents(2004, 3, 2), new TimeComponents(13, 17, 7.865), TimeScalesFactory.getUTC()); final double rate = 2 * FastMath.PI / (12 * 60); final Frame frame = FramesFactory.getEME2000(); FixedRate law = new FixedRate(new Attitude(date, frame, new Rotation(0.48, 0.64, 0.36, 0.48, false), new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO)); PVCoordinates pv = new PVCoordinates(new Vector3D(28812595.32012577, 5948437.4640250085, 0), new Vector3D(0, 0, 3680.853673522056)); Orbit orbit = new KeplerianOrbit(pv, FramesFactory.getEME2000(), date, 3.986004415e14); Rotation attitude0 = law.getAttitude(orbit, date, frame).getRotation(); Assert.assertEquals(0, Rotation.distance(attitude0, law.getReferenceAttitude().getRotation()), 1.0e-10); Rotation attitude1 = law.getAttitude(orbit.shiftedBy(10.0), date.shiftedBy(10.0), frame).getRotation(); Assert.assertEquals(10 * rate, Rotation.distance(attitude1, law.getReferenceAttitude().getRotation()), 1.0e-10);//from w w w .ja v a 2s .c om Rotation attitude2 = law.getAttitude(orbit.shiftedBy(-20.0), date.shiftedBy(-20.0), frame).getRotation(); Assert.assertEquals(20 * rate, Rotation.distance(attitude2, law.getReferenceAttitude().getRotation()), 1.0e-10); Assert.assertEquals(30 * rate, Rotation.distance(attitude2, attitude1), 1.0e-10); Rotation attitude3 = law.getAttitude(orbit.shiftedBy(0.0), date, frame).getRotation(); Assert.assertEquals(0, Rotation.distance(attitude3, law.getReferenceAttitude().getRotation()), 1.0e-10); }
From source file:org.orekit.attitudes.FixedRateTest.java
@Test public void testSpin() throws OrekitException { AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789), TimeScalesFactory.getUTC()); final double rate = 2 * FastMath.PI / (12 * 60); AttitudeProvider law = new FixedRate(new Attitude(date, FramesFactory.getEME2000(), new Rotation(0.48, 0.64, 0.36, 0.48, false), new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO)); KeplerianOrbit orbit = new KeplerianOrbit(7178000.0, 1.e-4, FastMath.toRadians(50.), FastMath.toRadians(10.), FastMath.toRadians(20.), FastMath.toRadians(30.), PositionAngle.MEAN, FramesFactory.getEME2000(), date, 3.986004415e14); Propagator propagator = new KeplerianPropagator(orbit, law); double h = 0.01; SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h)); SpacecraftState s0 = propagator.propagate(date); SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h)); // check spin is consistent with attitude evolution double errorAngleMinus = Rotation.distance(sMinus.shiftedBy(h).getAttitude().getRotation(), s0.getAttitude().getRotation()); double evolutionAngleMinus = Rotation.distance(sMinus.getAttitude().getRotation(), s0.getAttitude().getRotation()); Assert.assertEquals(0.0, errorAngleMinus, 1.0e-6 * evolutionAngleMinus); double errorAnglePlus = Rotation.distance(s0.getAttitude().getRotation(), sPlus.shiftedBy(-h).getAttitude().getRotation()); double evolutionAnglePlus = Rotation.distance(s0.getAttitude().getRotation(), sPlus.getAttitude().getRotation()); Assert.assertEquals(0.0, errorAnglePlus, 1.0e-6 * evolutionAnglePlus); Vector3D spin0 = s0.getAttitude().getSpin(); Vector3D reference = AngularCoordinates.estimateRate(sMinus.getAttitude().getRotation(), sPlus.getAttitude().getRotation(), 2 * h); Assert.assertEquals(0.0, spin0.subtract(reference).getNorm(), 1.0e-14); }