Example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D add

List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D add

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D add.

Prototype

public Vector3D add(final Vector<Euclidean3D> v) 

Source Link

Usage

From source file:org.jtrfp.trcl.obj.ExplosionSystem.java

public Explosion triggerExplosion(Vector3D loc, ExplosionType type) {
    if (!isNewExplosionFeasible(loc, type))
        return null;
    indices[type.ordinal()]++;/*from w  ww . j a v a 2s  . c  om*/
    indices[type.ordinal()] %= MAX_EXPLOSIONS_PER_POOL;
    Explosion result = allExplosions[type.ordinal()][indices[type.ordinal()]];
    result.destroy();
    result.reset();
    result.setPosition(loc.getX(), loc.getY(), loc.getZ());
    result.notifyPositionChange();
    final SmokeSystem sf = tr.getResourceManager().getSmokeSystem();
    final int NUM_PUFFS = 1;

    for (int i = 0; i < NUM_PUFFS; i++) {
        sf.triggerSmoke(loc.add(new Vector3D(Math.random() * 10000 - 5000, Math.random() * 10000 - 5000,
                Math.random() * 10000 - 5000)), SmokeType.Puff);
    } //end for(i)

    add(result);
    return result;
}

From source file:org.jtrfp.trcl.Tunnel.java

