Angle difference between two bearings
33 次查看(过去 30 天)
显示 更早的评论
How do I find the minimum angle difference between two angles A & B, for example:
if A = -175, B = 175 -> difference would be 10
if A = 355, B = 5 -> difference would be 10
if A = 720, B = 360 -> difference would be 0
etc.
All I know is that I have to use the absolute and modulus functions somewhere
Would appreciate any help.
0 个评论
采纳的回答
Basil C.
2021-3-11
Read about principal angles...
For the 1st case:
A=-175 whose principal angle is 185 degree
A - B = 185 - 175 = 10 degrees
You can similarly solve the for the remaining cases
3 个评论
Basil C.
2021-3-11
The problem with your code is that it A and B must be in the principal form for the code to work.
To solve your question, A and B need to be converted to the principal angle and then just subtract them
更多回答(1 个)
Basil C.
2021-3-12
编辑:Basil C.
2021-3-12
To convert any angle to its principal angle
function y = prin_angle(x)
y=rem(x,360); % returns the remainder when dividing by 360
if y<0
y=y+360;
end
end
Just pass both angles to above function individually to obtain the principal angle, then subtract the two outputs
OR
Just use the following code and pass both A and B directly:
function y = get_difference(A,B)
y=rem(B-A,360); % returns the remainder when dividing by 360
if y<-180
y=y+360;
elseif y>180
y=y-360;
end
end
P.S.: I have just converted the java code from above into matlab code
5 个评论
cem polat
2022-1-20
Use anglediff function in Communications or Robotics toolbox. Since anglediff uses radians, you can use a function like below for the angle diff in degrees:
function result = angdiffdeg(from, to)
result = rad2deg(angdiff(deg2rad(from),deg2rad(to)));
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!