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

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

Introduction

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

Prototype

public Vector3D(double x, double y, double z) 

Source Link

Document

Simple constructor.

Usage

From source file:com.diozero.sandpit.imu.invensense.MPU9150DriverMqttPublisher.java

private void handleGyroBias(ImuData imuData) {
    /*/*from  ww  w  .  j  a va 2 s .c  o m*/
     * Shouldn't need to do any of this if we call dmp_set_orientation...
    // do axis rotation
    if (axisRotation != null) {
       // need to do an axis rotation
       byte[][] matrix = axisRotation.getOrientationMatrix();
       IMUData tempIMU = imuData;
            
       // do new x value
       if (matrix[0][0] != 0) {
    imuData.gyro.setX(tempIMU.gyro.x() * matrix[0][0]);
    imuData.accel.setX(tempIMU.accel.x() * matrix[0][0]);
    imuData.compass.setX(tempIMU.compass.x() * matrix[0][0]);
       } else if (matrix[0][1] != 0) {
    imuData.gyro.setX(tempIMU.gyro.y() * matrix[0][1]);
    imuData.accel.setX(tempIMU.accel.y() * matrix[0][1]);
    imuData.compass.setX(tempIMU.compass.y() * matrix[0][1]);
       } else if (matrix[0][2] != 0) {
    imuData.gyro.setX(tempIMU.gyro.z() * matrix[0][2]);
    imuData.accel.setX(tempIMU.accel.z() * matrix[0][2]);
    imuData.compass.setX(tempIMU.compass.z() * matrix[0][2]);
       }
            
       // do new y value
       if (matrix[1][0] != 0) {
    imuData.gyro.setY(tempIMU.gyro.x() * matrix[1][0]);
    imuData.accel.setY(tempIMU.accel.x() * matrix[1][0]);
    imuData.compass.setY(tempIMU.compass.x() * matrix[1][0]);
       } else if (matrix[1][1] != 0) {
    imuData.gyro.setY(tempIMU.gyro.y() * matrix[1][1]);
    imuData.accel.setY(tempIMU.accel.y() * matrix[1][1]);
    imuData.compass.setY(tempIMU.compass.y() * matrix[1][1]);
       } else if (matrix[1][2] != 0) {
    imuData.gyro.setY(tempIMU.gyro.z() * matrix[1][2]);
    imuData.accel.setY(tempIMU.accel.z() * matrix[1][2]);
    imuData.compass.setY(tempIMU.compass.z() * matrix[1][2]);
       }
            
       // do new z value
       if (matrix[2][0] != 0) {
    imuData.gyro.setZ(tempIMU.gyro.x() * matrix[2][0]);
    imuData.accel.setZ(tempIMU.accel.x() * matrix[2][0]);
    imuData.compass.setZ(tempIMU.compass.x() * matrix[2][0]);
       } else if (matrix[2][1] != 0) {
    imuData.gyro.setZ(tempIMU.gyro.y() * matrix[2][1]);
    imuData.accel.setZ(tempIMU.accel.y() * matrix[2][1]);
    imuData.compass.setZ(tempIMU.compass.y() * matrix[2][1]);
       } else if (matrix[2][2] != 0) {
    imuData.gyro.setZ(tempIMU.gyro.z() * matrix[2][2]);
    imuData.accel.setZ(tempIMU.accel.z() * matrix[2][2]);
    imuData.compass.setZ(tempIMU.compass.z() * matrix[2][2]);
       }
    }
    */

    Vector3D deltaAccel = previousAccel.subtract(imuData.getAccel()); // compute difference
    previousAccel = imuData.getAccel();

    if ((deltaAccel.getNorm() < RTIMU_FUZZY_ACCEL_ZERO)
            && (imuData.getGyro().getNorm() < RTIMU_FUZZY_GYRO_ZERO)) {
        // What we are seeing on the gyros should be bias only so learn from this
        if (gyroSampleCount < (5 * sampleRate)) {
            gyroBias = new Vector3D(
                    (1.0 - gyroLearningAlpha) * gyroBias.getX() + gyroLearningAlpha * imuData.getGyro().getX(),
                    (1.0 - gyroLearningAlpha) * gyroBias.getY() + gyroLearningAlpha * imuData.getGyro().getY(),
                    (1.0 - gyroLearningAlpha) * gyroBias.getZ() + gyroLearningAlpha * imuData.getGyro().getZ());

            gyroSampleCount++;

            if (gyroSampleCount == (5 * sampleRate)) {
                // this could have been true already of course
                gyroBiasValid = true;
                //saveSettings();
            }
        } else {
            gyroBias = new Vector3D(
                    (1.0 - gyroContinuousAlpha) * gyroBias.getX()
                            + gyroContinuousAlpha * imuData.getGyro().getX(),
                    (1.0 - gyroContinuousAlpha) * gyroBias.getY()
                            + gyroContinuousAlpha * imuData.getGyro().getY(),
                    (1.0 - gyroContinuousAlpha) * gyroBias.getZ()
                            + gyroContinuousAlpha * imuData.getGyro().getZ());
        }
    }

    imuData.setGyro(imuData.getGyro().subtract(gyroBias));
}

