简体   繁体   中英

rotation angle between -90 and 90

I have two 1d arrays. They are plotted together. They are constructed such that they make angle to one another. the red line is the reference line or you can say axis. In picture 1 this makes theoretically an angle of positive 36 degrees from the red line. I know this based on my data.

Picture two has the same referenced line(red) but now the blue line is above it. This is an angle of -36 degrees. So based on my calculation the two arrays are plotting the way it should be.

But now I like to estimate an angle based on how they are plotted. These plots are based on data, which I already know. I now need to make a logic to estimate angles. I was reading that arctan2 would help. But I am not sure why?

Please note that the maximum angle of rotation should not exceed beyong-90 to 90 degrees. So -90 above the red line and 90 bel0w the red line, in my case.

Thanks sal

在此处输入图像描述

在此处输入图像描述

This is basic trigonometry. The angle of a line from the x axis is arctan(dy/dx) . So, ypu need two points on each line. We can use (0,Y0) , where Y0 is the Y coordinate of both lines when X=0. Then, say we have (xb1,yb1) as some point on the blue line, and (xr1,yr1) as some point on the red line. Then we have:

import math
# Angle of red line from horizontal
theta_r = math.atan( (yr1-y0) / xr1 )
# Angle of blue line from horizontal
theta_b = math.atan( (yb1-y0) / xb1 )
# Difference
delta = theta_r - theta_b

If both lines are in the first quadrant, there's no need for atan2 . The simpler atan will do.

The result here will be in radians. If you want degrees, you can do

degrees = delta * 180 / math.pi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM