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

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

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

Math.toDegrees介绍

[英]Returns the measure in degrees of the supplied radian angle. The result is angrad * 180 / pi.

Special cases:

  • toDegrees(+0.0) = +0.0
  • toDegrees(-0.0) = -0.0
  • toDegrees(+infinity) = +infinity
  • toDegrees(-infinity) = -infinity
  • toDegrees(NaN) = NaN
    [中]

代码示例

代码示例来源:origin: google/ExoPlayer

private float calculateFieldOfViewInYDirection(float aspect) {
  boolean landscapeMode = aspect > 1;
  if (landscapeMode) {
   double halfFovX = FIELD_OF_VIEW_DEGREES / 2;
   double tanY = Math.tan(Math.toRadians(halfFovX)) / aspect;
   double halfFovY = Math.toDegrees(Math.atan(tanY));
   return (float) (halfFovY * 2);
  } else {
   return FIELD_OF_VIEW_DEGREES;
  }
 }
}

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

public float getAngle(Point target) {
  float angle = (float) Math.toDegrees(Math.atan2(target.y - y, target.x - x));

  if(angle < 0){
    angle += 360;
  }

  return angle;
}

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

private void updateOrientation () {
  if (rotationVectorAvailable){
    SensorManager.getRotationMatrixFromVector(R, rotationVectorValues);
  } else if (!SensorManager.getRotationMatrix(R, null, accelerometerValues, magneticFieldValues)) {
      return; // compass + accelerometer in free fall
  }
  SensorManager.getOrientation(R, orientation);
  azimuth = (float)Math.toDegrees(orientation[0]);
  pitch = (float)Math.toDegrees(orientation[1]);
  roll = (float)Math.toDegrees(orientation[2]);
}

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

private void updateOrientation () {
  if (rotationVectorAvailable){
    SensorManager.getRotationMatrixFromVector(R, rotationVectorValues);
  } else if (!SensorManager.getRotationMatrix(R, null, accelerometerValues, magneticFieldValues)) {
      return; // compass + accelerometer in free fall
  }
  SensorManager.getOrientation(R, orientation);
  azimuth = (float)Math.toDegrees(orientation[0]);
  pitch = (float)Math.toDegrees(orientation[1]);
  roll = (float)Math.toDegrees(orientation[2]);
}

代码示例来源:origin: Yalantis/uCrop

private float calculateAngleBetweenLines(float fx1, float fy1, float fx2, float fy2,
                     float sx1, float sy1, float sx2, float sy2) {
  return calculateAngleDelta(
      (float) Math.toDegrees((float) Math.atan2((fy1 - fy2), (fx1 - fx2))),
      (float) Math.toDegrees((float) Math.atan2((sy1 - sy2), (sx1 - sx2))));
}

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

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

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

private static double addDistanceToLatitude(
    @SqlType(StandardTypes.DOUBLE) double latitude,
    @SqlType(StandardTypes.DOUBLE) double radiusInKm,
    @SqlType(StandardTypes.DOUBLE) double bearing)
{
  double latitudeInRadians = toRadians(latitude);
  double bearingInRadians = toRadians(bearing);
  double radiusRatio = radiusInKm / EARTH_RADIUS_KM;
  // Haversine formula
  double newLatitude = toDegrees(asin(sin(latitudeInRadians) * cos(radiusRatio) +
      cos(latitudeInRadians) * sin(radiusRatio) * cos(bearingInRadians)));
  if (newLatitude > MAX_LATITUDE) {
    return MAX_LATITUDE;
  }
  if (newLatitude < MIN_LATITUDE) {
    return MIN_LATITUDE;
  }
  return newLatitude;
}

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

/**
 * returns the angle relative to the chart center for the given point on the
 * chart in degrees. The angle is always between 0 and 360°, 0° is NORTH,
 * 90° is EAST, ...
 *
 * @param x
 * @param y
 * @return
 */
public float getAngleForPoint(float x, float y) {
  MPPointF c = getCenterOffsets();
  double tx = x - c.x, ty = y - c.y;
  double length = Math.sqrt(tx * tx + ty * ty);
  double r = Math.acos(ty / length);
  float angle = (float) Math.toDegrees(r);
  if (x > c.x)
    angle = 360f - angle;
  // add 90° because chart starts EAST
  angle = angle + 90f;
  // neutralize overflow
  if (angle > 360f)
    angle = angle - 360f;
  MPPointF.recycleInstance(c);
  return angle;
}

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

