Java Angle angleYawinRange(float start, float end, float angle)

Here you can find the source of angleYawinRange(float start, float end, float angle)

Description

Return whether a -180~180 wrapped yaw angle is in the range denoted by [start, end].

License

MIT License

Declaration

public static boolean angleYawinRange(float start, float end, float angle) 

Method Source Code

//package com.java2s;
/**/*  w  w w  .j  a v a  2  s.  com*/
* Copyright (c) Lambda Innovation, 2013-2016
* This file is part of LambdaLib modding library.
* https://github.com/LambdaInnovation/LambdaLib
* Licensed under MIT, see project root for more information.
*/

public class Main {
    /**
     * Return whether a -180~180 wrapped yaw angle is in the range denoted by [start, end].
     * Note that this is not a simple range comparison. If the arc of the angle is in the
     * range sweeped from start to end clockwisely, then the result is true.
     */
    public static boolean angleYawinRange(float start, float end, float angle) {
        if (end < start)
            return false;
        if (end - start >= 360f)
            return true;

        float ss = wrapYawAngle(start), se = wrapYawAngle(end), sa = wrapYawAngle(angle);

        if (ss > se) {
            return ss <= sa || sa <= se;
        }

        //System.out.println(ss + " " + se + " " + sa);
        return ss <= sa && sa <= se;
    }

    public static float wrapYawAngle(float a) {
        float ret = a % 360f;
        return ret < 0 ? ret + 360f : ret;
    }
}

Related

  1. angleSum(float a1, float a2)
  2. angleTo(final int x, final int y, final int thatx, final int thaty)
  3. angleToCompass(double angleIn)
  4. angleToDefaultAngle(double angle)
  5. angleToFacing(float angle)