Search in sources :

Example 6 with Vector3D

use of org.apache.commons.math3.geometry.euclidean.threed.Vector3D in project imagej-ops by imagej.

the class DefaultVoxelization3D method calculate.

@Override
public RandomAccessibleInterval<BitType> calculate(Mesh input) {
    Img<BitType> outImg = ops.create().img(new FinalInterval(width, height, depth), new BitType());
    DefaultMesh dMesh = (DefaultMesh) input;
    Set<RealLocalizable> verts = dMesh.getVertices();
    RealPoint minPoint = new RealPoint(verts.iterator().next());
    RealPoint maxPoint = new RealPoint(verts.iterator().next());
    for (RealLocalizable v : verts) {
        if (v.getDoublePosition(0) < minPoint.getDoublePosition(0))
            minPoint.setPosition(v.getDoublePosition(0), 0);
        if (v.getDoublePosition(1) < minPoint.getDoublePosition(1))
            minPoint.setPosition(v.getDoublePosition(1), 1);
        if (v.getDoublePosition(2) < minPoint.getDoublePosition(2))
            minPoint.setPosition(v.getDoublePosition(2), 2);
        if (v.getDoublePosition(0) > maxPoint.getDoublePosition(0))
            maxPoint.setPosition(v.getDoublePosition(0), 0);
        if (v.getDoublePosition(1) > maxPoint.getDoublePosition(1))
            maxPoint.setPosition(v.getDoublePosition(1), 1);
        if (v.getDoublePosition(2) > maxPoint.getDoublePosition(2))
            maxPoint.setPosition(v.getDoublePosition(2), 2);
    }
    RealPoint dimPoint = new RealPoint((maxPoint.getDoublePosition(0) - minPoint.getDoublePosition(0)), (maxPoint.getDoublePosition(1) - minPoint.getDoublePosition(1)), (maxPoint.getDoublePosition(2) - minPoint.getDoublePosition(2)));
    double[] stepSizes = new double[3];
    stepSizes[0] = dimPoint.getDoublePosition(0) / width;
    stepSizes[1] = dimPoint.getDoublePosition(1) / height;
    stepSizes[2] = dimPoint.getDoublePosition(2) / depth;
    double[] voxelHalfsize = new double[3];
    for (int k = 0; k < stepSizes.length; k++) voxelHalfsize[k] = stepSizes[k] / 2.0;
    for (Facet f : dMesh.getFacets()) {
        TriangularFacet tri = (TriangularFacet) f;
        Vector3D v1 = tri.getP0();
        Vector3D v2 = tri.getP1();
        Vector3D v3 = tri.getP2();
        double[] minSubBoundary = new double[] { Math.min(Math.min(v1.getX(), v2.getX()), v3.getX()) - minPoint.getDoublePosition(0), Math.min(Math.min(v1.getY(), v2.getY()), v3.getY()) - minPoint.getDoublePosition(1), Math.min(Math.min(v1.getZ(), v2.getZ()), v3.getZ()) - minPoint.getDoublePosition(2) };
        double[] maxSubBoundary = new double[] { Math.max(Math.max(v1.getX(), v2.getX()), v3.getX()) - minPoint.getDoublePosition(0), Math.max(Math.max(v1.getY(), v2.getY()), v3.getY()) - minPoint.getDoublePosition(1), Math.max(Math.max(v1.getZ(), v2.getZ()), v3.getZ()) - minPoint.getDoublePosition(2) };
        // Should use the
        RandomAccess<BitType> ra = outImg.randomAccess();
        // interval
        // implementation
        // for speed
        long[] indices = new long[3];
        for (indices[0] = (long) Math.floor(minSubBoundary[0] / stepSizes[0]); indices[0] < Math.floor(maxSubBoundary[0] / stepSizes[0]); indices[0]++) {
            for (indices[1] = (long) Math.floor(minSubBoundary[1] / stepSizes[1]); indices[1] < Math.floor(maxSubBoundary[1] / stepSizes[1]); indices[1]++) {
                for (indices[2] = (long) Math.floor(minSubBoundary[2] / stepSizes[2]); indices[2] < Math.floor(maxSubBoundary[2] / stepSizes[2]); indices[2]++) {
                    ra.setPosition(indices);
                    if (// Don't check if voxel is already
                    !ra.get().get()) // filled
                    {
                        double[] voxelCenter = new double[3];
                        for (int k = 0; k < 3; k++) voxelCenter[k] = indices[k] * stepSizes[k] + voxelHalfsize[k];
                        if (triBoxOverlap(voxelCenter, voxelHalfsize, v1, v2, v3) == 1) {
                            ra.get().set(true);
                        }
                    }
                }
            }
        }
    }
    return outImg;
}
Also used : RealLocalizable(net.imglib2.RealLocalizable) RealPoint(net.imglib2.RealPoint) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet) DefaultMesh(net.imagej.ops.geom.geom3d.mesh.DefaultMesh) BitType(net.imglib2.type.logic.BitType) Vector3D(org.apache.commons.math3.geometry.euclidean.threed.Vector3D) RealPoint(net.imglib2.RealPoint) FinalInterval(net.imglib2.FinalInterval) Facet(net.imagej.ops.geom.geom3d.mesh.Facet) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet)

