Java atan2 atan2(float y, float x)

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

Description

Returns atan2 in radians, faster but less accurate than Math.atan2.

License

Open Source License

Declaration

static public float atan2(float y, float x) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    static public final float PI = 3.1415927f;

    /** Returns atan2 in radians, faster but less accurate than Math.atan2. Average error of 0.00231 radians (0.1323 degrees),
     * largest error of 0.00488 radians (0.2796 degrees). */
    static public float atan2(float y, float x) {
        if (x == 0f) {
            if (y > 0f)
                return PI / 2;
            if (y == 0f)
                return 0f;
            return -PI / 2;
        }//from  w w  w  . java2 s  .  com
        final float atan, z = y / x;
        if (Math.abs(z) < 1f) {
            atan = z / (1f + 0.28f * z * z);
            if (x < 0f)
                return atan + (y < 0f ? -PI : PI);
            return atan;
        }
        atan = PI / 2 - z / (z * z + 0.28f);
        return y < 0f ? atan - PI : atan;
    }
}

Related

  1. atan2(double y, double x)
  2. atan2(double y, double x)
  3. atan2(double y, double x)
  4. atan2(double[] arr1, double[] arr2)
  5. atan2(final double y, final double x)
  6. atan2(Integer y, Integer x)
  7. atan2Scalar(double val, double[] arr)
  8. squareAtan2(float y, float x)