Java atan2 atan2(double y, double x)

Here you can find the source of atan2(double y, double x)

Description

Converts rectangular coordinates (xy) to polar (r, theta).

License

Open Source License

Parameter

Parameter Description
y the ordinate coordinate
x the abscissa coordinate

Return

the theta component of the point (rtheta) in polar coordinates that corresponds to the point (xy) in Cartesian coordinates.

Declaration

public static double atan2(double y, double x) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w ww. ja v  a2s . co  m*/
     * Converts rectangular coordinates (<code>x</code>,&nbsp;<code>y</code>) to
     * polar (r,&nbsp;<i>theta</i>). This method computes the phase <i>theta</i>
     * by computing an arc tangent of <code>y/x</code> in the range of
     * -<i>pi</i> to <i>pi</i>. Special cases:
     * 
     * <ul>
     * <li>
     * If either argument is NaN, then the result is NaN.</li>
     * <li>
     * If the first argument is positive zero and the second argument is
     * positive, or the first argument is positive and finite and the second
     * argument is positive infinity, then the result is positive zero.</li>
     * <li>
     * If the first argument is negative zero and the second argument is
     * positive, or the first argument is negative and finite and the second
     * argument is positive infinity, then the result is negative zero.</li>
     * <li>
     * If the first argument is positive zero and the second argument is
     * negative, or the first argument is positive and finite and the second
     * argument is negative infinity, then the result is the <code>double</code>
     * value closest to <i>pi</i>.</li>
     * <li>
     * If the first argument is negative zero and the second argument is
     * negative, or the first argument is negative and finite and the second
     * argument is negative infinity, then the result is the <code>double</code>
     * value closest to -<i>pi</i>.</li>
     * <li>
     * If the first argument is positive and the second argument is positive
     * zero or negative zero, or the first argument is positive infinity and the
     * second argument is finite, then the result is the <code>double</code>
     * value closest to <i>pi</i>/2.</li>
     * <li>
     * If the first argument is negative and the second argument is positive
     * zero or negative zero, or the first argument is negative infinity and the
     * second argument is finite, then the result is the <code>double</code>
     * value closest to -<i>pi</i>/2.</li>
     * <li>
     * If both arguments are positive infinity, then the result is the
     * <code>double</code> value closest to <i>pi</i>/4.</li>
     * <li>
     * If the first argument is positive infinity and the second argument is
     * negative infinity, then the result is the <code>double</code> value
     * closest to 3<i>pi</i>/4.</li>
     * <li>
     * If the first argument is negative infinity and the second argument is
     * positive infinity, then the result is the <code>double</code> value
     * closest to -<i>pi</i>/4.</li>
     * <li>
     * If both arguments are negative infinity, then the result is the
     * <code>double</code> value closest to -3<i>pi</i>/4.</li>
     * </ul>
     * 
     * <p>
     * A result must be within 2 ulps of the correctly rounded result. Results
     * must be semi-monotonic.
     * </p>
     * 
     * @param y
     *            the ordinate coordinate
     * @param x
     *            the abscissa coordinate
     * 
     * @return the <i>theta</i> component of the point
     *         (<i>r</i>,&nbsp;<i>theta</i>) in polar coordinates that
     *         corresponds to the point (<i>x</i>,&nbsp;<i>y</i>) in Cartesian
     *         coordinates.
     */
    public static double atan2(double y, double x) {
        return Math.atan2(y, x);
    }
}

Related

  1. atan2(double arg1, double arg2)
  2. atan2(double x, double y)
  3. atan2(double y, double x)
  4. atan2(double y, double x)
  5. atan2(double y, double x)
  6. atan2(double[] arr1, double[] arr2)
  7. atan2(final double y, final double x)