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

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

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

Math.cos介绍

[英]Returns the closest double approximation of the cosine of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • cos(+infinity) = NaN
  • cos(-infinity) = NaN
  • cos(NaN) = NaN
    [中]返回参数余弦的最接近的双近似值。返回的结果在实际结果的1 ulp(最后一位的单位)范围内。
    特殊情况:
    *cos(+无穷大)=NaN
    *cos(-无穷大)=NaN
    *cos(NaN)=NaN

代码示例

代码示例来源:origin: PhilJay/MPAndroidChart

public float getInterpolation(float input) {
    return -(float) Math.cos(input * (Math.PI / 2f)) + 1f;
  }
};

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

public static double cos(double a){
 return Math.cos(a);
}

代码示例来源:origin: PhilJay/MPAndroidChart

public float getInterpolation(float input) {
    return -0.5f * ((float) Math.cos(Math.PI * input) - 1f);
  }
};

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

/** Rotates the Vector2 by the given angle, counter-clockwise assuming the y-axis points up.
 * @param radians the angle in radians */
public Vector2 rotateRad (float radians) {
  float cos = (float)Math.cos(radians);
  float sin = (float)Math.sin(radians);
  float newX = this.x * cos - this.y * sin;
  float newY = this.x * sin + this.y * cos;
  this.x = newX;
  this.y = newY;
  return this;
}

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

/** Sets the rotation of this transform
 * @param angle angle in radians */
public void setRotation (float angle) {
  float c = (float)Math.cos(angle), s = (float)Math.sin(angle);
  vals[COS] = c;
  vals[SIN] = s;
}

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

/** Rotates the Vector2 by the given angle, counter-clockwise assuming the y-axis points up.
 * @param radians the angle in radians */
public Vector2 rotateRad (float radians) {
  float cos = (float)Math.cos(radians);
  float sin = (float)Math.sin(radians);
  float newX = this.x * cos - this.y * sin;
  float newY = this.x * sin + this.y * cos;
  this.x = newX;
  this.y = newY;
  return this;
}

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

/** Sets the rotation of this transform
 * @param angle angle in radians */
public void setRotation (float angle) {
  float c = (float)Math.cos(angle), s = (float)Math.sin(angle);
  vals[COS] = c;
  vals[SIN] = s;
}

代码示例来源:origin: PhilJay/MPAndroidChart

public static void getPosition(MPPointF center, float dist, float angle, MPPointF outputPoint){
  outputPoint.x = (float) (center.x + dist * Math.cos(Math.toRadians(angle)));
  outputPoint.y = (float) (center.y + dist * Math.sin(Math.toRadians(angle)));
}

代码示例来源:origin: PhilJay/MPAndroidChart

public void getPosition(MPPointF center, float dist, float angle, MPPointF outputPoint) {
  outputPoint.x = (float) (center.x + dist * Math.cos(Math.toRadians(angle)));
  outputPoint.y = (float) (center.y + dist * Math.sin(Math.toRadians(angle)));
}

代码示例来源: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

private GreatCircleDistanceToPoint(double latitude, double longitude)
{
  double radianLatitude = toRadians(latitude);
  this.sinLatitude = sin(radianLatitude);
  this.cosLatitude = cos(radianLatitude);
  this.radianLongitude = toRadians(longitude);
}

代码示例来源: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: stackoverflow.com

public static float distFrom(float lat1, float lng1, float lat2, float lng2) {
 double earthRadius = 6371000; //meters
 double dLat = Math.toRadians(lat2-lat1);
 double dLng = Math.toRadians(lng2-lng1);
 double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
       Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
       Math.sin(dLng/2) * Math.sin(dLng/2);
 double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
 float dist = (float) (earthRadius * c);
 return dist;
 }

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

@Override
 protected ExprEval eval(double param)
 {
  return ExprEval.of(Math.cos(param));
 }
}

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

/** Sets the quaternion components from the given axis and angle around that axis.
 * @param x X direction of the axis
 * @param y Y direction of the axis
 * @param z Z direction of the axis
 * @param radians The angle in radians
 * @return This quaternion for chaining. */
public Quaternion setFromAxisRad (final float x, final float y, final float z, final float radians) {
  float d = Vector3.len(x, y, z);
  if (d == 0f) return idt();
  d = 1f / d;
  float l_ang = radians < 0 ? MathUtils.PI2 - (-radians % MathUtils.PI2) : radians % MathUtils.PI2;
  float l_sin = (float)Math.sin(l_ang / 2);
  float l_cos = (float)Math.cos(l_ang / 2);
  return this.set(d * x * l_sin, d * y * l_sin, d * z * l_sin, l_cos).nor();
}

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

/** Sets the quaternion components from the given axis and angle around that axis.
 * @param x X direction of the axis
 * @param y Y direction of the axis
 * @param z Z direction of the axis
 * @param radians The angle in radians
 * @return This quaternion for chaining. */
public Quaternion setFromAxisRad (final float x, final float y, final float z, final float radians) {
  float d = Vector3.len(x, y, z);
  if (d == 0f) return idt();
  d = 1f / d;
  float l_ang = radians < 0 ? MathUtils.PI2 - (-radians % MathUtils.PI2) : radians % MathUtils.PI2;
  float l_sin = (float)Math.sin(l_ang / 2);
  float l_cos = (float)Math.cos(l_ang / 2);
  return this.set(d * x * l_sin, d * y * l_sin, d * z * l_sin, l_cos).nor();
}

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

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

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

@Description("cosine")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double cos(@SqlType(StandardTypes.DOUBLE) double num)
{
  return Math.cos(num);
}

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

private void drawSolidCircle (Vector2 center, float radius, Vector2 axis, Color color) {
  float angle = 0;
  float angleInc = 2 * (float)Math.PI / 20;
  renderer.setColor(color.r, color.g, color.b, color.a);
  for (int i = 0; i < 20; i++, angle += angleInc) {
    v.set((float)Math.cos(angle) * radius + center.x, (float)Math.sin(angle) * radius + center.y);
    if (i == 0) {
      lv.set(v);
      f.set(v);
      continue;
    }
    renderer.line(lv.x, lv.y, v.x, v.y);
    lv.set(v);
  }
  renderer.line(f.x, f.y, lv.x, lv.y);
  renderer.line(center.x, center.y, 0, center.x + axis.x * radius, center.y + axis.y * radius, 0);
}

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

private void drawSolidCircle (Vector2 center, float radius, Vector2 axis, Color color) {
  float angle = 0;
  float angleInc = 2 * (float)Math.PI / 20;
  renderer.setColor(color.r, color.g, color.b, color.a);
  for (int i = 0; i < 20; i++, angle += angleInc) {
    v.set((float)Math.cos(angle) * radius + center.x, (float)Math.sin(angle) * radius + center.y);
    if (i == 0) {
      lv.set(v);
      f.set(v);
      continue;
    }
    renderer.line(lv.x, lv.y, v.x, v.y);
    lv.set(v);
  }
  renderer.line(f.x, f.y, lv.x, lv.y);
  renderer.line(center.x, center.y, 0, center.x + axis.x * radius, center.y + axis.y * radius, 0);
}

相关文章