From source file:ch.epfl.leb.sass.ijplugin.IJPluginModel.java

/**
 * Builds a microscope from the model parameters.
 * @return A new microscope built from the model parameters.
 *//*from   ww  w  . j a v a2s. c  o  m*/
public Microscope build() {
    DefaultCamera.Builder cameraBuilder = new DefaultCamera.Builder();
    DefaultObjective.Builder objectiveBuilder = new DefaultObjective.Builder();
    DefaultStage.Builder stageBuilder = new DefaultStage.Builder();
    FluorophoreDynamicsBuilder fluorPropBuilder = null;
    DefaultLaser.Builder laserBuilder = new DefaultLaser.Builder();
    PSFBuilder psfBuilder = null;
    FluorophoreCommandBuilder fluorPosBuilder = null;
    GenerateFiducialsRandom2D.Builder fidBuilder = new GenerateFiducialsRandom2D.Builder();
    BackgroundCommandBuilder backgroundBuilder = null;

    cameraBuilder.nX(cameraNX);
    cameraBuilder.nY(cameraNY);
    cameraBuilder.readoutNoise(cameraReadoutNoise);
    cameraBuilder.darkCurrent(cameraDarkCurrent);
    cameraBuilder.quantumEfficiency(cameraQuantumEfficiency);
    cameraBuilder.aduPerElectron(cameraAduPerElectron);
    cameraBuilder.emGain(cameraEmGain);
    cameraBuilder.baseline(cameraBaseline);
    cameraBuilder.pixelSize(cameraPixelSize);

    objectiveBuilder.NA(objectiveNa);
    objectiveBuilder.mag(objectiveMag);

    stageBuilder.x(0);
    stageBuilder.y(0);
    stageBuilder.z(stageZ);

    if (fluorophoreCurrentSelection.equals(fluorophoreSimpleText)) {
        try {
            SimpleDynamics.Builder tempFluorPropBuilder = new SimpleDynamics.Builder();
            tempFluorPropBuilder.signal(fluorophoreSignal);
            tempFluorPropBuilder.wavelength(fluorophoreWavelength);
            tempFluorPropBuilder.tOn(fluorophoreTOn);
            tempFluorPropBuilder.tOff(fluorophoreTOff);
            tempFluorPropBuilder.tBl(fluorophoreTBl);
            fluorPropBuilder = tempFluorPropBuilder;
        } catch (Exception ex) {
            IJ.showMessage("Error in Simple fluorophore properties parsing.");
        }
    } else if (fluorophoreCurrentSelection.equals(fluorophorePalmText)) {
        try {
            PalmDynamics.Builder tempFluorPropBuilder = new PalmDynamics.Builder();
            tempFluorPropBuilder.signal(palmSignal);
            tempFluorPropBuilder.wavelength(palmWavelength);
            tempFluorPropBuilder.kA(palmKA).kB(palmKB).kD1(palmKD1).kR1(palmKR1).kD2(palmKD2).kR2(palmKR2);
            fluorPropBuilder = tempFluorPropBuilder;
        } catch (Exception ex) {
            IJ.showMessage("Error in PALM fluorophore properties parsing.");
        }
    } else if (fluorophoreCurrentSelection.equals(fluorophoreStormText)) {
        try {
            StormDynamics.Builder tempFluorPropBuilder = new StormDynamics.Builder();
            tempFluorPropBuilder.signal(stormSignal);
            tempFluorPropBuilder.wavelength(stormWavelength);
            tempFluorPropBuilder.kBl(stormKBl).kTriplet(stormKTriplet).kTripletRecovery(stormKTripletRecovery)
                    .kDark(stormKDark).kDarkRecovery(stormKDarkRecovery)
                    .kDarkRecoveryConstant(stormKDarkRecoveryConstant);
            fluorPropBuilder = tempFluorPropBuilder;
        } catch (Exception ex) {
            IJ.showMessage("Error in STORM fluorophore properties parsing.");
        }
    }

    fidBuilder.numFiducials(fiducialsNumber); // Set to zero if you don't want fiducials
    fidBuilder.brightness(fiducialsSignal);

    laserBuilder.currentPower(laserCurrentPower);
    laserBuilder.minPower(laserMinPower);
    laserBuilder.maxPower(laserMaxPower);
    // TODO: Make this an option later
    laserBuilder.wavelength(0.642);

    if (emittersCurrentSelection.equals(emittersRandomButtonText) & !(emitters3DCheckBoxEnabled)) {
        // Random 2D fluorophore distributions
        try {
            GenerateFluorophoresRandom2D.Builder tempPosBuilder = new GenerateFluorophoresRandom2D.Builder();
            tempPosBuilder.numFluors(emittersRandomNumber);
            fluorPosBuilder = tempPosBuilder;
        } catch (Exception ex) {
            IJ.showMessage("Error in emitter position parsing.");
        }
    } else if (emittersCurrentSelection.equals(emittersGridButtonText) & !(emitters3DCheckBoxEnabled)) {
        // Fluorophore distributions in 2D on a square grid
        try {
            GenerateFluorophoresGrid2D.Builder tempPosBuilder = new GenerateFluorophoresGrid2D.Builder();
            tempPosBuilder.spacing(emittersGridSpacing);
            fluorPosBuilder = tempPosBuilder;
        } catch (Exception ex) {
            IJ.showMessage("Error in emitter position parsing.");
        }
    } else if (emittersCurrentSelection.equals(emittersRandomButtonText) & emitters3DCheckBoxEnabled) {
        // Random 3D fluorophore distributions
        try {
            GenerateFluorophoresRandom3D.Builder tempPosBuilder = new GenerateFluorophoresRandom3D.Builder();
            tempPosBuilder.numFluors(emittersRandomNumber);
            tempPosBuilder.zLow(emitters3DMinZ);
            tempPosBuilder.zHigh(emitters3DMaxZ);
            fluorPosBuilder = tempPosBuilder;
        } catch (Exception ex) {
            IJ.showMessage("Error in emitter position parsing.");
        }
    } else if (emittersCurrentSelection.equals(emittersGridButtonText) & !(emitters3DCheckBoxEnabled)) {
        // Fluorophore distributions in 3D on a square grid
        try {
            GenerateFluorophoresGrid3D.Builder tempPosBuilder = new GenerateFluorophoresGrid3D.Builder();
            tempPosBuilder.spacing(emittersGridSpacing);
            tempPosBuilder.zLow(emitters3DMinZ);
            tempPosBuilder.zHigh(emitters3DMaxZ);
            fluorPosBuilder = tempPosBuilder;
        } catch (Exception ex) {
            IJ.showMessage("Error in emitter position parsing.");
        }
    } else if (emittersCurrentSelection.equals(emittersCsvFileButtonText)) {
        // Parse fluorophore positions from a CSV file
        GenerateFluorophoresFromCSV.Builder tempPosBuilder = new GenerateFluorophoresFromCSV.Builder();
        tempPosBuilder.file(new File(emittersCsvFile));
        tempPosBuilder.rescale(false);
        fluorPosBuilder = tempPosBuilder;
    }

    if (backgroundCurrentSelection.equals(backgroundUniformButtonText)) {
        try {
            GenerateUniformBackground.Builder tempBuilder = new GenerateUniformBackground.Builder();
            tempBuilder.backgroundSignal(backgroundUniformSignal);
            backgroundBuilder = tempBuilder;
        } catch (NumberFormatException ex) {
            IJ.showMessage("Error in parsing of numerical values.");
        } catch (Exception ex) {
            IJ.showMessage("Error in device component intialization.");
        }
    } else if (backgroundCurrentSelection.equals(backgroundTifFileButtonText)) {
        try {
            GenerateBackgroundFromFile.Builder tempBuilder = new GenerateBackgroundFromFile.Builder();
            tempBuilder.file(new File(backgroundTifFile));
            backgroundBuilder = tempBuilder;
        } catch (ArrayIndexOutOfBoundsException ex) {
            IJ.showMessage("Error in background loading. The image is not large enough.");
        } catch (Exception ex) {
            IJ.showMessage("Error in background loading.");
        }
    } else if (backgroundCurrentSelection.equals(backgroundRandomButtonText)) {
        try {
            GenerateRandomBackground.Builder tempBuilder = new GenerateRandomBackground.Builder();
            tempBuilder.featureSize(backgroundRandomFeatureSize);
            tempBuilder.min(backgroundRandomMinValue);
            tempBuilder.max(backgroundRandomMaxValue);
            tempBuilder.seed(backgroundRandomSeed);
            backgroundBuilder = tempBuilder;
        } catch (NumberFormatException ex) {
            IJ.showMessage("Error in parsing of numerical values.");
        } catch (Exception ex) {
            IJ.showMessage("Error in device component intialization.");
        }
    }

    if (psfCurrentSelection.equals(psfGaussian2dText)) {
        psfBuilder = new Gaussian2D.Builder();
    } else if (psfCurrentSelection.equals(psfGaussian3dText)) {
        psfBuilder = new Gaussian3D.Builder();
    } else if (psfCurrentSelection.equals(psfGibsonLanniText)) {
        GibsonLanniPSF.Builder tempBuilder = new GibsonLanniPSF.Builder();
        tempBuilder.numBasis(psfGibsonLanniNumBasis).numSamples(psfGibsonLanniNumSamples)
                .oversampling(psfGibsonLanniOversampling).sizeX(psfGibsonLanniSizeX).sizeY(psfGibsonLanniSizeY)
                .ns(psfGibsonLanniNs).ng0(psfGibsonLanniNg0).ng(psfGibsonLanniNg).ni0(psfGibsonLanniNi0)
                .ni(psfGibsonLanniNi).ti0(psfGibsonLanniTi0).tg0(psfGibsonLanniTg0).tg(psfGibsonLanniTg)
                .resPSF(psfGibsonLanniResPsf).resPSFAxial(psfGibsonLanniResPsfAxial)
                .solver(psfGibsonLanniSolver).maxRadius(psfGibsonLanniMaxRadius);
        psfBuilder = tempBuilder;

    }

    // TODO: Add illumination setup to the GUI
    RefractiveIndex n = new UniformRefractiveIndex(new Complex(1.33));
    SquareUniformIllumination.Builder illumBuilder = new SquareUniformIllumination.Builder();
    illumBuilder.height(cameraNY * cameraPixelSize / objectiveMag);
    illumBuilder.orientation(new Vector3D(1.0, 0, 0)); // x-polarized
    illumBuilder.refractiveIndex(n);
    illumBuilder.width(cameraNY * cameraPixelSize / objectiveMag);

    return new Microscope(cameraBuilder, laserBuilder, objectiveBuilder, psfBuilder, stageBuilder,
            fluorPosBuilder, fluorPropBuilder, fidBuilder, backgroundBuilder, illumBuilder);
}