Example 7 with Vector3D

use of org.apache.commons.math3.geometry.euclidean.threed.Vector3D in project imagej-ops by imagej.

the class TriangularFacet method computeNormal.

/**
 * Compute the normal of this facet.
 */
private void computeNormal() {
    Vector3D v0 = vertices.get(0);
    Vector3D v1 = vertices.get(1);
    Vector3D v2 = vertices.get(2);
    normal = v1.subtract(v0).crossProduct(v2.subtract(v0));
}
Also used : Vector3D(org.apache.commons.math3.geometry.euclidean.threed.Vector3D)

Example 8 with Vector3D

use of org.apache.commons.math3.geometry.euclidean.threed.Vector3D in project SpriteOrbits by ProjectPersephone.

the class SpriteProp method main.

/**
 * @param args
 */
public static void main(String[] args) {
    PrintStream out = null;
    try {
        // set up orekit data
        // for this to work, the orekit-data.zip file avaiable at the following URL
        // must be put in the current working directory
        // URL:     https://www.orekit.org/forge/projects/orekit/files
        File userDir = new File(System.getProperty("user.dir"));
        File orekitZip = new File(userDir, "orekit-data.zip");
        DataProvidersManager.getInstance().addProvider(new ZipJarCrawler(orekitZip));
        // reference models
        // this is the frame labeled J2K in the NASA page
        final Frame eme2000 = FramesFactory.getEME2000();
        final Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
        final TimeScale utc = TimeScalesFactory.getUTC();
        // central attraction coefficient MU
        final double mu = Constants.EIGEN5C_EARTH_MU;
        // set up some data, ideally, this should be provided as input to the program
        // ISS orbit is from http://spaceflight.nasa.gov/realdata/sightings/SSapplications/Post/JavaSSOP/orbit/ISS/SVPOST.html
        // 
        // Coasting Arc #15 (Orbit 3386)
        // ---------------------------------------
        // 
        // Vector Time (GMT): 2014/055/16:27:06.921
        // Vector Time (MET): N/A
        // Weight (LBS)     : 911651.1
        // 
        // ...
        // 
        // J2K Cartesian
        // --------------------------------
        // X    =         2998767.75
        // Y    =        -6097451.56  meter
        // ...              Z    =         -141448.92
        // XDOT =        4323.077242
        // YDOT =        1994.291706  meter/sec
        // ZDOT =        6000.774574
        // we start small, we can increase this later
        final int numberOfSprites = 12;
        // (m/s)
        final double relativeReleaseVelocity = 1.0;
        final AbsoluteDate releaseDate = new // year, month, day
        AbsoluteDate(// year, month, day
        2014, // year, month, day
        3, // year, month, day
        1, // hours, minutes, seconds
        12, // hours, minutes, seconds
        0, // hours, minutes, seconds
        0.0, utc);
        final CartesianOrbit kickSatOrbit = new CartesianOrbit(new // position (m)
        PVCoordinates(// position (m)
        new Vector3D(2998767.75, -6097451.56, -141448.92), // velocity (m/s)
        new Vector3D(4323.077242, 1994.291706, 6000.774574)), eme2000, new // year, day in year as NASA page above
        AbsoluteDate(// year, day in year as NASA page above
        new DateComponents(2014, 55), // hour in day
        new TimeComponents(16, 27, 6.921), utc), mu);
        // kg
        final double kickSatMass = 10.0;
        // m^2
        final double kickSatCrossSection = 0.03;
        // no units
        final double kickSatDragCoeff = 2.2;
        // kg
        final double spriteMass = 0.01;
        // m^2
        final double spriteCrossSection = 2.5e-3;
        // no units
        final double spriteDragCoeff = 2.2;
        SpriteProp spriteProp = new SpriteProp(numberOfSprites, kickSatOrbit, kickSatMass, kickSatCrossSection, kickSatDragCoeff, spriteMass, spriteCrossSection, spriteDragCoeff, relativeReleaseVelocity, releaseDate, itrf);
        // days after release
        final double propagationDuration = 0.2;
        // seconds
        final double step = 60.0;
        // out = new PrintStream(new File(userDir, "sprites-prop.txt"));
        out = new PrintStream(new File(userDir, "orbits.json"));
        out.format(Locale.US, "[");
        spriteProp.run(out, propagationDuration, step, utc);
        out.format(Locale.US, "]");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (OrekitException e) {
        e.printStackTrace();
    } finally {
        if (out != null) {
            out.close();
        }
    }
}
Also used : PrintStream(java.io.PrintStream) Frame(org.orekit.frames.Frame) CartesianOrbit(org.orekit.orbits.CartesianOrbit) DateComponents(org.orekit.time.DateComponents) TimeComponents(org.orekit.time.TimeComponents) IOException(java.io.IOException) TimeScale(org.orekit.time.TimeScale) GeodeticPoint(org.orekit.bodies.GeodeticPoint) AbsoluteDate(org.orekit.time.AbsoluteDate) Vector3D(org.apache.commons.math3.geometry.euclidean.threed.Vector3D) ZipJarCrawler(org.orekit.data.ZipJarCrawler) OrekitException(org.orekit.errors.OrekitException) File(java.io.File)

Example 9 with Vector3D

use of org.apache.commons.math3.geometry.euclidean.threed.Vector3D in project SpriteOrbits by ProjectPersephone.

the class SpritePropOrig method main.

/**
 * @param args
 */
public static void main(String[] args) {
    PrintStream out = null;
    try {
        // set up orekit data
        // for this to work, the orekit-data.zip file avaiable at the following URL
        // must be put in the current working directory
        // URL:     https://www.orekit.org/forge/projects/orekit/files
        File userDir = new File(System.getProperty("user.dir"));
        File orekitZip = new File(userDir, "orekit-data.zip");
        DataProvidersManager.getInstance().addProvider(new ZipJarCrawler(orekitZip));
        // reference models
        // this is the frame labeled J2K in the NASA page
        final Frame eme2000 = FramesFactory.getEME2000();
        final Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
        final TimeScale utc = TimeScalesFactory.getUTC();
        // central attraction coefficient MU
        final double mu = Constants.EIGEN5C_EARTH_MU;
        // set up some data, ideally, this should be provided as input to the program
        // ISS orbit is from http://spaceflight.nasa.gov/realdata/sightings/SSapplications/Post/JavaSSOP/orbit/ISS/SVPOST.html
        // 
        // Coasting Arc #15 (Orbit 3386)
        // ---------------------------------------
        // 
        // Vector Time (GMT): 2014/055/16:27:06.921
        // Vector Time (MET): N/A
        // Weight (LBS)     : 911651.1
        // 
        // ...
        // 
        // J2K Cartesian
        // --------------------------------
        // X    =         2998767.75
        // Y    =        -6097451.56  meter
        // ...              Z    =         -141448.92
        // XDOT =        4323.077242
        // YDOT =        1994.291706  meter/sec
        // ZDOT =        6000.774574
        // we start small, we can increase this later
        final int numberOfSprites = 12;
        // (m/s)
        final double relativeReleaseVelocity = 1.0;
        final AbsoluteDate releaseDate = new // year, month, day
        AbsoluteDate(// year, month, day
        2014, // year, month, day
        3, // year, month, day
        1, // hours, minutes, seconds
        12, // hours, minutes, seconds
        0, // hours, minutes, seconds
        0.0, utc);
        final CartesianOrbit kickSatOrbit = new CartesianOrbit(new // position (m)
        PVCoordinates(// position (m)
        new Vector3D(2998767.75, -6097451.56, -141448.92), // velocity (m/s)
        new Vector3D(4323.077242, 1994.291706, 6000.774574)), eme2000, new // year, day in year as NASA page above
        AbsoluteDate(// year, day in year as NASA page above
        new DateComponents(2014, 55), // hour in day
        new TimeComponents(16, 27, 6.921), utc), mu);
        // kg
        final double kickSatMass = 10.0;
        // m^2
        final double kickSatCrossSection = 0.03;
        // no units
        final double kickSatDragCoeff = 2.2;
        // kg
        final double spriteMass = 0.01;
        // m^2
        final double spriteCrossSection = 2.5e-3;
        // no units
        final double spriteDragCoeff = 2.2;
        SpritePropOrig spriteProp = new SpritePropOrig(numberOfSprites, kickSatOrbit, kickSatMass, kickSatCrossSection, kickSatDragCoeff, spriteMass, spriteCrossSection, spriteDragCoeff, relativeReleaseVelocity, releaseDate, itrf);
        // days after release
        final double propagationDuration = 0.2;
        // seconds
        final double step = 60.0;
        out = new PrintStream(new File(userDir, "sprites-prop.txt"));
        spriteProp.run(out, propagationDuration, step, utc);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (OrekitException e) {
        e.printStackTrace();
    } finally {
        if (out != null) {
            out.close();
        }
    }
}
Also used : PrintStream(java.io.PrintStream) Frame(org.orekit.frames.Frame) CartesianOrbit(org.orekit.orbits.CartesianOrbit) DateComponents(org.orekit.time.DateComponents) TimeComponents(org.orekit.time.TimeComponents) IOException(java.io.IOException) TimeScale(org.orekit.time.TimeScale) GeodeticPoint(org.orekit.bodies.GeodeticPoint) AbsoluteDate(org.orekit.time.AbsoluteDate) Vector3D(org.apache.commons.math3.geometry.euclidean.threed.Vector3D) ZipJarCrawler(org.orekit.data.ZipJarCrawler) OrekitException(org.orekit.errors.OrekitException) File(java.io.File)

Example 10 with Vector3D

use of org.apache.commons.math3.geometry.euclidean.threed.Vector3D in project j6dof-flight-sim by chris-ali.

the class AccelAndMoments method calculateTotalMoments.

/**
 * Calculates the total moment experienced by the aircraft (lb ft)
 *
 * @param windParameters
 * @param angularRates
 * @param environmentParameters
 * @param controls
 * @param alphaDot
 * @param engineList
 * @param aircraft
 * @param groundReaction
 * @param heightAGL
 * @return totalMoments
 */
public static double[] calculateTotalMoments(double[] windParameters, double[] angularRates, Map<EnvironmentParameters, Double> environmentParameters, Map<FlightControl, Double> controls, double alphaDot, Set<Engine> engineList, Aircraft aircraft, IntegrateGroundReaction groundReaction, double heightAGL) {
    Vector3D aeroForceVector = new Vector3D(aero.calculateBodyForces(windParameters, angularRates, environmentParameters, controls, alphaDot, heightAGL));
    // Apache Commons vector methods only accept primitive double[] arrays
    Vector3D acVector = new Vector3D(aircraft.getAerodynamicCenter());
    Vector3D cgVector = new Vector3D(aircraft.getCenterOfGravity());
    Vector3D aeroForceCrossProd = Vector3D.crossProduct(aeroForceVector, acVector.subtract(cgVector));
    Vector3D aeroMomentVector = new Vector3D(aero.calculateAeroMoments(windParameters, angularRates, environmentParameters, controls, alphaDot));
    Vector3D groundMomentVector = new Vector3D(groundReaction.getTotalGroundMoments());
    // Create a vector of engine moment, iterate through engineList and add the moment of each engine in list
    Vector3D engineMoment = Vector3D.ZERO;
    for (Engine engine : engineList) engineMoment = engineMoment.add(new Vector3D(engine.getEngineMoment()));
    totalMoments = aeroMomentVector.add(engineMoment).add(aeroForceCrossProd).add(groundMomentVector).toArray();
    return SaturationUtilities.limitTotalMoments(totalMoments);
}
Also used : Vector3D(org.apache.commons.math3.geometry.euclidean.threed.Vector3D) Engine(com.chrisali.javaflightsim.simulation.propulsion.Engine)

Aggregations

Vector3D (org.apache.commons.math3.geometry.euclidean.threed.Vector3D)13 Engine (com.chrisali.javaflightsim.simulation.propulsion.Engine)2 File (java.io.File)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 TriangularFacet (net.imagej.ops.geom.geom3d.mesh.TriangularFacet)2 Vertex (net.imagej.ops.geom.geom3d.mesh.Vertex)2 RealPoint (net.imglib2.RealPoint)2 GeodeticPoint (org.orekit.bodies.GeodeticPoint)2 ZipJarCrawler (org.orekit.data.ZipJarCrawler)2 OrekitException (org.orekit.errors.OrekitException)2 Frame (org.orekit.frames.Frame)2 CartesianOrbit (org.orekit.orbits.CartesianOrbit)2 AbsoluteDate (org.orekit.time.AbsoluteDate)2 DateComponents (org.orekit.time.DateComponents)2 TimeComponents (org.orekit.time.TimeComponents)2 TimeScale (org.orekit.time.TimeScale)2 DefaultMesh (net.imagej.ops.geom.geom3d.mesh.DefaultMesh)1 Facet (net.imagej.ops.geom.geom3d.mesh.Facet)1 FinalInterval (net.imglib2.FinalInterval)1