角度在两个角度之间 [英] Is angle in between two angles

查看:96
本文介绍了角度在两个角度之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个角度a b c

a = 315 b = 20 c = 45

好,如果b在a和c之间,那么我想知道全部给出三个

我做这种加法和减法有很长的路要走.我只想得到更小,也许更高效的产品.

谢谢

编辑

这是我要说的照片.

好吧,我的角度为L(当前为0),我加上45(或任何角度)并减去45(或任何角度)即可得到a和b(我的视角).

现在我需要知道绿点是否在a和b之间

(g> a || g> 0)&& (g< b)

所以在这张照片中,只有最上面的绿点是真实的.

很抱歉,如果我不明确自己的母语不是英语

解决方案

我遇到了类似的问题.我得到了它.所有计算均以度为单位. 我需要计算ID的gps位置是在矩形内.

或者,我需要查看角度x是否在角度check+r和角度check-r之间.

check-r<x<check+r.

如果需要a<x<b,请在ab的中间找到角度check,然后找到checkab的距离(r). /p>

该方法规范化,将角度从-infinity ... infinity更改为-180 ... 180. 方法检查,接受参数 x:我们需要查看它是否位于角度check-r和check + r之间的角度. check:要检查的角度. r:围绕角度检查的半径.

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 && x>-r;
}

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 and subtracting that's seems to work. I would just like to get something smaller and maybe more efficient.

thanks

EDIT

Here is a picture what i am trying to say.

Ok I have angle L(currently 0) i add 45(or any angle) and subtract 45(or any angle) to get a and b (my view angle).

Now i need to know if the green dot is between a and b

(g> a || g > 0) && (g < b)

so in this picture only the top green dot will be true..

Sorry if I am not making my self clear my first language is not English

解决方案

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<x<check+r.

If you need a<x<b, 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 && x>-r;
}

这篇关于角度在两个角度之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