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.hbird.business.navigation.processors.orekit.EclipseCalculator.java
public static double calculateEclipse(SpacecraftState s) throws OrekitException { double occultedRadius = Constants.EQUATORIAL_RADIUS_OF_SUN; double occultingRadius = Constants.EQUATORIAL_RADIUS_OF_THE_EARTH; final Vector3D pted = CelestialBodyFactory.getSun().getPVCoordinates(s.getDate(), s.getFrame()) .getPosition();//w w w .ja va 2 s .c o m final Vector3D ping = CelestialBodyFactory.getEarth().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 = Math.asin(occultedRadius / ps.getNorm()); final double ro = Math.asin(occultingRadius / po.getNorm()); return angle - ro - rs; }
From source file:org.jtrfp.trcl.beh.ProjectileBehavior.java
public void reset(Vector3D heading, double speed) { this.speed = speed; honingTarget = null;//w w w. j a va2s. co m final WorldObject parent = getParent(); final Behavior beh = parent.getBehavior(); parent.setHeading(heading); if (honing) { // Find target WorldObject closestObject = null; double closestDistance = Double.POSITIVE_INFINITY; List<WorldObject> possibleTargets = getParent().getTr().getCollisionManager() .getCurrentlyActiveCollisionList(); synchronized (possibleTargets) { for (WorldObject possibleTarget : possibleTargets) { if (possibleTarget instanceof DEFObject) { DEFObject possibleDEFTarget = (DEFObject) possibleTarget; if (!possibleDEFTarget.isIgnoringProjectiles() && !possibleDEFTarget.isRuin()) { final Vector3D targetPos = new Vector3D(possibleTarget.getPositionWithOffset()); final Vector3D delta = targetPos.subtract(new Vector3D(getParent().getPosition())); final double dist = delta.getNorm(); final Vector3D proposedHeading = delta.normalize(); final Vector3D headingDelta = getParent().getHeading().subtract(proposedHeading); final double compositeHeadingDelta = headingDelta.getNorm(); if (compositeHeadingDelta < .5) { final double compositeDistance = dist; if (compositeDistance < closestDistance) { closestDistance = dist; closestObject = possibleTarget; parent.setHeading(proposedHeading); getParent().getBehavior().probeForBehavior(AutoLeveling.class) .setLevelingVector(heading); } // end if(closesObject) } // end if(headingDelta<1) } // end if(isIgnoringProjectiles) } // end if(DEFObject) } } // end for(WorldObject others) honingTarget = new WeakReference<WorldObject>(closestObject); // if(honingTarget==null){ getParent().getBehavior().probeForBehavior(AutoLeveling.class).setLevelingVector(heading); movesByVelocity.setVelocity(getParent().getHeading().scalarMultiply(speed)); // }//end if(honingTarget==null) } // end if(honingTarget) beh.probeForBehavior(LimitedLifeSpan.class).reset(LIFESPAN_MILLIS); beh.probeForBehavior(DeathBehavior.class).reset(); }
From source file:org.jtrfp.trcl.LineSegment.java
public static Triangle[] buildTriPipe(Vector3D start, Vector3D end, TextureDescription texture, int thickness, Triangle[] dest, int destOffset) { Rotation rot = new Rotation(Vector3D.PLUS_K, end.subtract(start).normalize()); final double len = start.distance(end); // Start/* ww w . j a v a 2s .c o m*/ Vector3D sbl = new Vector3D(-thickness, -thickness, 0);// bottom left Vector3D sbr = new Vector3D(thickness, -thickness, 0);// bottom right Vector3D stp = new Vector3D(0, thickness, 0); // End Vector3D ebl = new Vector3D(-thickness, -thickness, len); Vector3D ebr = new Vector3D(thickness, -thickness, len); Vector3D etp = new Vector3D(0, thickness, len); Vector3D cl = new Vector3D(-1, 1, 0).normalize(); Vector3D cr = new Vector3D(1, 1, 0).normalize(); Vector3D cb = new Vector3D(0, -1, 0); cl = rot.applyTo(cl); cr = rot.applyTo(cr); cb = rot.applyTo(cb); sbl = rot.applyTo(sbl).add(start); sbr = rot.applyTo(sbr).add(start); stp = rot.applyTo(stp).add(start); ebl = rot.applyTo(ebl).add(start); ebr = rot.applyTo(ebr).add(start); etp = rot.applyTo(etp).add(start); final double u[] = { 0, 1, 1, 0 }; final double v[] = { 1, 1, 0, 0 }; // TOP LEFT Triangle.quad2Triangles(new double[] { sbl.getX(), stp.getX(), etp.getX(), ebl.getX() }, new double[] { sbl.getY(), stp.getY(), etp.getY(), ebl.getY() }, new double[] { sbl.getZ(), stp.getZ(), etp.getZ(), ebl.getZ() }, u, v, texture, RenderMode.STATIC, false, cl, dest, destOffset, "LineSegment.topLeft"); // TOP RIGHT Triangle.quad2Triangles(new double[] { sbr.getX(), stp.getX(), etp.getX(), ebr.getX() }, new double[] { sbr.getY(), stp.getY(), etp.getY(), ebr.getY() }, new double[] { sbr.getZ(), stp.getZ(), etp.getZ(), ebr.getZ() }, u, v, texture, RenderMode.STATIC, false, cr, dest, destOffset + 2, "LineSegment.topRight"); // BOTTOM Triangle.quad2Triangles(new double[] { sbl.getX(), sbr.getX(), ebr.getX(), ebl.getX() }, new double[] { sbl.getY(), sbr.getY(), ebr.getY(), ebl.getY() }, new double[] { sbr.getZ(), sbr.getZ(), ebr.getZ(), ebl.getZ() }, u, v, texture, RenderMode.STATIC, false, cb, dest, destOffset + 4, "LineSegment.bottom"); return dest; }
From source file:org.jtrfp.trcl.SpacePartitioningGrid.java
public void cubesWithinRadiusOf(Vector3D centerInWorldUnits, Submitter<List<E>> submitter) { recursiveAlwaysVisibleGridCubeSubmit(submitter); final double[] startPoint = centerInWorldUnits .subtract(new Vector3D(radiusInWorldUnits, radiusInWorldUnits, radiusInWorldUnits)).toArray(); int startRaw = worldSpaceRasterizer.adapt(new Vector3D(startPoint[0], startPoint[1], startPoint[2])); final int zEnd = startRaw + getSquaresX() * getSquaresY() * rawDiaZ + (rawDiaY * getSquaresX()) + (rawDiaX); for (int point = startRaw; point < zEnd; point += zProgression) {//Z final int yEnd = point + getSquaresX() * rawDiaY; for (; point < yEnd; point += yProgression) {//Y final int xEnd = point + rawDiaX; for (; point < xEnd; point += xProgression) {//X final int wrappedPoint = point % rolloverPoint; recursiveGridCubeSubmit(submitter, wrappedPoint); } //end for(X) } //end for(Y) } //end for(Z) }
From source file:org.jtrfp.trcl.SpacePartitioningGrid.java
@SuppressWarnings("unchecked") public void itemsWithinRadiusOf(Vector3D centerInWorldUnits, Submitter<E> submitter) { recursiveAlwaysVisibleSubmit(submitter); final double[] startPoint = centerInWorldUnits .subtract(new Vector3D(radiusInWorldUnits, radiusInWorldUnits, radiusInWorldUnits)).toArray(); int startRaw = worldSpaceRasterizer.adapt(new Vector3D(startPoint[0], startPoint[1], startPoint[2])); final int zEnd = startRaw + getSquaresX() * getSquaresY() * rawDiaZ + (rawDiaY * getSquaresX()) + (rawDiaX); for (int point = startRaw; point < zEnd; point += zProgression) {//Z final int yEnd = point + getSquaresX() * rawDiaY; for (; point < yEnd; point += yProgression) {//Y final int xEnd = point + rawDiaX; for (; point < xEnd; point += xProgression) {//X final int wrappedPoint = point % rolloverPoint; recursiveBlockSubmit(submitter, wrappedPoint); } //end for(X) } //end for(Y) } //end for(Z) }
From source file:org.jtrfp.trcl.Tunnel.java
/** * Tunnel items: FANBODY.BIN - fan IRIS.BIN - animated iris BEAM.BIN / * PIPE.BIN JAW1.BIN (right) JAW2.BIN (left) - jaws ELECTRI[0-3].RAW - force * field TP1.RAW - good enough for blastable door? * // w ww . ja v a2s .c om * @throws IOException * @throws FileLoadException * * */ private void installObstacles(Segment s, ColorPaletteVectorList tunnelColorPalette, ColorPaletteVectorList ESTuTvPalette, TextureDescription[] tunnelTexturePalette, Vector3D heading, Vector3D top, Vector3D wPos, double width, double height, TR tr) throws IllegalAccessException, FileLoadException, IOException { final ColorPaletteVectorList palette = tr.getGlobalPaletteVL(); Obstacle obs = s.getObstacle(); WorldObject wo; Model m; switch (obs) { case none0: break; case doorway: { m = Model.buildCube(tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, .5, .5, 1, 1, tr); wo = new WorldObject(tr, m); wo.setPosition(wPos.toArray()); wo.setHeading(heading); wo.setTop(top); add(wo); break; } case closedDoor: { BarrierCube bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, .5, .5, 0, 1, false); bc.setPosition(wPos.toArray()); bc.setHeading(heading); bc.addBehavior(new DamageableBehavior().setHealth(4096)); bc.addBehavior(new ExplodesOnDeath(ExplosionType.Blast)); bc.addBehavior(new DeathBehavior()); bc.addBehavior(new DebrisOnDeathBehavior()); bc.addBehavior(new DestructibleWallBehavior()); bc.setTop(top); add(bc); break; } case blownOpenDoor://TODO: This is not displaying alpha BarrierCube bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, .5, .5, 1, 1, true); bc.setPosition(wPos.toArray()); bc.setHeading(heading); bc.setTop(top); add(bc); break; case movingWallLeft: { Vector3D endPos = wPos.add(heading.crossProduct(top).scalarMultiply(tunnelDia)); bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false); bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos)); bc.setPosition(wPos.toArray()); bc.setHeading(heading); bc.setTop(top); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); break; } case movingWallRight: { Vector3D endPos = wPos.subtract(heading.crossProduct(top).scalarMultiply(tunnelDia)); bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false); bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos)); bc.addBehavior(new CubeCollisionBehavior(bc)); bc.setPosition(wPos.toArray()); bc.setHeading(heading); bc.setTop(top); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); break; } case movingWallDown: { Vector3D endPos = wPos.subtract(top.scalarMultiply(tunnelDia)); bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false); bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos)); bc.setPosition(wPos.toArray()); bc.setHeading(heading); bc.setTop(top); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); break; } case movingWallUp: { Vector3D endPos = wPos.add(top.scalarMultiply(tunnelDia)); bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false); bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos)); bc.setPosition(wPos.toArray()); bc.setHeading(heading); bc.setTop(top); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); break; } case wallLeftSTUB: case wallLeft: bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0., tunnelDia / 2., 0 }, false); bc.setPosition(wPos.toArray()); bc.setHeading(heading); bc.setTop(top); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); break; case wallRightSTUB: case wallRight: bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { tunnelDia, tunnelDia / 2., 0 }, false); bc.setPosition(wPos.toArray()); bc.setHeading(heading); bc.setTop(top); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); break; case wallDownSTUB: case wallDown: bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false); bc.setPosition((wPos.subtract(top.scalarMultiply(tunnelDia / 2))).toArray()); bc.setHeading(heading); bc.setTop(top); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); break; case wallUpSTUB: case wallUp: bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false); bc.setPosition((wPos.add(top.scalarMultiply(tunnelDia / 2))).toArray()); bc.setHeading(heading); bc.setTop(top); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); break; case rotatingHalfWall: { final double rotPeriod = 32768. / (double) s.getRotationSpeed(); final boolean rotate = !Double.isInfinite(rotPeriod); bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0, tunnelDia / 2., 0 }, false); if (rotate) { bc.addBehavior(new RotatingObjectBehavior(heading, heading, top, (int) (rotPeriod * 1000.), 0)); bc.setTop(top); } else bc.setTop(new Rotation(heading, Math.PI + Math.PI / 2).applyTo(top)); bc.setPosition(wPos.toArray()); bc.setHeading(heading); bc.setTop(top); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); break; } case rotating34Wall: { final double rotPeriod = 32768. / (double) s.getRotationSpeed(); final boolean rotate = !Double.isInfinite(rotPeriod); bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0, tunnelDia / 2., 10 }, false); if (rotate) { bc.addBehavior( new RotatingObjectBehavior(heading, heading, top, (int) (rotPeriod * 1000.), Math.PI)); bc.setTop(top); } else bc.setTop(new Rotation(heading, Math.PI + Math.PI / 2).applyTo(top)); bc.setPosition(wPos.toArray()); bc.setHeading(heading); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness, tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0, tunnelDia / 2., 0 }, false); if (rotate) { bc.addBehavior(new RotatingObjectBehavior(heading, heading, top, (int) (rotPeriod * 1000.), Math.PI + Math.PI / 2)); bc.setTop(top); } else bc.setTop(new Rotation(heading, Math.PI * 2).applyTo(top)); bc.setPosition((wPos.add(new Vector3D(100, 0, 0))).toArray()); bc.setHeading(heading); bc.addBehavior(new CubeCollisionBehavior(bc)); add(bc); break; } case fan: wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BLADE.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 28, false, palette, ESTuTvPalette)); wo.setPosition(wPos.toArray()); wo.setHeading(heading); wo.setTop(top); wo.addBehavior(new CubeCollisionBehavior(wo)); wo.addBehavior(new RotatingObjectBehavior(heading, heading, top, 6000, Math.random() * 2 * Math.PI)); add(wo); wo = new WorldObject(tr, tr.getResourceManager().getBINModel("FANBODY.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 28, false, palette, null));//No ESTuTv for fan for now. wo.setPosition(wPos.toArray()); wo.setHeading(heading); wo.setTop(top); wo.addBehavior(new CubeCollisionBehavior(wo)); add(wo); break; case jawsVertical: // Up jaw wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW2.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette)); wo.addBehavior(new ShiftingObjectBehavior(3000, wPos, wPos.add(top.scalarMultiply(tunnelDia / 2)))); wo.addBehavior(new CubeCollisionBehavior(wo)); wo.setPosition(wPos.toArray()); wo.setHeading(heading); wo.setTop(heading.crossProduct(top).negate()); wo.addBehavior(new CubeCollisionBehavior(wo)); add(wo); // Down jaw wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW1.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette)); wo.addBehavior( new ShiftingObjectBehavior(3000, wPos, wPos.subtract(top.scalarMultiply(tunnelDia / 2)))); wo.setPosition(wPos.toArray()); wo.setHeading(heading); wo.setTop(heading.crossProduct(top).negate()); wo.addBehavior(new CubeCollisionBehavior(wo)); add(wo); break; case jawsHorizontal: // Left jaw wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW2.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette)); wo.addBehavior(new ShiftingObjectBehavior(3000, wPos, wPos.add(heading.crossProduct(top).scalarMultiply(tunnelDia / 2)))); wo.setPosition(wPos.toArray()); wo.setHeading(heading); wo.setTop(top); wo.addBehavior(new CubeCollisionBehavior(wo)); add(wo); // Right jaw wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW1.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette)); wo.addBehavior(new ShiftingObjectBehavior(3000, wPos, wPos.subtract(heading.crossProduct(top).scalarMultiply(tunnelDia / 2)))); wo.setPosition(wPos.toArray()); wo.setHeading(heading); wo.setTop(top); wo.addBehavior(new CubeCollisionBehavior(wo)); add(wo); break; case metalBeamUp: wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette)); wo.setPosition(wPos.add(new Vector3D(0, tunnelDia / 6, 0)).toArray()); wo.setHeading(heading); wo.setTop(top); wo.addBehavior(new CubeCollisionBehavior(wo)); add(wo); break; case metalBeamDown: wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette)); wo.setPosition(wPos.add(new Vector3D(0, -tunnelDia / 6, 0)).toArray()); wo.setHeading(heading); wo.setTop(top); wo.addBehavior(new CubeCollisionBehavior(wo)); add(wo); break; case metalBeamLeft: wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette)); wo.setPosition(wPos.add(new Vector3D(-tunnelDia / 6, 0, 0)).toArray()); wo.setHeading(heading); wo.setTop(top.crossProduct(heading)); wo.addBehavior(new CubeCollisionBehavior(wo)); add(wo); break; case metalBeamRight: wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette)); wo.setPosition(wPos.add(new Vector3D(tunnelDia / 6, 0, 0)).toArray()); wo.setHeading(heading); wo.setTop(top.crossProduct(heading)); wo.addBehavior(new CubeCollisionBehavior(wo)); add(wo); break; case forceField: { //ELECTRI[0-3].RAW final ForceField ff = new ForceField(tr, (int) tunnelDia, (int) wallThickness); ff.setPosition(wPos.toArray()); ff.setHeading(heading); ff.setTop(top); add(ff); break; } // Invisible walls, as far as I know, are never used. // This makes sense: There is nothing fun about trying to get through a // tunnel and crashing into invisible walls. case invisibleWallUp:// TODO break; case invisibleWallDown:// TODO break; case invisibleWallLeft:// TODO break; case invisibleWallRight:// TODO break; case iris: { wo = new WorldObject(tr, tr.getResourceManager().getBINModel("IRIS.BIN", tunnelTexturePalette[s.getObstacleTextureIndex()], 4 * 256, false, palette, ESTuTvPalette)); final Model mod = wo.getModel(); wo.addBehavior(new IrisBehavior(new Sequencer(mod.getFrameDelayInMillis(), 2, true), width)); wo.setPosition(wPos.toArray()); wo.setHeading(heading); wo.setTop(top); wo.addBehavior(new CubeCollisionBehavior(wo)); add(wo); break; } }// end switch(obstruction) }
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 ww w. ja v a 2 s .c o 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.BodyCenterPointingTest.java
@Test public void testSpin() 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 .j a v a 2s. com*/ propagator.setAttitudeProvider(earthCenterAttitudeLaw); double h = 0.01; SpacecraftState s0 = propagator.propagate(date); SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h)); 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.assertTrue(spin0.getNorm() > 1.0e-3); Assert.assertEquals(0.0, spin0.subtract(reference).getNorm(), 1.0e-13); }
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); }