Angle difference between two bearings
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
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 comentarios
Shikhar Singh
el 12 de Mzo. de 2021
Basil C.
el 13 de Mzo. de 2021
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
y=abs(y)
end
Shikhar Singh
el 13 de Mzo. de 2021
darova
el 13 de Mzo. de 2021

cem polat
el 20 de En. de 2022
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
Categorías
Más información sobre Axes Transformations en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!