Here you can find the source of atan2(double y, double x)
x
, y
) to polar (r, theta).
Parameter | Description |
---|---|
y | the ordinate coordinate |
x | the abscissa coordinate |
public static double atan2(double y, double x)
//package com.java2s; public class Main { /**/*from w ww. ja v a2s . co m*/ * Converts rectangular coordinates (<code>x</code>, <code>y</code>) to * polar (r, <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>, <i>theta</i>) in polar coordinates that * corresponds to the point (<i>x</i>, <i>y</i>) in Cartesian * coordinates. */ public static double atan2(double y, double x) { return Math.atan2(y, x); } }