Example usage for java.lang Math atan2

List of usage examples for java.lang Math atan2

Introduction

In this page you can find the example usage for java.lang Math atan2.

Prototype

@HotSpotIntrinsicCandidate
public static double atan2(double y, double x) 

Source Link

Document

Returns the angle theta from the conversion of rectangular coordinates ( x ,  y ) to polar coordinates (r, theta).

Usage

From source file:be.ugent.maf.cellmissy.analysis.singlecell.processing.impl.interpolation.InterpolatedTrackOperatorImpl.java

@Override
public void computeTurningAngles(InterpolatedTrack interpolatedTrack) {
    // get the (already computed) delta movements of the interpolated track
    double[][] deltaMovements = interpolatedTrack.getDeltaMovements();
    double[] turningAngles = new double[deltaMovements.length];
    for (int row = 0; row < turningAngles.length; row++) {
        // angle = degrees(atan(deltaY/deltaX))
        double angleRadians = Math.atan2(deltaMovements[row][0], deltaMovements[row][1]);
        // go from radians to degrees
        turningAngles[row] = Math.toDegrees(angleRadians);
    }/*w  ww. j a  v a 2 s.c om*/
    interpolatedTrack.setTurningAngles(turningAngles);
}

From source file:jat.core.cm.TwoBodyAPL.java

public VectorN position(double t) {

    double[] temp = new double[6];

    // Determine step size
    double n = this.meanMotion();

    // determine initial E and M
    double sqrome2 = Math.sqrt(1.0 - this.e * this.e);
    double cta = Math.cos(this.ta);
    double sta = Math.sin(this.ta);
    double sine0 = (sqrome2 * sta) / (1.0 + this.e * cta);
    double cose0 = (this.e + cta) / (1.0 + this.e * cta);
    double e0 = Math.atan2(sine0, cose0);

    double ma = e0 - this.e * Math.sin(e0);

    ma = ma + n * t;/* w w w .  ja  va2 s . c om*/
    double ea = solveKepler(ma, this.e);

    double sinE = Math.sin(ea);
    double cosE = Math.cos(ea);
    double den = 1.0 - this.e * cosE;

    double sinv = (sqrome2 * sinE) / den;
    double cosv = (cosE - this.e) / den;

    this.ta = Math.atan2(sinv, cosv);
    if (this.ta < 0.0) {
        this.ta = this.ta + 2.0 * Constants.pi;
    }

    temp = this.randv();
    this.rv = new VectorN(temp);

    // Reset everything to before
    this.ta = initial_ta;

    VectorN out = new VectorN(3);
    out.x[0] = temp[0];
    out.x[1] = temp[1];
    out.x[2] = temp[2];
    // out.print("sat pos at t");
    return out;

}

From source file:com.opengamma.analytics.math.ComplexMathUtils.java

/**
 * Returns the principal value of log, with z the principal argument of z defined to lie in the interval (-pi, pi]
 * @param z ComplexNumber//from  w  w w . jav a 2  s.co  m
 * @return The log
 */
public static ComplexNumber log(final ComplexNumber z) {
    ArgumentChecker.notNull(z, "z");
    return new ComplexNumber(Math.log(Math.hypot(z.getReal(), z.getImaginary())),
            Math.atan2(z.getImaginary(), z.getReal()));
}

From source file:geogebra.kernel.GeoVec2D.java

final public double getPhi() {
    return Math.atan2(y, x);
}

From source file:com.androidquery.simplefeed.data.Place.java

public static double distFrom(double lat1, double lng1, double lat2, double lng2) {

    double earthRadius = 3958.75;
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;

    int meterConversion = 1609;
    return new Double(dist * meterConversion);

}

From source file:org.apache.flink.table.runtime.functions.SqlFunctionUtils.java

public static double atan2(Decimal y, Decimal x) {
    return Math.atan2(y.doubleValue(), x.doubleValue());
}

From source file:beans.BL.java

