c++ - Determine if angle lies between 2 other angles -


I am trying to figure out whether the angle is located between two other angles. I am trying to make it a simple task, but any of my techniques will work for all possible values ​​of angles.

Can you help me in determining if an angle is located between 2 other angles?

Enter image details here

above In the picture; I use the green dot as the central point, then I set the angle of each line at a green dot. I then calculate the angle of the black point at the green dot. I am trying to check that the angle of black dot dissection is angles of 2 lines.

Note: in my case; An angle (target angel) is said to lie between 2 other angles if the difference between 2 angles is & lt; The 180 degree and the target angle is located in the cave created by those 2 angles.

The following code should work, but it fails for them (who lie between the angles):
- is_angle_between (150, 190, 110)
- is_angle_between ( 3, 41, 345) bool is_angle_between (int target, int angle1, int angle2) {int rAngle1 = ((iTarget - iAngle1)% 360 + 360)% 360; Int rAngle2 = ((iAngle2 - iAngle1)% 360 + 360)% 360; Return (0 <= rAngle1 & amp; rAngle1 & lt; = rAngle2); } // example usage_jail_betin (3, 41, 345);

I did not try any other technique that works: int is_angle_between (int target, int angle1, int angle2) {int dif1 = Angle1-angle2; Int dif2 = angle2-angle1; Int uDif1 = convert_to_positive_angle (dif1); // for example; Convert -15 to 345 difference UDIF 2 = Convert_to_positiv_engel (Diff2); If (uDif1 & lt; = uDif2) {if (dif1 & lt; 0) {Return (target = l = & angle1 & amp; target> gtle2;); } And return (in_between_numbers (iTarget, iAngle1, iAngle2)); } And Return (in_between_numbers (iTarget, iAngle1, iAngle2))} return - and return (if (dif2 & lt; 0) {return (target = l = & angle1 & amp; target = gtle2; 1;}

  bool is_angle_between (int target, int angle1, int angle2 ) {// Become angle to angle2 from angle1 & lt; = 180 degree int rAngle = (angle2 - angle1)% 360 + 360)% 360; if (rg> = 180) std :: swap (angle1, angle2 ); // Check if it passes zero if return (angle 1 <= angle2) return target> gtle1 & amp; target = l =; angle2; return another target gt; = angle1 || Goal & lt; = angle2;}    

Comments