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:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void atan2PiPiHalf() {
    try {/*from w  w  w  .j  a v  a  2 s . co m*/
        Expression expression = getExpressionWithFunctionContext("atan2(pi,pi/2)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.atan2(Math.PI, Math.PI / 2), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void atan2PiHalfPi() {
    try {//from   w ww  . j ava2  s .co m
        Expression expression = getExpressionWithFunctionContext("atan2(pi/2,pi)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.atan2(Math.PI / 2, Math.PI), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void atan2PiHalfPiHalf() {
    try {/* w  w w  .j  av  a2 s.  co  m*/
        Expression expression = getExpressionWithFunctionContext("atan2(pi/2,pi/2)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.atan2(Math.PI / 2, Math.PI / 2), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:msi.gaml.operators.Maths.java

@operator(value = "atan2", can_be_const = true, category = { IOperatorCategory.ARITHMETIC })
@doc(value = "the atan2 value of the two operands.", comment = "The function atan2 is the arctangent function with two arguments. The purpose of using two arguments instead of one is to gather information on the signs of the inputs in order to return the appropriate quadrant of the computed angle, which is not possible for the single-argument arctangent function.", masterDoc = true, examples = @example(value = "atan2 (0,0)", equals = "0.0"), see = {
        "atan", "acos", "asin" })
public static double atan2(final double y, final double x) {
    return Math.atan2(y, x) * toDeg;
}

From source file:civilisation.individu.Humain.java

/**
 * Return the angle towards the specified patch
 *//*w ww. j  a  v  a2 s .c om*/
public double towards(Patch p) {
    double dx = p.x - xcor();
    double dy = -(p.y - ycor());
    double inRads = Math.atan2(dy, dx);

    if (inRads < 0)
        inRads = Math.abs(inRads);
    else
        inRads = 2 * Math.PI - inRads;

    return Math.toDegrees(inRads);
}

From source file:gdsc.utils.Cell_Outliner.java

/**
 * Estimate the starting ellipse using the eccentricity around the central moments
 * <p>//from   w  w  w .  j a va2  s  .  c  o  m
 * 
 * @see Burger & Burge, Digital Image Processing, An Algorithmic Introduction using Java (1st Edition), pp231
 * 
 * @param roi
 * @param height
 * @param width
 * @return
 */
private double[] estimateStartPoint(PolygonRoi roi, int width, int height) {
    ByteProcessor ip = createFilledCell(width, height, roi);
    byte[] data = (byte[]) ip.getPixels();

    //// Default processing
    //double m00 = moment(ip, 0, 0); // region area
    //double xCtr = moment(ip, 1, 0) / m00;
    //double yCtr = moment(ip, 0, 1) / m00;
    //
    //double u00 = m00; //centralMoment(ip, 0, 0);
    //double u11 = centralMoment(ip, 1, 1);
    //double u20 = centralMoment(ip, 2, 0);
    //double u02 = centralMoment(ip, 0, 2);

    // Speed up processing of the moments
    double u00 = 0;
    for (byte b : data)
        if (b != 0)
            u00++;

    double xCtr = 0, yCtr = 0;
    for (int v = 0, i = 0; v < ip.getHeight(); v++) {
        for (int u = 0; u < ip.getWidth(); u++, i++) {
            if (data[i] != 0) {
                xCtr += u;
                yCtr += v;
            }
        }
    }
    xCtr /= u00;
    yCtr /= u00;

    double u11 = 0;
    double u20 = 0;
    double u02 = 0;
    for (int v = 0, i = 0; v < ip.getHeight(); v++) {
        for (int u = 0; u < ip.getWidth(); u++, i++) {
            if (data[i] != 0) {
                double dx = u - xCtr;
                double dy = v - yCtr;
                u11 += dx * dy;
                u20 += dx * dx;
                u02 += dy * dy;
            }
        }
    }

    // Calculate the ellipsoid
    double A = 2 * u11;
    double B = u20 - u02;

    double angle = 0.5 * Math.atan2(A, B);

    double a1 = u20 + u02 + Math.sqrt((u20 - u02) * (u20 - u02) + 4 * u11 * u11);
    double a2 = u20 + u02 - Math.sqrt((u20 - u02) * (u20 - u02) + 4 * u11 * u11);

    double ra = Math.sqrt(2 * a1 / u00);
    double rb = Math.sqrt(2 * a2 / u00);

    double[] params = new double[] { xCtr, yCtr, ra, ra, rb, angle };

    if (debug) {
        EllipticalCell cell = new EllipticalCell();
        FloatPolygon ellipse = cell.drawEllipse(params);
        ip = createFilledCell(width, height,
                new PolygonRoi(ellipse.xpoints, ellipse.ypoints, ellipse.npoints, PolygonRoi.POLYGON));
        ip.setMinAndMax(0, CELL);
        displayImage(ip, "Start estimate");
    }

    return params;
}

From source file:civilisation.individu.Humain.java

/**
 * Return the angle towards the specified patch coordinates
 *///from  www  .j a  v  a  2 s  . co m
public double towards(int x, int y) {
    double dx = x - xcor();
    double dy = -(y - ycor());
    double inRads = Math.atan2(dy, dx);

    if (inRads < 0)
        inRads = Math.abs(inRads);
    else
        inRads = 2 * Math.PI - inRads;

    return Math.toDegrees(inRads);
}

From source file:lineage2.gameserver.model.Creature.java

/**
 * Method calcHeading./*from w w w  . j ava2s.c om*/
 * @param x_dest int
 * @param y_dest int
 * @return int
 */
public int calcHeading(int x_dest, int y_dest) {
    return (int) (Math.atan2(getY() - y_dest, getX() - x_dest) * HEADINGS_IN_PI) + 32768;
}

From source file:Rotation.java

/** Get the azimuth of the vector.
 * @return azimuth (&alpha;) of the vector, between -&pi; and +&pi;
 * @see #Vector3D(double, double)//  ww w .  j  av a  2 s . c  om
 */
public double getAlpha() {
    return Math.atan2(y, x);
}

From source file:foodsimulationmodel.pathmapping.Route.java

/**
 * Returns the angle of the vector from p0 to p1 relative to the x axis
 * <p>//from   w ww . jav a  2  s .c  om
 * The angle will be between -Pi and Pi. I got this directly from the JUMP program source.
 * 
 * @return the angle (in radians) that p0p1 makes with the positive x-axis.
 */
public static synchronized double angle(Coordinate p0, Coordinate p1) {
    double dx = p1.x - p0.x;
    double dy = p1.y - p0.y;

    return Math.atan2(dy, dx);
}