List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D
public Vector3D(double x, double y, double z)
From source file:Engine.Player.java
public void AttackPlayer(Player p, WorldMap worldMap, Screen screen) { Vector3D vf = new Vector3D(ViewFrom[0], ViewFrom[1], ViewFrom[2]); Vector3D pp = AlgebraUtils.ReturnClosestWectorMirror(p.ViewFrom, ViewFrom, worldMap); //Vector3D pp = new Vector3D(p.ViewFrom[0], p.ViewFrom[1], p.ViewFrom[2]); Vector3D sv = pp.subtract(vf); screen.shoot(vf, sv, this); }
From source file:jtrace.object.transformation.Scale.java
@Override public Vector3D apply(Vector3D vec) { return new Vector3D(vec.getX() * scaleVec.getX(), vec.getY() * scaleVec.getY(), vec.getZ() * scaleVec.getZ()); }
From source file:jat.core.cm.TwoBodyAPL.java
@Override public void computeDerivatives(double t, double[] y, double[] yDot) { Vector3D r = new Vector3D(y[0], y[1], y[2]); double rnorm = r.getNorm(); double r3 = rnorm * rnorm * rnorm; double k = -1. * this.mu / r3; yDot[0] = y[3];/* www . j av a 2 s .c o m*/ yDot[1] = y[4]; yDot[2] = y[5]; yDot[3] = k * y[0]; yDot[4] = k * y[1]; yDot[5] = k * y[2]; }
From source file:jtrace.object.transformation.Scale.java
@Override public Vector3D applyInverse(Vector3D vec) { return new Vector3D(vec.getX() / scaleVec.getX(), vec.getY() / scaleVec.getY(), vec.getZ() / scaleVec.getZ()); }
From source file:edu.mit.fss.hla.FSScartesianVector.java
/** * Gets this vector as a {@link Vector3D} object. * * @return the value/*w ww.j a va 2s . co m*/ */ public Vector3D getValue() { return new Vector3D(x.getValue(), y.getValue(), z.getValue()); }
From source file:lambertmrev.Lambert.java
/** Constructs and solves a Lambert problem. * * \param[in] R1 first cartesian position * \param[in] R2 second cartesian position * \param[in] tof time of flight//ww w.j a va 2s .c om * \param[in] mu gravity parameter * \param[in] cw when 1 a retrograde orbit is assumed * \param[in] multi_revs maximum number of multirevolutions to compute */ public void lambert_problem(Vector3D r1, Vector3D r2, double tof, double mu, Boolean cw, int multi_revs) { // sanity checks if (tof <= 0) { System.out.println("ToF is negative! \n"); } if (mu <= 0) { System.out.println("mu is below zero"); } // 1 - getting lambda and T double m_c = FastMath.sqrt((r2.getX() - r1.getX()) * (r2.getX() - r1.getX()) + (r2.getY() - r1.getY()) * (r2.getY() - r1.getY()) + (r2.getZ() - r1.getZ()) * (r2.getZ() - r1.getZ())); double R1 = r1.getNorm(); double R2 = r2.getNorm(); double m_s = (m_c + R1 + R2) / 2.0; Vector3D ir1 = r1.normalize(); Vector3D ir2 = r2.normalize(); Vector3D ih = Vector3D.crossProduct(ir1, ir2); ih = ih.normalize(); if (ih.getZ() == 0) { System.out.println("angular momentum vector has no z component \n"); } double lambda2 = 1.0 - m_c / m_s; double m_lambda = FastMath.sqrt(lambda2); Vector3D it1 = new Vector3D(0.0, 0.0, 0.0); Vector3D it2 = new Vector3D(0.0, 0.0, 0.0); if (ih.getZ() < 0.0) { // Transfer angle is larger than 180 degrees as seen from abive the z axis m_lambda = -m_lambda; it1 = Vector3D.crossProduct(ir1, ih); it2 = Vector3D.crossProduct(ir2, ih); } else { it1 = Vector3D.crossProduct(ih, ir1); it2 = Vector3D.crossProduct(ih, ir2); } it1.normalize(); it2.normalize(); if (cw) { // Retrograde motion m_lambda = -m_lambda; it1.negate(); it2.negate(); } double lambda3 = m_lambda * lambda2; double T = FastMath.sqrt(2.0 * mu / m_s / m_s / m_s) * tof; // 2 - We now hava lambda, T and we will find all x // 2.1 - let us first detect the maximum number of revolutions for which there exists a solution int m_Nmax = FastMath.toIntExact(FastMath.round(T / FastMath.PI)); double T00 = FastMath.acos(m_lambda) + m_lambda * FastMath.sqrt(1.0 - lambda2); double T0 = (T00 + m_Nmax * FastMath.PI); double T1 = 2.0 / 3.0 * (1.0 - lambda3); double DT = 0.0; double DDT = 0.0; double DDDT = 0.0; if (m_Nmax > 0) { if (T < T0) { // We use Halley iterations to find xM and TM int it = 0; double err = 1.0; double T_min = T0; double x_old = 0.0, x_new = 0.0; while (true) { ArrayRealVector deriv = dTdx(x_old, T_min, m_lambda); DT = deriv.getEntry(0); DDT = deriv.getEntry(1); DDDT = deriv.getEntry(2); if (DT != 0.0) { x_new = x_old - DT * DDT / (DDT * DDT - DT * DDDT / 2.0); } err = FastMath.abs(x_old - x_new); if ((err < 1e-13) || (it > 12)) { break; } tof = x2tof(x_new, m_Nmax, m_lambda); x_old = x_new; it++; } if (T_min > T) { m_Nmax -= 1; } } } // We exit this if clause with Mmax being the maximum number of revolutions // for which there exists a solution. We crop it to multi_revs m_Nmax = FastMath.min(multi_revs, m_Nmax); // 2.2 We now allocate the memory for the output variables m_v1 = MatrixUtils.createRealMatrix(m_Nmax * 2 + 1, 3); RealMatrix m_v2 = MatrixUtils.createRealMatrix(m_Nmax * 2 + 1, 3); RealMatrix m_iters = MatrixUtils.createRealMatrix(m_Nmax * 2 + 1, 3); //RealMatrix m_x = MatrixUtils.createRealMatrix(m_Nmax*2+1, 3); ArrayRealVector m_x = new ArrayRealVector(m_Nmax * 2 + 1); // 3 - We may now find all solution in x,y // 3.1 0 rev solution // 3.1.1 initial guess if (T >= T00) { m_x.setEntry(0, -(T - T00) / (T - T00 + 4)); } else if (T <= T1) { m_x.setEntry(0, T1 * (T1 - T) / (2.0 / 5.0 * (1 - lambda2 * lambda3) * T) + 1); } else { m_x.setEntry(0, FastMath.pow((T / T00), 0.69314718055994529 / FastMath.log(T1 / T00)) - 1.0); } // 3.1.2 Householder iterations //m_iters.setEntry(0, 0, housOutTmp.getEntry(0)); m_x.setEntry(0, householder(T, m_x.getEntry(0), 0, 1e-5, 15, m_lambda)); // 3.2 multi rev solutions double tmp; double x0; for (int i = 1; i < m_Nmax + 1; i++) { // 3.2.1 left householder iterations tmp = FastMath.pow((i * FastMath.PI + FastMath.PI) / (8.0 * T), 2.0 / 3.0); m_x.setEntry(2 * i - 1, (tmp - 1) / (tmp + 1)); x0 = householder(T, m_x.getEntry(2 * i - 1), i, 1e-8, 15, m_lambda); m_x.setEntry(2 * i - 1, x0); //m_iters.setEntry(2*i-1, 0, housOutTmp.getEntry(0)); //3.2.1 right Householder iterations tmp = FastMath.pow((8.0 * T) / (i * FastMath.PI), 2.0 / 3.0); m_x.setEntry(2 * i, (tmp - 1) / (tmp + 1)); x0 = householder(T, m_x.getEntry(2 * i), i, 1e-8, 15, m_lambda); m_x.setEntry(2 * i, x0); //m_iters.setEntry(2*i, 0, housOutTmp.getEntry(0)); } // 4 - For each found x value we recontruct the terminal velocities double gamma = FastMath.sqrt(mu * m_s / 2.0); double rho = (R1 - R2) / m_c; double sigma = FastMath.sqrt(1 - rho * rho); double vr1, vt1, vr2, vt2, y; ArrayRealVector ir1_vec = new ArrayRealVector(3); ArrayRealVector ir2_vec = new ArrayRealVector(3); ArrayRealVector it1_vec = new ArrayRealVector(3); ArrayRealVector it2_vec = new ArrayRealVector(3); // set Vector3D values to a mutable type ir1_vec.setEntry(0, ir1.getX()); ir1_vec.setEntry(1, ir1.getY()); ir1_vec.setEntry(2, ir1.getZ()); ir2_vec.setEntry(0, ir2.getX()); ir2_vec.setEntry(1, ir2.getY()); ir2_vec.setEntry(2, ir2.getZ()); it1_vec.setEntry(0, it1.getX()); it1_vec.setEntry(1, it1.getY()); it1_vec.setEntry(2, it1.getZ()); it2_vec.setEntry(0, it2.getX()); it2_vec.setEntry(1, it2.getY()); it2_vec.setEntry(2, it2.getZ()); for (int i = 0; i < m_x.getDimension(); i++) { y = FastMath.sqrt(1.0 - lambda2 + lambda2 * m_x.getEntry(i) * m_x.getEntry(i)); vr1 = gamma * ((m_lambda * y - m_x.getEntry(i)) - rho * (m_lambda * y + m_x.getEntry(i))) / R1; vr2 = -gamma * ((m_lambda * y - m_x.getEntry(i)) + rho * (m_lambda * y + m_x.getEntry(i))) / R2; double vt = gamma * sigma * (y + m_lambda * m_x.getEntry(i)); vt1 = vt / R1; vt2 = vt / R2; for (int j = 0; j < 3; ++j) m_v1.setEntry(i, j, vr1 * ir1_vec.getEntry(j) + vt1 * it1_vec.getEntry(j)); for (int j = 0; j < 3; ++j) m_v2.setEntry(i, j, vr2 * ir2_vec.getEntry(j) + vt2 * it2_vec.getEntry(j)); } }
From source file:edu.mit.fss.examples.visual.gui.WorldWindVisualization.java
/** * Converts a NASA World Wind {@link Vec4} to an Apache Math Commons * {@link Vector3D}.// ww w. jav a2 s. com * * @param vector the NASA World Wind vector * @return the Apache Math Commons vector */ private static Vector3D convert(Vec4 vector) { return new Vector3D(vector.getX(), vector.getY(), vector.getZ()); }
From source file:edu.mit.fss.tutorial.part4.ControlPanel.java
/** * Instantiates a new control panel./*from ww w. ja v a 2 s. c o m*/ */ public ControlPanel() { setFocusable(true); // required for key listener setPreferredSize(new Dimension(300, 300)); setBackground(Color.white); // Add a new KeyAdapter object instance to bind actions to key presses. addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (boundElement == null) { // Do nothing if no element is bound. return; } if (e.getKeyCode() == KeyEvent.VK_UP) { // Increment Y-velocity. boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(0, 1, 0))); } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { // Decrement Y-velocity. boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(0, -1, 0))); } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { // Decrement X-velocity. boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(-1, 0, 0))); } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { // Increment X-velocity. boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(1, 0, 0))); } } }); }
From source file:lambertmrev.conversions.java
public static Vector3D radec2geo(Tracklet tracklet, double rho, TopocentricFrame staF, Frame inertialFrame, TimeScale utc) {// ww w . j a v a 2 s .co m double rho_k = rho * FastMath.sin(tracklet.getDEC()); double rho_j = rho * FastMath.cos(tracklet.getDEC()) * FastMath.sin(tracklet.getRA()); double rho_i = rho * FastMath.cos(tracklet.getDEC()) * FastMath.cos(tracklet.getRA()); Vector3D rho_vec = new Vector3D(rho_i, rho_j, rho_k); // System.out.println("rho used: " + rho_vec); AbsoluteDate year = new AbsoluteDate(Main.YEAR, utc); AbsoluteDate epoch = new AbsoluteDate(year, tracklet.getDOY() * 24 * 3600); Vector3D out = new Vector3D(0, 0, 0); try { // System.out.println("at epoch " + epoch + "\t the station is at: " + staF.getPVCoordinates(epoch, inertialFrame).getPosition()); out = rho_vec.add(staF.getPVCoordinates(epoch, inertialFrame).getPosition()); } catch (OrekitException e) { System.out.println("station coordinates not computed"); } return out; }
From source file:jtrace.object.Sphere.java
@Override public List<Vector3D[]> getWireFrameObjectFrame() { List<Vector3D[]> edgeList = new ArrayList<>(); int nLongitudeLines = 50; int nLongitudeSteps = 20; for (int i = 0; i < nLongitudeLines; i++) { double theta = 2 * Math.PI * i / nLongitudeLines; for (int j = 0; j < nLongitudeSteps; j++) { double phi = Math.PI * j / nLongitudeSteps; double phiNext = Math.PI * (j + 1) / nLongitudeSteps; Vector3D p = new Vector3D(Math.sin(phi) * Math.cos(theta), Math.sin(phi) * Math.sin(theta), Math.cos(phi)); Vector3D pNext = new Vector3D(Math.sin(phiNext) * Math.cos(theta), Math.sin(phiNext) * Math.sin(theta), Math.cos(phiNext)); Vector3D[] edge = { p, pNext }; edgeList.add(edge);//from w w w. j a va2s . c o m } } return edgeList; }