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;
}
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));
}
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();
}
}
}
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();
}
}
}
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);
}
Aggregations