public void test(TPVObject tpv) {
    /**//from  w w w.  j ava2 s . c o  m
     * Neue Idee alles zu speichern
     */
    /*Umwandlung von Double in LDT Problem das es zu ungenau ist
     Double test = (tpv.getTimestamp());
     long int_timestamp = test.longValue();
     LocalDateTime ldt = LocalDateTime.ofEpochSecond(int_timestamp, 0, ZoneOffset.UTC);
     */

    System.out.println(
            tpv.getTimestamp() + " Longitude: " + tpv.getLatitude() + " Latitude: " + tpv.getLongitude());
    //TODO:
    /**
     * Algorithmus um die gefahrenen Km zu messen
     */

    if (tpv.getSpeed() > 2.77) {
        if (latOld == -1 && lonOld == -1) {
            latNew = tpv.getLatitude();
            lonNew = tpv.getLongitude();
        }
        latOld = latNew;
        lonOld = lonNew;
        latNew = tpv.getLatitude();
        lonNew = tpv.getLongitude();

        double R = 6371000; // metres

        double dLat = Math.toRadians(latNew - latOld);
        double dLon = Math.toRadians(lonNew - lonOld);
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(latOld))
                * Math.cos(Math.toRadians(latNew)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        d = d + (R * c);
        System.out.println("Distance:" + d + "Speed:" + tpv.getSpeed());
    }
    Point point = new Point(LocalDateTime.now(), tpv.getLatitude(), tpv.getLongitude(), d, tpv.getSpeed(),
            track);

    try {
        points.put(point);
    } catch (InterruptedException ex) {
        Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex);
    }

    try {
        System.out.println("points size:" + points.size());
        System.out.println("traks size:" + tracks.size());
        for (Track track1 : tracks) {
            System.out.println("track: " + track1.getId());
        }
        data_manager.writeFile(points);
    } catch (ParseException ex) {
        Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:uk.ac.diamond.scisoft.analysis.diffraction.powder.PixelIntegrationUtils.java

public static Dataset[] generateMinMaxAzimuthalArray(double[] beamCentre, int[] shape, double min) {
    //Number of circles
    int n = (int) Math.floor((min + 180) / 360);
    double minInBase = (min - (360 * n));
    Dataset aMax = DatasetFactory.zeros(shape, Dataset.FLOAT64);
    Dataset aMin = DatasetFactory.zeros(shape, Dataset.FLOAT64);

    PositionIterator iter = aMax.getPositionIterator();
    int[] pos = iter.getPos();
    double[] vals = new double[4];

    while (iter.hasNext()) {
        //find vals at pixel corners
        vals[0] = Math.toDegrees(Math.atan2(pos[0] - beamCentre[1], pos[1] - beamCentre[0]));
        vals[1] = Math.toDegrees(Math.atan2(pos[0] - beamCentre[1] + 1, pos[1] - beamCentre[0]));
        vals[2] = Math.toDegrees(Math.atan2(pos[0] - beamCentre[1], pos[1] - beamCentre[0] + 1));
        vals[3] = Math.toDegrees(Math.atan2(pos[0] - beamCentre[1] + 1, pos[1] - beamCentre[0] + 1));
        if (vals[0] < minInBase)
            vals[0] = vals[0] + 360;//from ww  w. j  a va2  s .c  o  m
        if (vals[1] < minInBase)
            vals[1] = vals[1] + 360;
        if (vals[2] < minInBase)
            vals[2] = vals[2] + 360;
        if (vals[3] < minInBase)
            vals[3] = vals[3] + 360;

        Arrays.sort(vals);
        //if the pixel needs to be split over 180 degrees, over the discontinuity
        //Only split up to the discontinuity on the side with the largest range
        //Should only change the single row of pixels allow the discontinuity
        //         (vals[0] < -Math.PI/2 && vals[3] > Math.PI/2)

        if (vals[3] - vals[0] > 180) {
            //FIXME do best to handle discontinuity here - saves changing the integration routine
            //may not be as accurate - might need to make the integration aware.
            //currently just squeeze all the signal in one side

            if ((minInBase + 360) - vals[3] > vals[0] - minInBase) {
                vals[0] = vals[3];
                vals[3] = minInBase + 360;
            } else {
                vals[3] = vals[0];
                vals[0] = minInBase;

            }
        }

        aMax.set(vals[3] + 360 * n, pos);
        aMin.set(vals[0] + 360 * n, pos);

    }

    return new Dataset[] { aMin, aMax };
}

From source file:uk.ac.diamond.scisoft.ncd.core.DegreeOfOrientation.java

public Object[] process(Serializable buffer, Serializable axis, final int[] dimensions) {

    double[] parentaxis = (double[]) ConvertUtils.convert(axis, double[].class);
    float[] parentdata = (float[]) ConvertUtils.convert(buffer, float[].class);

    int size = dimensions[dimensions.length - 1];
    double[] myaxis = new double[size];
    double[] mydata = new double[size];
    double[] cos2data = new double[size];
    double[] sin2data = new double[size];
    double[] sincosdata = new double[size];

    for (int i = 0; i < parentaxis.length; i++) {
        myaxis[i] = Math.toRadians(parentaxis[i]);
        mydata[i] = parentdata[i];//www  .  ja  v a 2  s .  c om
        float cos2alpha = (float) Math.cos(2.0 * myaxis[i]);
        float sin2alpha = (float) Math.sin(2.0 * myaxis[i]);
        cos2data[i] = (1.0f + cos2alpha) * parentdata[i] / 2.0;
        sin2data[i] = (1.0f - cos2alpha) * parentdata[i] / 2.0;
        sincosdata[i] = sin2alpha * parentdata[i] / 2.0;
    }

    UnivariateInterpolator interpolator = new SplineInterpolator();
    UnivariateFunction function = interpolator.interpolate(myaxis, mydata);
    UnivariateFunction cos2Function = interpolator.interpolate(myaxis, cos2data);
    UnivariateFunction sin2Function = interpolator.interpolate(myaxis, sin2data);
    UnivariateFunction sincosFunction = interpolator.interpolate(myaxis, sincosdata);

    UnivariateIntegrator integrator = new IterativeLegendreGaussIntegrator(15,
            BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY,
            BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY);

    try {
        float cos2mean = (float) integrator.integrate(INTEGRATION_POINTS, cos2Function, myaxis[0],
                myaxis[myaxis.length - 1]);
        float sin2mean = (float) integrator.integrate(INTEGRATION_POINTS, sin2Function, myaxis[0],
                myaxis[myaxis.length - 1]);
        float sincosmean = (float) integrator.integrate(INTEGRATION_POINTS, sincosFunction, myaxis[0],
                myaxis[myaxis.length - 1]);
        float norm = (float) integrator.integrate(INTEGRATION_POINTS, function, myaxis[0],
                myaxis[myaxis.length - 1]);

        cos2mean /= norm;
        sin2mean /= norm;
        sincosmean /= norm;

        float result = (float) Math.sqrt(Math.pow(cos2mean - sin2mean, 2) - 4.0 * sincosmean * sincosmean);
        double angle = MathUtils.normalizeAngle(Math.atan2(2.0 * sincosmean, cos2mean - sin2mean) / 2.0,
                Math.PI);

        Object[] output = new Object[] { new float[] { result }, new float[] { (float) Math.toDegrees(angle) },
                new float[] { (float) (result * Math.cos(angle)), (float) (result * Math.sin(angle)) }, };

        return output;

    } catch (TooManyEvaluationsException e) {
        return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } };
    } catch (MaxCountExceededException e) {
        return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } };
    }
}

