Example usage for org.apache.commons.math.util FastMath pow

List of usage examples for org.apache.commons.math.util FastMath pow

Introduction

In this page you can find the example usage for org.apache.commons.math.util FastMath pow.

Prototype

public static double pow(double x, double y) 

Source Link

Document

Power function.

Usage

From source file:org.esa.nest.eo.GeoUtils.java

/**
 * Convert cartesian XYZ coordinate into geodetic coordinate with specified geodetic system.
 * @param xyz The xyz coordinate of the given pixel.
 * @param geoPos The geodetic coordinate of the given pixel.
 * @param geoSystem The geodetic system.
 */// w  w w .  j  a  va 2 s  . c  om
public static void xyz2geo(final double xyz[], final GeoPos geoPos, final EarthModel geoSystem) {

    double a = 0.0;
    double b = 0.0;
    double e2 = 0.0;
    double ep2 = 0.0;

    if (geoSystem == EarthModel.WGS84) {

        a = WGS84.a;
        b = WGS84.b;
        e2 = WGS84.e2;
        ep2 = WGS84.ep2;

    } else if (geoSystem == EarthModel.GRS80) {

        a = GRS80.a;
        b = GRS80.b;
        e2 = GRS80.e2;
        ep2 = GRS80.ep2;

    } else {
        throw new OperatorException("Incorrect geodetic system");
    }

    final double x = xyz[0];
    final double y = xyz[1];
    final double z = xyz[2];
    final double s = Math.sqrt(x * x + y * y);
    final double theta = FastMath.atan(z * a / (s * b));

    geoPos.lon = (float) (FastMath.atan(y / x) * org.esa.beam.util.math.MathUtils.RTOD);

    if (geoPos.lon < 0.0 && y >= 0.0) {
        geoPos.lon += 180.0;
    } else if (geoPos.lon > 0.0 && y < 0.0) {
        geoPos.lon -= 180.0;
    }

    geoPos.lat = (float) (FastMath
            .atan((z + ep2 * b * FastMath.pow(FastMath.sin(theta), 3))
                    / (s - e2 * a * FastMath.pow(FastMath.cos(theta), 3)))
            * org.esa.beam.util.math.MathUtils.RTOD);
}

From source file:org.esa.nest.eo.GeoUtils.java

/**
 * Convert cartesian XYZ coordinate into geodetic coordinate with specified geodetic system.
 * @param xyz The xyz coordinate of the given pixel.
 * @param geoPos The geodetic coordinate of the given pixel.
 *//*from  w ww  .  j  av a  2  s  .com*/
public static void xyz2geoWGS84(final double xyz[], final GeoPos geoPos) {

    final double x = xyz[0];
    final double y = xyz[1];
    final double z = xyz[2];
    final double s = Math.sqrt(x * x + y * y);
    final double theta = FastMath.atan(z * WGS84.a / (s * WGS84.b));

    geoPos.lon = (float) (FastMath.atan(y / x) * org.esa.beam.util.math.MathUtils.RTOD);

    if (geoPos.lon < 0.0 && y >= 0.0) {
        geoPos.lon += 180.0;
    } else if (geoPos.lon > 0.0 && y < 0.0) {
        geoPos.lon -= 180.0;
    }

    geoPos.lat = (float) (FastMath
            .atan((z + WGS84.ep2 * WGS84.b * FastMath.pow(FastMath.sin(theta), 3))
                    / (s - WGS84.e2 * WGS84.a * FastMath.pow(FastMath.cos(theta), 3)))
            * org.esa.beam.util.math.MathUtils.RTOD);
}

From source file:org.esa.nest.eo.GeoUtils.java

/**
 * Compute accurate target position for given orbit information using Newton's method.
 * @param data The orbit data./*from   ww w  .  j av  a  2 s  .  c o  m*/
 * @param xyz The xyz coordinate for the target.
 * @param time The slant range time in seconds.
 */
public static void computeAccurateXYZ(final Orbits.OrbitData data, final double[] xyz, final double time) {

    final double a = Constants.semiMajorAxis;
    final double b = Constants.semiMinorAxis;
    final double a2 = a * a;
    final double b2 = b * b;
    final double del = 0.001;
    final int maxIter = 10;

    Matrix X = new Matrix(3, 1);
    final Matrix F = new Matrix(3, 1);
    final Matrix J = new Matrix(3, 3);

    X.set(0, 0, xyz[0]);
    X.set(1, 0, xyz[1]);
    X.set(2, 0, xyz[2]);

    J.set(0, 0, data.xVel);
    J.set(0, 1, data.yVel);
    J.set(0, 2, data.zVel);

    final double time2 = FastMath.pow(time * Constants.halfLightSpeed, 2.0);
    for (int i = 0; i < maxIter; i++) {

        final double x = X.get(0, 0);
        final double y = X.get(1, 0);
        final double z = X.get(2, 0);

        final double dx = x - data.xPos;
        final double dy = y - data.yPos;
        final double dz = z - data.zPos;

        F.set(0, 0, data.xVel * dx + data.yVel * dy + data.zVel * dz);
        F.set(1, 0, dx * dx + dy * dy + dz * dz - time2);
        F.set(2, 0, x * x / a2 + y * y / a2 + z * z / b2 - 1);

        J.set(1, 0, 2.0 * dx);
        J.set(1, 1, 2.0 * dy);
        J.set(1, 2, 2.0 * dz);
        J.set(2, 0, 2.0 * x / a2);
        J.set(2, 1, 2.0 * y / a2);
        J.set(2, 2, 2.0 * z / b2);

        X = X.minus(J.inverse().times(F));

        if (Math.abs(F.get(0, 0)) <= del && Math.abs(F.get(1, 0)) <= del && Math.abs(F.get(2, 0)) <= del) {
            break;
        }
    }

    xyz[0] = X.get(0, 0);
    xyz[1] = X.get(1, 0);
    xyz[2] = X.get(2, 0);
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.particlefilter.ParticleFilter.java

public static double getEffectiveSampleSize(Multiset<Particle> particles)
        throws BadProbabilityParticleFilterException {
    double Wnorm = 0.0;
    for (final Multiset.Entry<Particle> p : particles.entrySet()) {
        final double weight = p.getElement().getWeight();
        Wnorm += weight * p.getCount();/*from w  ww.  j a  va2 s  .c  o  m*/
    }

    if (Wnorm == 0)
        return 0d;

    double Wvar = 0.0;
    for (final Multiset.Entry<Particle> p : particles.entrySet()) {
        final double weight = p.getElement().getWeight();
        Wvar += FastMath.pow(weight / Wnorm, 2) * p.getCount();
    }

    if (Double.isInfinite(Wvar) || Double.isNaN(Wvar))
        throw new BadProbabilityParticleFilterException("effective sample size numerical error: Wvar=" + Wvar);

    return 1 / Wvar;
}

From source file:org.renjin.gnur.api.Rmath.java

public static double R_pow(double x, double y) {
    return FastMath.pow(x, y);
}