getDirection static method

String getDirection(
  1. double radians
)

获取标准8方向

Implementation

static String getDirection(double radians) {
  /// 判断8方向
  String direction = DFDirection.NONE;

  /// 换算角度
  double angle = 180 / pi * radians;
  if (angle < 0) {
    angle = angle + 360;
  }

  /// 顺时针 0~360
  /// print("angle:" + angle.toString());

  /// 右边
  if ((angle >= 0 && angle < 22.5) || (angle >= 337.5 && angle <= 360)) {
    direction = DFDirection.RIGHT;
  }

  /// 右下
  if (angle >= 22.5 && angle < 67.5) {
    direction = DFDirection.DOWN_RIGHT;
  }

  /// 下
  if (angle >= 67.5 && angle < 112.5) {
    direction = DFDirection.DOWN;
  }

  /// 左下
  if (angle >= 112.5 && angle < 157.5) {
    direction = DFDirection.DOWN_LEFT;
  }

  /// 左
  if (angle >= 157.5 && angle < 202.5) {
    direction = DFDirection.LEFT;
  }

  /// 左上
  if (angle >= 202.5 && angle < 247.5) {
    direction = DFDirection.UP_LEFT;
  }

  /// 上
  if (angle >= 247.5 && angle < 292.5) {
    direction = DFDirection.UP;
  }

  /// 右上
  if (angle >= 292.5 && angle < 337.5) {
    direction = DFDirection.UP_RIGHT;
  }

  /// 返回结果
  return direction;
}