Is angle in between two angles

前端 未结 4 1408
一整个雨季
一整个雨季 2020-12-20 07:08

I have 3 angles a b c

a=315 b=20 c=45

ok so would like to know giving all three if b is in between a and c

i have the long way of doing this adding a

4条回答
  •  一向
    一向 (楼主)
    2020-12-20 07:52

    I had a similar problem. I got it. All the calculations are in degrees. I needed to calculate id a gps location is inside a rectangle.

    Or, I needed to see if an angle x is between angle check+r and angle check-r.

    check-r.

    If you need a, find the angle check in the middle of a and b and then the distance (r) of check from a or b.

    The method normalize, changes the angles from -infinity...infinity to -180...180. The method check, takes the arguments x: the angle that we need to see if it is between the angles check-r and check+r. check: the angle to check with. r: the radius around angle check.

    private static double normalize(double x) {
            x = x % 360;
            if (x>=180) {
                return x-360;
            }
            if (x<-180) {
                return x+360;
            }
            return x;
    }
    public static boolean check(double x, double check, double r) {
            x = x - check;
            x = normalize(x);
            return x-r;
    }
    

提交回复
热议问题