public Tunnel(TR tr, TDFFile.Tunnel sourceTunnel, LoadingProgressReporter rootReporter) {
    super(tr.getDefaultGrid());
    this.world = tr.getWorld();
    reporters = rootReporter.generateSubReporters(2);
    this.sourceTunnel = sourceTunnel;
    this.tr = tr;
    gl = tr.gpu.get().getGl();//from  w w w.java  2s  .  c  om
    tunnelAssemblyReporter = reporters[0];
    Vector3D tunnelEnd = null;
    deactivate();// Sleep until activated by tunnel entrance
    try {
        lvl = tr.getResourceManager().getLVL(sourceTunnel.getTunnelLVLFile());
        final Vector3D entranceVector = TUNNEL_START_DIRECTION.getHeading();
        palette = tr.getResourceManager().getPalette(lvl.getGlobalPaletteFile());
        palette[0] = new Color(0, 0, 0, 0);//KLUDGE: Color zero must be transparent.
        paletteVL = new ColorPaletteVectorList(palette);
        ESTuTvPalette = new ColorPaletteVectorList(
                tr.getResourceManager().getLTE("FOG\\" + lvl.getLuminanceMapFile()).toColors(palette));
        tunnelEnd = buildTunnel(sourceTunnel, entranceVector, false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    exitObject = new TunnelExitObject(tr, this);
    exitObject.setMirrorTerrain(sourceTunnel.getExitMode() == ExitMode.exitToChamber);
    exitObject.setPosition(tunnelEnd.add(new Vector3D(50000, 0, 0)).toArray());
    exitObject.notifyPositionChange();
    add(exitObject);
    // X is tunnel depth, Z is left-right
    try {
        objectSystem = new ObjectSystem(this, tr, lvl, null, Vector3D.MINUS_I,
                TUNNEL_START_POS.add(TUNNEL_OBJECT_POS_OFFSET), reporters[1]);
    } catch (Exception e) {
        e.printStackTrace();
    }
    /*tr.getGame().getCurrentMission().getOverworldSystem().add(
       entranceObject = new TunnelEntranceObject(tr, this));*/
}

From source file:org.jtrfp.trcl.Tunnel.java

private Vector3D buildTunnel(TDFFile.Tunnel _tun, Vector3D groundVector, boolean entrance)
        throws IllegalAccessException, UnrecognizedFormatException, FileNotFoundException, FileLoadException,
        IOException {//w w  w . ja  v a  2  s . co m
    // Entrance uses only a stub. Player is warped to TUNNEL_POS facing
    // TUNNEL_START_DIRECTION
    ResourceManager rm = tr.getResourceManager();
    LVLFile tlvl = rm.getLVL(_tun.getTunnelLVLFile());
    final ColorPaletteVectorList tunnelColorPalette = new ColorPaletteVectorList(
            tr.getResourceManager().getPalette(lvl.getGlobalPaletteFile()));
    TextureDescription[] tunnelTexturePalette = rm.getTextures(tlvl.getLevelTextureListFile(), paletteVL,
            ESTuTvPalette, true);
    TNLFile tun = tr.getResourceManager().getTNLData(tlvl.getHeightMapOrTunnelFile());

    final double segLen = 65536;
    final double bendiness = 18;
    List<Segment> segs = tun.getSegments();
    final LoadingProgressReporter[] reporters = tunnelAssemblyReporter.generateSubReporters(segs.size());
    // Vector3D tunnelEnd = TUNNEL_START_POS;
    Rotation rotation = entrance ? new Rotation(new Vector3D(0, 0, 1), groundVector)
            : new Rotation(new Vector3D(0, 0, 1), new Vector3D(1, 0, 0));
    Vector3D startPoint = TUNNEL_START_POS;

    Vector3D segPos = Vector3D.ZERO;

    final Vector3D top = rotation.applyTo(new Vector3D(0, 1, 0));
    /*
    if (entrance) {
        // Entrance is just a stub so we only need a few of the segments
        List<Segment> newSegs = new ArrayList<Segment>();
        for (int i = 0; i < 10; i++) {
       newSegs.add(segs.get(i));
        }
        segs = newSegs;
    }*/
    // CONSTRUCT AND INSTALL SEGMENTS
    int segIndex = 0;
    Vector3D finalPos = TUNNEL_START_POS;
    for (Segment s : segs) {
        reporters[segIndex].complete();
        tr.getReporter().report(
                "org.jtrfp.trcl.Tunnel." + _tun.getTunnelLVLFile() + ".segment" + (segIndex++) + "",
                s.getObstacle().name());
        // Figure out the space the segment will take
        Vector3D positionDelta = new Vector3D((double) (s.getEndX() - s.getStartX()) * bendiness * -1,
                (double) (s.getEndY() - s.getStartY()) * bendiness, segLen);
        // Create the segment
        Vector3D position = startPoint.add(rotation.applyTo(segPos));
        TunnelSegment ts = new TunnelSegment(tr, s, tunnelTexturePalette, segLen, positionDelta.getX(),
                positionDelta.getY());
        ts.setPosition(position.toArray());
        ts.setHeading(entrance ? groundVector : Vector3D.PLUS_I);
        ts.setTop(entrance ? top : Vector3D.PLUS_J);
        // Install the segment
        add(ts);
        installObstacles(s, tunnelColorPalette, ESTuTvPalette, tunnelTexturePalette,
                entrance ? groundVector : Vector3D.PLUS_I, entrance ? top : Vector3D.PLUS_J, position,
                TR.legacy2Modern(s.getStartWidth() * TunnelSegment.TUNNEL_DIA_SCALAR),
                TR.legacy2Modern(s.getStartWidth() * TunnelSegment.TUNNEL_DIA_SCALAR), tr);
        // Move origin to next segment
        segPos = segPos.add(positionDelta);
        finalPos = position;
    } // end for(segments)
    return finalPos;
}

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?
 * /*from  w ww . j  ava2 s .  c  o m*/
 * @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.micromanager.plugins.magellan.propsandcovariants.LaserPredNet.java

/**
 *
 * @return return distance to surface interpolation based on x y and z points
 *//*from  w  w w.java  2  s  .c  o  m*/
private static double getSampledDistancesToSurface(int angleIndex, double x, double y, double z,
        SurfaceInterpolator surface) throws InterruptedException {
    double dTheta = Math.PI * 2.0 / (double) N_THETA_ANGLES;
    Vector3D initialPoint = new Vector3D(x, y, z);
    double[] distances = new double[N_THETA_ANGLES];
    double theta = angleIndex * dTheta;
    //calculate unit vector in theta phi direction
    Vector3D directionUnitVec = new Vector3D(Math.cos(theta) * Math.sin(PHI), Math.sin(theta) * Math.sin(PHI),
            Math.cos(PHI)).scalarMultiply(-1);
    //binary search 
    double initialDist = SEARCH_START_DIST;
    //start with a point outside and then binary line search for the distance
    while (isWithinSurace(surface, initialPoint.add(directionUnitVec.scalarMultiply(initialDist)))) {
        initialDist *= 2;
    }
    return binarySearch(initialPoint, directionUnitVec, 0, initialDist, surface);
}

From source file:org.micromanager.plugins.magellan.propsandcovariants.LaserPredNet.java

private static double binarySearch(Vector3D initialPoint, Vector3D direction, double minDistance,
        double maxDistance, SurfaceInterpolator surf) throws InterruptedException {
    double halfDistance = (minDistance + maxDistance) / 2;
    //if the distance has been narrowed to a sufficiently small interval, return
    if (maxDistance - minDistance < SEARCH_TOLERANCE) {
        return halfDistance;
    }//from  w w  w .  j  a v a2  s. co m
    //check if point is above surface in 
    Vector3D searchPoint = initialPoint.add(direction.scalarMultiply(halfDistance));
    boolean withinSurface = isWithinSurace(surf, searchPoint);
    if (!withinSurface) {
        return binarySearch(initialPoint, direction, minDistance, halfDistance, surf);
    } else {
        return binarySearch(initialPoint, direction, halfDistance, maxDistance, surf);
    }
}

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.GroundPointingWrapper.java

/** {@inheritDoc} */
@Override/*from  w  w w.ja  va2 s. c om*/
public Attitude getAttitude(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame)
        throws OrekitException {

    // Get attitude from base attitude provider
    final Attitude base = getBaseState(pvProv, date, frame);

    // Get compensation
    final Rotation compensation = getCompensation(pvProv, date, frame, base);

    // Compute compensation rotation rate
    final double h = 0.1;
    final Rotation compensationM1H = getCompensation(pvProv, date.shiftedBy(-h), frame, base.shiftedBy(-h));
    final Rotation compensationP1H = getCompensation(pvProv, date.shiftedBy(h), frame, base.shiftedBy(h));
    final Vector3D compensationRate = AngularCoordinates.estimateRate(compensationM1H, compensationP1H, 2 * h);

    // Combination of base attitude, compensation and compensation rate
    return new Attitude(date, frame, compensation.applyTo(base.getRotation()),
            compensationRate.add(compensation.applyTo(base.getSpin())));

}

From source file:org.orekit.bodies.OneAxisEllipsoidTest.java

@Test
public void testLineIntersection() throws OrekitException {
    AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
    Frame frame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);

    OneAxisEllipsoid model = new OneAxisEllipsoid(100.0, 0.9, frame);
    Vector3D point = new Vector3D(0.0, 93.7139699, 3.5930796);
    Vector3D direction = new Vector3D(0.0, 1.0, 1.0);
    Line line = new Line(point, point.add(direction), 1.0e-10);
    GeodeticPoint gp = model.getIntersectionPoint(line, point, frame, date);
    Assert.assertEquals(gp.getAltitude(), 0.0, 1.0e-12);
    Assert.assertTrue(line.contains(model.transform(gp)));

    model = new OneAxisEllipsoid(100.0, 0.9, frame);
    point = new Vector3D(0.0, -93.7139699, -3.5930796);
    direction = new Vector3D(0.0, -1.0, -1.0);
    line = new Line(point, point.add(direction), 1.0e-10).revert();
    gp = model.getIntersectionPoint(line, point, frame, date);
    Assert.assertTrue(line.contains(model.transform(gp)));

    model = new OneAxisEllipsoid(100.0, 0.9, frame);
    point = new Vector3D(0.0, -93.7139699, 3.5930796);
    direction = new Vector3D(0.0, -1.0, 1.0);
    line = new Line(point, point.add(direction), 1.0e-10);
    gp = model.getIntersectionPoint(line, point, frame, date);
    Assert.assertTrue(line.contains(model.transform(gp)));

    model = new OneAxisEllipsoid(100.0, 0.9, frame);
    point = new Vector3D(-93.7139699, 0.0, 3.5930796);
    direction = new Vector3D(-1.0, 0.0, 1.0);
    line = new Line(point, point.add(direction), 1.0e-10);
    gp = model.getIntersectionPoint(line, point, frame, date);
    Assert.assertTrue(line.contains(model.transform(gp)));
    Assert.assertFalse(line.contains(new Vector3D(0, 0, 7000000)));

    point = new Vector3D(0.0, 0.0, 110);
    direction = new Vector3D(0.0, 0.0, 1.0);
    line = new Line(point, point.add(direction), 1.0e-10);
    gp = model.getIntersectionPoint(line, point, frame, date);
    Assert.assertEquals(gp.getLatitude(), FastMath.PI / 2, 1.0e-12);

    point = new Vector3D(0.0, 110, 0);
    direction = new Vector3D(0.0, 1.0, 0.0);
    line = new Line(point, point.add(direction), 1.0e-10);
    gp = model.getIntersectionPoint(line, point, frame, date);
    Assert.assertEquals(gp.getLatitude(), 0, 1.0e-12);

}

From source file:org.orekit.bodies.OneAxisEllipsoidTest.java

@Test
public void testNoLineIntersection() throws OrekitException {
    AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
    Frame frame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
    OneAxisEllipsoid model = new OneAxisEllipsoid(100.0, 0.9, frame);
    Vector3D point = new Vector3D(0.0, 93.7139699, 3.5930796);
    Vector3D direction = new Vector3D(0.0, 9.0, -2.0);
    Line line = new Line(point, point.add(direction), 1.0e-10);
    Assert.assertNull(model.getIntersectionPoint(line, point, frame, date));
}