Refine search
/** Simple constructor. * Build a vector from its azimuthal coordinates * @param alpha azimuth (α) around Z * (0 is +X, π/2 is +Y, π is -X and 3π/2 is -Y) * @param delta elevation (δ) above (XY) plane, from -π/2 to +π/2 * @see #getAlpha() * @see #getDelta() */ public Vector3D(double alpha, double delta) { double cosDelta = FastMath.cos(delta); this.x = FastMath.cos(alpha) * cosDelta; this.y = FastMath.sin(alpha) * cosDelta; this.z = FastMath.sin(delta); }
static double bearing(Coordinate c1, Coordinate c2) { double deltaLon = (c2.x - c1.x) * FastMath.PI / 180; double lat1Radians = c1.y * FastMath.PI / 180; double lat2Radians = c2.y * FastMath.PI / 180; double y = FastMath.sin(deltaLon) * FastMath.cos(lat2Radians); double x = FastMath.cos(lat1Radians)*FastMath.sin(lat2Radians) - FastMath.sin(lat1Radians)*FastMath.cos(lat2Radians)*FastMath.cos(deltaLon); return FastMath.atan2(y, x); }
/** Build a spherical coordinates transformer from spherical coordinates. * @param r radius * @param theta azimuthal angle in x-y plane * @param phi polar (co-latitude) angle */ public SphericalCoordinates(final double r, final double theta, final double phi) { final double cosTheta = FastMath.cos(theta); final double sinTheta = FastMath.sin(theta); final double cosPhi = FastMath.cos(phi); final double sinPhi = FastMath.sin(phi); // spherical coordinates this.r = r; this.theta = theta; this.phi = phi; // Cartesian coordinates this.v = new Vector3D(r * cosTheta * sinPhi, r * sinTheta * sinPhi, r * cosPhi); }
/** Get a circle point from its phase around the circle. * @param alpha phase around the circle * @return circle point on the sphere * @see #toSpace(Point) * @see #getXAxis() * @see #getYAxis() */ public Vector3D getPointAt(final double alpha) { return new Vector3D(FastMath.cos(alpha), x, FastMath.sin(alpha), y); }
/** Build the normalized vector corresponding to spherical coordinates. * @param theta azimuthal angle \( \theta \) in the x-y plane * @param phi polar angle \( \varphi \) * @return normalized vector * @exception OutOfRangeException if \( \varphi \) is not in the [\( 0; \pi \)] range */ private static Vector3D vector(final double theta, final double phi) throws OutOfRangeException { if (phi < 0 || phi > FastMath.PI) { throw new OutOfRangeException(phi, 0, FastMath.PI); } final double cosTheta = FastMath.cos(theta); final double sinTheta = FastMath.sin(theta); final double cosPhi = FastMath.cos(phi); final double sinPhi = FastMath.sin(phi); return new Vector3D(cosTheta * sinPhi, sinTheta * sinPhi, cosPhi); }
public static final double distance(double lat1, double lon1, double lat2, double lon2, double radius) { // http://en.wikipedia.org/wiki/Great-circle_distance lat1 = toRadians(lat1); // Theta-s lon1 = toRadians(lon1); // Lambda-s lat2 = toRadians(lat2); // Theta-f lon2 = toRadians(lon2); // Lambda-f double deltaLon = lon2 - lon1; double y = sqrt(p2(cos(lat2) * sin(deltaLon)) + p2(cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(deltaLon))); double x = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(deltaLon); return radius * atan2(y, x); }
/** Compute sine of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * sine the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void sin(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; function[0] = FastMath.sin(operand[operandOffset]); if (order > 0) { function[1] = FastMath.cos(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = -function[i - 2]; } } // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
/** Compute cosine of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * cosine the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void cos(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; function[0] = FastMath.cos(operand[operandOffset]); if (order > 0) { function[1] = -FastMath.sin(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = -function[i - 2]; } } // apply function composition compose(operand, operandOffset, function, result, resultOffset); }