Home > Enterprise >  Understanding of degree calcuation in quadrants
Understanding of degree calcuation in quadrants

Time:12-04

I found something in my search, which I don't understand. The goal is to read out the angle of a pointer in a pressure gauge. In my research, I found this example:

https://circuits-ninja.pl/reading-an-indication-from-an-analog-pressure-gauge-using-the-esp32-cam-module-with-an-ov2640-and-opencv-camera/

He's calculating the degree as follows:

# Finding angle using the arc tan of y/x
res = np.arctan(np.divide(float(y_angle), float(x_angle)))
#Converting to degrees
res = np.rad2deg(res)

if x_angle > 0 and y_angle > 0:  #in quadrant I
    final_angle = 270 - res
if x_angle < 0 and y_angle > 0:  #in quadrant II
    final_angle = 90 - res
if x_angle < 0 and y_angle < 0:  #in quadrant III
    final_angle = 90 - res
if x_angle > 0 and y_angle < 0:  #in quadrant IV
    final_angle = 270 - res

I understand the reason of using quadrants in this case, but what i don't understand is why does he calculate 270 - res if x_angle and y_angle > 0 and also calculate 270 - res if x_angle > 0 and y_angle < 0. He's using the same formula for two different quadrants?

Thanks in forward

CodePudding user response:

I think this is because 0 degrees is located, if placed on a two-dimensional surface, on (0,1)=(cos(90),sin(90)) instead of (1,0)=(cos(0),sin(0)). This means it has an offset of 90 degrees.

CodePudding user response:

Much simpler way:

 res = np.arctan2(float(y_angle), float(x_angle))
 #Converting to degrees
 res = np.rad2deg(res)
 if (res < 0):
     res  = 360 

That's all, arctan2 will account for all cases including zero x

  • Related