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

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

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

Math.sin介绍

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

Special cases:

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

代码示例

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

public float getInterpolation(float input) {
    return (float) Math.sin(input * (Math.PI / 2f));
  }
};

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

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

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

/** 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: scwang90/SmartRefreshLayout

@Override
  public float getInterpolation(float t) {
    if (t == 0) return 0;
    if (t >= 1) return 1;
    float p=.3f;
    float s=p/4;
    return ((float)Math.pow(2,-10*t) * (float)Math.sin( (t-s)*(2*(float)Math.PI)/p) + 1);
  }
}

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

public float getInterpolation(float input) {
    if (input == 0) {
      return 0f;
    } else if (input == 1) {
      return 1f;
    }
    float p = 0.3f;
    float s = p / DOUBLE_PI * (float) Math.asin(1f);
    return -((float) Math.pow(2f, 10f * (input -= 1f))
        *(float) Math.sin((input - s) * DOUBLE_PI / p));
  }
};

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

public float getInterpolation(float input) {
    if (input == 0) {
      return 0f;
    } else if (input == 1) {
      return 1f;
    }
    float p = 0.3f;
    float s = p / DOUBLE_PI * (float) Math.asin(1f);
    return 1f
        + (float) Math.pow(2f, -10f * input)
        * (float) Math.sin((input - s) * DOUBLE_PI / p);
  }
};

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

private static void squigglyHorizontalPath(Path path, float left, float right, float centerY,
   float amplitude,
   float periodDegrees) {
  path.reset();

  float y;
  path.moveTo(left, centerY);
  float period = (float) (2 * Math.PI / periodDegrees);

  for (float x = 0; x <= right - left; x += 1) {
   y = (float) (amplitude * Math.sin(40 + period * x) + centerY);
   path.lineTo(left + x, y);
  }
 }
}

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

private static int longitudeToTileY(double latitude, long mapSize)
{
  double sinLatitude = Math.sin(latitude * Math.PI / 180);
  double y = 0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);
  return axisToCoordinates(y, mapSize);
}

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

@Override
 protected ExprEval eval(double param)
 {
  return ExprEval.of(Math.sin(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 testSin()
{
  for (double doubleValue : DOUBLE_VALUES) {
    assertFunction("sin(" + doubleValue + ")", DOUBLE, Math.sin(doubleValue));
    assertFunction("sin(REAL '" + (float) doubleValue + "')", DOUBLE, Math.sin((float) doubleValue));
  }
  assertFunction("sin(NULL)", DOUBLE, null);
}

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

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

相关文章