use of org.apache.commons.math3.geometry.euclidean.threed.Vector3D in project j6dof-flight-sim by chris-ali.
the class AccelAndMoments method calculateLinearAccelerations.
/**
* Calculates the total linear acceleration experienced by the aircraft (ft/sec^2)
*
* @param windParameters
* @param angularRates
* @param environmentParameters
* @param controls
* @param alphaDot
* @param engineList
* @param aircraft
* @param groundReaction
* @param heightAGL
* @return linearAccelerations
*/
public static double[] calculateLinearAccelerations(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));
Vector3D groundForceVector = new Vector3D(groundReaction.getTotalGroundForces());
// Create a vector of engine force, iterate through engineList and add the thrust of each engine in list
Vector3D engineForceVector = Vector3D.ZERO;
for (Engine engine : engineList) engineForceVector = engineForceVector.add(new Vector3D(engine.getEngineThrust()));
linearAccelerations = aeroForceVector.add(engineForceVector).add(groundForceVector).scalarMultiply(1 / aircraft.getMassProperty(MassProperties.TOTAL_MASS)).toArray();
return SaturationUtilities.limitLinearAccelerations(linearAccelerations);
}
use of org.apache.commons.math3.geometry.euclidean.threed.Vector3D in project j6dof-flight-sim by chris-ali.
the class Engine method calculateEngMoments.
/**
* Calculates the moment generated by the engine as a function of its thrust and location
* relative to the aircraft's center of gravity. Used in {@link Engine#updateEngineState(EnumMap, EnumMap, double[])}
*/
protected void calculateEngMoments() {
Vector3D forceVector = new Vector3D(engineThrust);
Vector3D armVector = new Vector3D(enginePosition);
this.engineMoment = Vector3D.crossProduct(forceVector, armVector).toArray();
}
use of org.apache.commons.math3.geometry.euclidean.threed.Vector3D in project imagej-ops by imagej.
the class DefaultConvexHull3D method getV3.
/**
* Finds the point with the largest distance to the plane described by v0, v1,
* v2.
*
* @param v0 Vertex of the plane.
* @param v1 Vertex of the plane.
* @param v2 Vertex of the plane.
* @return Vertex with the largest distance.
*/
private Vertex getV3(final double epsilon, final Set<Vertex> vertices, final Vertex v0, final Vertex v1, final Vertex v2) {
double distPlanePoint = epsilon;
Vertex v3 = null;
Vector3D d0 = v1.subtract(v0);
Vector3D d1 = v2.subtract(v0);
Vector3D normal = d0.crossProduct(d1).normalize();
for (final Vertex v : vertices) {
double d = Math.abs(normal.dotProduct(v.subtract(v0)));
if (d > distPlanePoint) {
distPlanePoint = d;
v3 = v;
}
}
return v3;
}
use of org.apache.commons.math3.geometry.euclidean.threed.Vector3D in project imagej-ops by imagej.
the class DefaultConvexHull3D method getV2.
/**
* Finds the vertex with the largest distance to the line described by v0, v1.
*
* @param v0 Vertex of the line.
* @param v1 Vertex of the line.
* @return Vertex with the largest distance.
*/
private Vertex getV2(final double epsilon, final Set<Vertex> vertices, final Vertex v0, final Vertex v1) {
Iterator<Vertex> it = vertices.iterator();
// v0 -------------------------------------v1
// |
// | d
// |
// * v
//
// d = |(v - v0) x (v - v1)| / |(v1 - v0)|
// We can omit the common denominator because it does not change over
// all computations.
double distLinePoint = epsilon;
Vertex v2 = null;
while (it.hasNext()) {
Vertex v = it.next();
Vector3D d0 = v.subtract(v1);
Vector3D d1 = v.subtract(v0);
double lengthSq = d0.crossProduct(d1).getNormSq();
if (lengthSq > distLinePoint) {
distLinePoint = lengthSq;
v2 = v;
}
}
return v2;
}
use of org.apache.commons.math3.geometry.euclidean.threed.Vector3D in project imagej-ops by imagej.
the class DefaultInertiaTensor3DMesh method tetrahedronInertiaTensor.
/**
* The computations are based on this paper:
* http://docsdrive.com/pdfs/sciencepublications/jmssp/2005/8-11.pdf
*
* Note: In the paper b' and c' are swapped.
*
* @param p1
* triangular facet point
* @param p2
* triangular facet point
* @param p3
* triangular facet point
* @param cent
* of the mesh
* @return inertia tensor of this tetrahedron
*/
private BlockRealMatrix tetrahedronInertiaTensor(final RealLocalizable p1, final RealLocalizable p2, final RealLocalizable p3, final RealLocalizable cent) {
final double originX = cent.getDoublePosition(0);
final double originY = cent.getDoublePosition(1);
final double originZ = cent.getDoublePosition(2);
final double x1 = p1.getDoublePosition(0) - originX;
final double y1 = p1.getDoublePosition(1) - originY;
final double z1 = p1.getDoublePosition(2) - originZ;
final double x2 = p2.getDoublePosition(0) - originX;
final double y2 = p2.getDoublePosition(1) - originY;
final double z2 = p2.getDoublePosition(2) - originZ;
final double x3 = p3.getDoublePosition(0) - originX;
final double y3 = p3.getDoublePosition(1) - originY;
final double z3 = p3.getDoublePosition(2) - originZ;
final double volume = tetrahedronVolume(new Vector3D(x1, y1, z1), new Vector3D(x2, y2, z2), new Vector3D(x3, y3, z3));
final double a = 6 * volume * (y1 * y1 + y1 * y2 + y2 * y2 + y1 * y3 + y2 * y3 + y3 * y3 + z1 * z1 + z1 * z2 + z2 * z2 + z1 * z3 + z2 * z3 + z3 * z3) / 60.0;
final double b = 6 * volume * (x1 * x1 + x1 * x2 + x2 * x2 + x1 * x3 + x2 * x3 + x3 * x3 + z1 * z1 + z1 * z2 + z2 * z2 + z1 * z3 + z2 * z3 + z3 * z3) / 60.0;
final double c = 6 * volume * (x1 * x1 + x1 * x2 + x2 * x2 + x1 * x3 + x2 * x3 + x3 * x3 + y1 * y1 + y1 * y2 + y2 * y2 + y1 * y3 + y2 * y3 + y3 * y3) / 60.0;
final double aa = 6 * volume * (2 * y1 * z1 + y2 * z1 + y3 * z1 + y1 * z2 + 2 * y2 * z2 + y3 * z2 + y1 * z3 + y2 * z3 + 2 * y3 * z3) / 120.0;
final double bb = 6 * volume * (2 * x1 * y1 + x2 * y1 + x3 * y1 + x1 * y2 + 2 * x2 * y2 + x3 * y2 + x1 * y3 + x2 * y3 + 2 * x3 * y3) / 120.0;
final double cc = 6 * volume * (2 * x1 * z1 + x2 * z1 + x3 * z1 + x1 * z2 + 2 * x2 * z2 + x3 * z2 + x1 * z3 + x2 * z3 + 2 * x3 * z3) / 120.0;
final BlockRealMatrix t = new BlockRealMatrix(3, 3);
t.setRow(0, new double[] { a, -bb, -cc });
t.setRow(1, new double[] { -bb, b, -aa });
t.setRow(2, new double[] { -cc, -aa, c });
return t;
}
Aggregations