From source file:nova.core.network.handler.BlockPacket.java

@Override
public void read(Packet packet) {
    Entity entity = packet.player().entity();
    Vector3D position = new Vector3D(packet.readInt(), packet.readInt(), packet.readInt());

    Optional<Block> opBlock = entity.world().getBlock(position);

    if (opBlock.isPresent()) {
        Block block = opBlock.get();//from   w  ww.  j  a  v a2 s .c o  m
        if (block instanceof Syncable) {
            ((Syncable) block).read(packet);
            return;
        }
    }
    throw new NetworkException("Failed to receive packet to block at " + position);
}

From source file:nova.core.util.math.Vector3DUtil.java

/**
 * @return Creates a random unit vector//from w w w  .  j  a  v a  2  s  .  com
 */
public static Vector3D random() {
    Random random = new Random();
    return new Vector3D(random.nextDouble(), random.nextDouble(), random.nextDouble()).scalarMultiply(2)
            .subtract(ONE);
}

From source file:nova.core.util.math.Vector3DUtil.java

/**
 * Calculates maximum of each coordinate.
 *
 * @param a first vector.// w w w .ja  va 2 s  .  c  o  m
 * @param b second vector.
 * @return new vector that's each coordinate is maximum of coordinates of a and b.
 */
public static Vector3D max(Vector3D a, Vector3D b) {
    return new Vector3D(FastMath.max(a.getX(), b.getX()), FastMath.max(a.getY(), b.getY()),
            FastMath.max(a.getZ(), b.getZ()));
}