From source file:org.opensha.commons.geo.LocationUtils.java

/**
 * Calculates the angle between two <code>Location</code>s using the <a
 * href="http://en.wikipedia.org/wiki/Haversine_formula" target="_blank">
 * Haversine</a> formula. This method properly handles values spanning
 * &#177;180&#176;. See <a//from  w w  w .j  av a  2s .  co  m
 * href="http://williams.best.vwh.net/avform.htm#Dist"> Aviation
 * Formulary</a> for source. Result is returned in radians.
 * 
 * @param p1 the first <code>Location</code> point
 * @param p2 the second <code>Location</code> point
 * @return the angle between the points (in radians)
 */
public static double angle(Location p1, Location p2) {
    double lat1 = p1.getLatRad();
    double lat2 = p2.getLatRad();
    double sinDlatBy2 = Math.sin((lat2 - lat1) / 2.0);
    double sinDlonBy2 = Math.sin((p2.getLonRad() - p1.getLonRad()) / 2.0);
    // half length of chord connecting points
    double c = (sinDlatBy2 * sinDlatBy2) + (Math.cos(lat1) * Math.cos(lat2) * sinDlonBy2 * sinDlonBy2);
    return 2.0 * Math.atan2(Math.sqrt(c), Math.sqrt(1 - c));
}