private static double addDistanceToLongitude(
    @SqlType(StandardTypes.DOUBLE) double latitude,
    @SqlType(StandardTypes.DOUBLE) double longitude,
    @SqlType(StandardTypes.DOUBLE) double radiusInKm,
    @SqlType(StandardTypes.DOUBLE) double bearing)
{
  double latitudeInRadians = toRadians(latitude);
  double longitudeInRadians = toRadians(longitude);
  double bearingInRadians = toRadians(bearing);
  double radiusRatio = radiusInKm / EARTH_RADIUS_KM;
  // Haversine formula
  double newLongitude = toDegrees(longitudeInRadians +
      atan2(sin(bearingInRadians) * sin(radiusRatio) * cos(latitudeInRadians),
          cos(radiusRatio) - sin(latitudeInRadians) * sin(latitudeInRadians)));
  if (newLongitude > MAX_LONGITUDE) {
    return MIN_LONGITUDE + (newLongitude - MAX_LONGITUDE);
  }
  if (newLongitude < MIN_LONGITUDE) {
    return MAX_LONGITUDE + (newLongitude - MIN_LONGITUDE);
  }
  return newLongitude;
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public float getDaylight() {
  float angle = (float) Math.toDegrees(TeraMath.clamp(Math.cos(getSunPositionAngle())));
  float daylight = 1.0f;
  if (angle < 24.0f) {
    daylight = 1.0f - (24.0f - angle) / 24.0f;
  }
  return daylight;
}

代码示例来源:origin: google/j2objc

public static @degrees double toDegrees(@radians double angrad) { return Math.toDegrees(angrad); }

代码示例来源:origin: apache/hive

@Override
protected DoubleWritable doEvaluate(DoubleWritable a) {
 result.set(Math.toDegrees(a.get()));
 return result;
}

代码示例来源:origin: google/ExoPlayer

private static float[] createRotationMatrix(float angleRadian, int x, int y, int z) {
 float[] expectedMatrix = new float[16];
 Matrix.setRotateM(expectedMatrix, 0, (float) Math.toDegrees(angleRadian), x, y, z);
 return expectedMatrix;
}

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

public static DoubleValue toDegrees( AnyValue in )
{
  if ( in instanceof NumberValue )
  {
    return doubleValue( Math.toDegrees( ((NumberValue) in).doubleValue() ) );
  }
  else
  {
    throw needsNumbers( "toDegrees()" );
  }
}

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

@Test
public void testDegrees()
{
  for (double doubleValue : DOUBLE_VALUES) {
    assertFunction(String.format("degrees(%s)", doubleValue), DOUBLE, Math.toDegrees(doubleValue));
    assertFunction(String.format("degrees(REAL '%s')", (float) doubleValue), DOUBLE, Math.toDegrees((float) doubleValue));
  }
  assertFunction("degrees(NULL)", DOUBLE, null);
}

代码示例来源:origin: google/ExoPlayer

private static void getRotationMatrixFromAngleAxis(float[] matrix, float[] angleAxis) {
  // Convert coordinates to OpenGL coordinates.
  // CAMM motion metadata: +x right, +y down, and +z forward.
  // OpenGL: +x right, +y up, -z forwards
  float x = angleAxis[0];
  float y = -angleAxis[1];
  float z = -angleAxis[2];
  float angleRad = Matrix.length(x, y, z);
  if (angleRad != 0) {
   float angleDeg = (float) Math.toDegrees(angleRad);
   Matrix.setRotateM(matrix, 0, angleDeg, x / angleRad, y / angleRad, z / angleRad);
  } else {
   Matrix.setIdentityM(matrix, 0);
  }
 }
}

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

@Description("converts an angle in radians to degrees")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double degrees(@SqlType(StandardTypes.DOUBLE) double radians)
{
  return Math.toDegrees(radians);
}

代码示例来源:origin: jfoenixadmin/JFoenix

private void goToTime(LocalTime time) {
  if (time != null) {
    int hour = time.getHour();
    selectedHourLabel.setText(Integer.toString(hour % (is24HourView ? 24 : 12) == 0 ?
      (is24HourView ? 0 : 12) : hour % (is24HourView ? 24 : 12)));
    selectedMinLabel.setText(unitConverter.toString(time.getMinute()));
    if (!is24HourView) {
      period.set(hour < 12 ? "AM" : "PM");
    }
    minsPointerRotate.setAngle(180 + (time.getMinute() + 45) % 60 * Math.toDegrees(2 * Math.PI / 60));
    hoursPointerRotate.setAngle(180 + Math.toDegrees(2 * (hour - 3) * Math.PI / 12));
    _24HourHoursPointerRotate.setAngle(180 + Math.toDegrees(2 * (hour - 3) * Math.PI / 12));
  }
}

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

private void renderBox (Body body, float halfWidth, float halfHeight) {
  // get the bodies center and angle in world coordinates
  Vector2 pos = body.getWorldCenter();
  float angle = body.getAngle();
  // set the translation and rotation matrix
  transform.setToTranslation(pos.x, pos.y, 0);
  transform.rotate(0, 0, 1, (float)Math.toDegrees(angle));
  // render the box
  renderer.begin(ShapeType.Line);
  renderer.setTransformMatrix(transform);
  renderer.setColor(1, 1, 1, 1);
  renderer.rect(-halfWidth, -halfHeight, halfWidth * 2, halfHeight * 2);
  renderer.end();
}

代码示例来源:origin: apache/hive

@Test
public void testVectorDegrees() throws HiveException {
 VectorizedRowBatch b = getVectorizedRowBatchDoubleInDoubleOut();
 DoubleColumnVector resultV = (DoubleColumnVector) b.cols[1];
 b.cols[0].noNulls = true;
 VectorExpression expr = new FuncDegreesDoubleToDouble(0, 1);
 expr.evaluate(b);
 Assert.assertEquals(Math.toDegrees(0.5d), resultV.vector[4]);
}

相关文章