From source file:nova.core.util.math.Vector3DUtil.java

/**
 * Calculates minimum of each coordinate.
 * @param a first vector./*  ww  w . j  a  v a2  s .  co  m*/
 * @param b second vector.
 * @return new vector that's each coordinate is minimum of coordinates of a and b.
 */
public static Vector3D min(Vector3D a, Vector3D b) {
    return new Vector3D(FastMath.min(a.getX(), b.getX()), FastMath.min(a.getY(), b.getY()),
            FastMath.min(a.getZ(), b.getZ()));
}

From source file:nova.core.util.math.Vector3DUtil.java

public static Vector3D cartesianProduct(Vector3D a, Vector3D b) {
    return new Vector3D(a.getX() * b.getX(), a.getY() * b.getY(), a.getZ() * b.getZ());
}

From source file:nova.core.util.math.Vector3DUtil.java

public static Vector3D xCross(Vector3D vec) {
    return new Vector3D(0, vec.getZ(), -vec.getY());
}

From source file:nova.core.util.math.Vector3DUtil.java

public static Vector3D zCross(Vector3D vec) {
    return new Vector3D(-vec.getY(), vec.getX(), 0);
}

From source file:nova.core.util.math.Vector3DUtil.java

/**
 * Calculates one by vectos./*from   ww  w.  j  ava  2 s . c o m*/
 * @param vec vector to be reciprocated.
 * @return reciprocal of vec.
 */
public static Vector3D reciprocal(Vector3D vec) {
    return new Vector3D(1 / vec.getX(), 1 / vec.getY(), 1 / vec.getZ());
}