Direction between points from [0,360]

조회 수: 15 (최근 30일)
AAS
AAS 2020년 9월 25일
댓글: John D'Errico 2020년 9월 25일
I have 5 points which has (x,y) position and want to calculate the direction from one point to the other. I used atan2d but the output is confusing. Is there any way to bypass the different signs for counterclockwise and clockwise and get the output to be between [0,360] from clockwise only?
Thanks

채택된 답변

John D'Errico
John D'Errico 2020년 9월 25일
편집: John D'Errico 2020년 9월 25일
The function atan2d gives angles that are from -180 to 180. Not a problem. This works:
mod(atan2d(y,x),360)
But you want the angles in a CLOCKWISE orientation? You do understand that is not the standard?
mod(360 - atan2d(y,x),360)
I won't ask why you need them in a clockwise orientation. The angles that come from this second expression are angles relative to a horizontal line, and proceeding CLOCKWISE around the origin.
Note that mod still works even if the angles are not integers. For example:
mod(360 - atan2d(-2,1),360)
ans =
63.435
So this points at an angle 63 degrees BELOW the right branch of the x-axis.
  댓글 수: 2
AAS
AAS 2020년 9월 25일
suppose point 1 is (x1,y1) , point 2 is (x2,y2)....point 5 is (x5,y5). does the y,x in your reply account for y2-y1 and x2-x1 respectively?
Thanks
John D'Errico
John D'Errico 2020년 9월 25일
It accounts for whatever you pass in.
mod(atan2d(diff(y),diff(x)),360)
or as you prefer,
mod(360 - atan2d(diff(y),diff(x)),360)
Learn to think in terms of vectors in MATLAB.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 9월 25일
편집: Ameer Hamza 2020년 9월 25일
Add 2pi to negative values.
x = -1;
y = -1;
theta = atan2(y, x);
if theta < 0
theta = theta + 2*pi;
end
  댓글 수: 1
John D'Errico
John D'Errico 2020년 9월 25일
The OP apparently wants results in DEGREES.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by