Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

math - Is angle in between two angles

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.

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...