java.lang.Math.atan2()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中java.lang.Math.atan2()方法的一些代码示例,展示了Math.atan2()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.atan2()方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:atan2

Math.atan2介绍

[英]Returns the closest double approximation of the arc tangent of y/x within the range [-pi..pi]. This is the angle of the polar representation of the rectangular coordinates (x,y). The returned result is within 2 ulps (units in the last place) of the real result.

Special cases:

  • atan2((anything), NaN ) = NaN;
  • atan2(NaN , (anything) ) = NaN;
  • atan2(+0.0, +(anything but NaN)) = +0.0
  • atan2(-0.0, +(anything but NaN)) = -0.0
  • atan2(+0.0, -(anything but NaN)) = +pi
  • atan2(-0.0, -(anything but NaN)) = -pi
  • atan2(+(anything but 0 and NaN), 0) = +pi/2
  • atan2(-(anything but 0 and NaN), 0) = -pi/2
  • atan2(+(anything but infinity and NaN), +infinity) = +0.0
  • atan2(-(anything but infinity and NaN), +infinity) = -0.0
  • atan2(+(anything but infinity and NaN), -infinity) = +pi
  • atan2(-(anything but infinity and NaN), -infinity) = -pi
  • atan2(+infinity, +infinity ) = +pi/4
  • atan2(-infinity, +infinity ) = -pi/4
  • atan2(+infinity, -infinity ) = +3pi/4
  • atan2(-infinity, -infinity ) = -3pi/4
  • atan2(+infinity, (anything but,0, NaN, and infinity)) = +pi/2
  • atan2(-infinity, (anything but,0, NaN, and infinity)) = -pi/2
    [中]返回[-pi..pi]范围内y/x的反正切的最近双近似值。这是直角坐标(x,y)极坐标表示的角度。返回的结果与实际结果相差2 ULP(最后一位的单位)。
    特殊情况:
    *atan2((任何事物),NaN)=NaN;
    *atan2(NaN,(任何事物))=NaN;
    *atan2(+0.0,+(除NaN之外的任何内容))=+0.0
    *atan2(-0.0,+(除NaN以外的任何内容))=-0.0
    *atan2(+0.0,-(除NaN以外的任何值))=+pi
    *atan2(-0.0,-(除NaN以外的任何值))=-pi
    *atan2(+(除0和NaN外的任何内容),0)=+pi/2
    *atan2(-(除0和NaN之外的任何值),0)=-pi/2
    *atan2(+(除无穷大和NaN外的任何事物),+infinity)=+0.0
    *atan2(-(除无穷大和NaN外的任何事物),+infinity)=-0.0
    *atan2(+(除无穷大和NaN外的任何事物),-无穷大)=+pi
    *atan2(-(除无穷大和NaN之外的任何事物),-无穷大)=-pi
    *atan2(+无穷大,+无穷大)=+pi/4
    *atan2(-无穷大,+无穷大)=-pi/4
    *atan2(+无穷大,-无穷大)=+3pi/4
    *atan2(-无穷大,-无穷大)=-3pi/4
    *atan2(+无穷大,(除0、NaN和无穷大以外的任何值))=+pi/2
    *atan2(-infinity,(除0、NaN和infinity之外的任何值))=-pi/2

代码示例

代码示例来源:origin: libgdx/libgdx

/** @return the angle in degrees of this vector (point) relative to the x-axis. Angles are towards the positive y-axis
 *         (typically counter-clockwise) and between 0 and 360. */
public float angle () {
  float angle = (float)Math.atan2(y, x) * MathUtils.radiansToDegrees;
  if (angle < 0) angle += 360;
  return angle;
}

代码示例来源:origin: libgdx/libgdx

/** @return the angle in radians of this vector (point) relative to the x-axis. Angles are towards the positive y-axis.
 *         (typically counter-clockwise) */
public float angleRad () {
  return (float)Math.atan2(y, x);
}

代码示例来源:origin: libgdx/libgdx

/** @return the angle in degrees of this vector (point) relative to the x-axis. Angles are towards the positive y-axis
 *         (typically counter-clockwise) and between 0 and 360. */
public float angle () {
  float angle = (float)Math.atan2(y, x) * MathUtils.radiansToDegrees;
  if (angle < 0) angle += 360;
  return angle;
}

代码示例来源:origin: libgdx/libgdx

/** @return the angle in radians of this vector (point) relative to the x-axis. Angles are towards the positive y-axis.
 *         (typically counter-clockwise) */
public float angleRad () {
  return (float)Math.atan2(y, x);
}

代码示例来源:origin: libgdx/libgdx

public float getRotation () {
  return (float)Math.atan2(vals[SIN], vals[COS]);
}
/** @return A vector 2 pointing to where the body is facing */

