필터 지우기
필터 지우기

Determining whether an angle is between two other angles

조회 수: 2 (최근 30일)
Matthes Müller
Matthes Müller 2018년 9월 17일
댓글: Matthes Müller 2018년 9월 18일
I have 3 angles given: gamma1 and gamma2 can attain any value between -360° and 720°, az_ray can attain any value between 0° and 360°.
I would like to check whether az_ray is between those two, and return RayCat(j) = 1 if so. My try would be
if gamma1 < 0
gamma1 = gamma1+360;
end
if gamma1 > 360
gamma1 = gamma1-360;
end
if gamma2 < 0
gamma2 = gamma2+360;
end
if gamma2 > 360
gamma2 = gamma2-360;
end
if gamma1 < gamma2
if (gamma1 <= az_ray) && (az_ray <=gamma2)
RayCat(j) = 1;
else
RayCat(j) = 0;
end
end
if gamma1 > gamma2
if (gamma2 <= az_ray) && (az_ray <=gamma1)
RayCat(j) = 1;
else
RayCat(j) = 0;
end
end
However, this usually works fine but fails for negative values, since it switches the "in- and outside" of the gammas. How can I avoid this or is there a smoother option?

답변 (1개)

Adam
Adam 2018년 9월 17일
RayCat = sign( az_ray - mod( gamma1, 360 ) ) == sign( mod( gamma2, 360 ) - az_ray );
looks like it would do the job.
  댓글 수: 3
Adam
Adam 2018년 9월 17일
It worked for the example I tested it on, but I didn't have time to exhaustively test each edge case. What example does it not work on?
Matthes Müller
Matthes Müller 2018년 9월 18일
az_ray = 358; gamma1 = 355; gamma2 = 365
returns
RayCat = 0

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by