代码示例来源:origin: libgdx/libgdx

public float getRotation () {
  return (float)Math.atan2(vals[SIN], vals[COS]);
}
/** @return A vector 2 pointing to where the body is facing */

代码示例来源:origin: libgdx/libgdx

public float getRotationRad () {
  return (float)Math.atan2(val[M10], val[M00]);
}

代码示例来源:origin: libgdx/libgdx

public float getRotationRad () {
  return (float)Math.atan2(val[M10], val[M00]);
}

代码示例来源:origin: libgdx/libgdx

public float getRotation () {
  return MathUtils.radiansToDegrees * (float)Math.atan2(val[M10], val[M00]);
}

代码示例来源:origin: libgdx/libgdx

public float getRotation () {
  return MathUtils.radiansToDegrees * (float)Math.atan2(val[M10], val[M00]);
}

代码示例来源:origin: libgdx/libgdx

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

代码示例来源:origin: stackoverflow.com

var rad = function(x) {
 return x * Math.PI / 180;
};

var getDistance = function(p1, p2) {
 var R = 6378137; // Earth’s mean radius in meter
 var dLat = rad(p2.lat() - p1.lat());
 var dLong = rad(p2.lng() - p1.lng());
 var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
  Math.cos(rad(p1.lat())) * Math.cos(rad(p2.lat())) *
  Math.sin(dLong / 2) * Math.sin(dLong / 2);
 var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
 var d = R * c;
 return d; // returns the distance in meter
};

代码示例来源:origin: prestodb/presto

public double distance(double latitude2, double longitude2)
  {
    double radianLatitude2 = toRadians(latitude2);
    double sin2 = sin(radianLatitude2);
    double cos2 = cos(radianLatitude2);
    double deltaLongitude = radianLongitude - toRadians(longitude2);
    double cosDeltaLongitude = cos(deltaLongitude);
    double t1 = cos2 * sin(deltaLongitude);
    double t2 = cosLatitude * sin2 - sinLatitude * cos2 * cosDeltaLongitude;
    double t3 = sinLatitude * sin2 + cosLatitude * cos2 * cosDeltaLongitude;
    return atan2(sqrt(t1 * t1 + t2 * t2), t3) * EARTH_RADIUS_KM;
  }
}

代码示例来源:origin: apache/incubator-druid

@Override
 protected ExprEval eval(double y, double x)
 {
  return ExprEval.of(Math.atan2(y, x));
 }
}

代码示例来源:origin: libgdx/libgdx

/** @return the angle in degrees of this vector (point) relative to the given vector. Angles are towards the positive y-axis
 *         (typically counter-clockwise.) between -180 and +180 */
public float angle (Vector2 reference) {
  return (float)Math.atan2(crs(reference), dot(reference)) * MathUtils.radiansToDegrees;
}

代码示例来源:origin: libgdx/libgdx

/** @return the angle in radians of this vector (point) relative to the given vector. Angles are towards the positive y-axis.
 *         (typically counter-clockwise.) */
public float angleRad (Vector2 reference) {
  return (float)Math.atan2(crs(reference), dot(reference));
}

代码示例来源:origin: libgdx/libgdx

/** @return the angle in radians of this vector (point) relative to the given vector. Angles are towards the positive y-axis.
 *         (typically counter-clockwise.) */
public float angleRad (Vector2 reference) {
  return (float)Math.atan2(crs(reference), dot(reference));
}

代码示例来源:origin: libgdx/libgdx

/** @return the angle in degrees of this vector (point) relative to the given vector. Angles are towards the positive y-axis
 *         (typically counter-clockwise.) between -180 and +180 */
public float angle (Vector2 reference) {
  return (float)Math.atan2(crs(reference), dot(reference)) * MathUtils.radiansToDegrees;
}

代码示例来源:origin: prestodb/presto

@Description("arc tangent of given fraction")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double atan2(@SqlType(StandardTypes.DOUBLE) double num1, @SqlType(StandardTypes.DOUBLE) double num2)
{
  return Math.atan2(num1, num2);
}

代码示例来源:origin: prestodb/presto

@Test
public void testAtan2()
{
  for (double doubleValue : DOUBLE_VALUES) {
    assertFunction("atan2(" + doubleValue + ", " + doubleValue + ")", DOUBLE, Math.atan2(doubleValue, doubleValue));
    assertFunction("atan2(REAL '" + (float) doubleValue + "', REAL '" + (float) doubleValue + "')", DOUBLE, Math.atan2((float) doubleValue, (float) doubleValue));
  }
  assertFunction("atan2(NULL, NULL)", DOUBLE, null);
  assertFunction("atan2(1.0E0, NULL)", DOUBLE, null);
  assertFunction("atan2(NULL, 1.0E0)", DOUBLE, null);
}

相关文章