ufrgs-gnss-lab / geo-alhazen

Modeling of reflection on a sphere
1 stars 0 forks source link

Fix Fujimura issue at zenith #24

Closed vitorhjr closed 1 year ago

vitorhjr commented 1 year ago

Fujimura algorithm has a bug in computing the grazing angle at 90°. It's because the grazing angle is computed with the geocentric angle between antenna and reflection point. So, at the zenith, the geocentric angle is zero and then the grazing angle return NaN.

To solve this problem I thinking to use the function get_grazing_angle_vector.m when computation is exactly at zenith.

Do you suggest any other solution @fgnievinski?

vitorhjr commented 1 year ago

I included a condition on computation grazing angle at zenith as follows:

if e==90
    graz_ang = get_grazing_angle_vector (pos_ant_loc,pos_spec_loc,pos_trans_loc); 
    return
end
graz_ang = atand(cotd(geo_ang)-(Rs./Ra)./sind(geo_ang));

It's documented in the commit https://github.com/vitorhjr/geo-alhazen/commit/59e46fbf5651f856cf32956cff5a7c15af699a46

fgnievinski commented 1 year ago

@vitorhjr pls try: graz_ang = rad2deg(angle(u-z1)); or something like that.

vitorhjr commented 1 year ago

It could be 90 - rad2deg(angle(u-z1)), but it returns the elevation angle and not the grazing angle.

fgnievinski commented 1 year ago

the problem with a special case for zenith is it ignores near zenith conditions -- for example, does it fail for e=90-eps()?

please try to reformulate the solution in terms of the complex number. borrowing from Miller, it seems it could be: graz_ang = rad2deg(0.5*acos(real(u));

vitorhjr commented 1 year ago

the problem with a special case for zenith is it ignores near zenith conditions -- for example, does it fail for e=90-eps()?

The Fujimura fails to solve because Matlab considers 90-eps() == 90.

please try to reformulate the solution in terms of the complex number. borrowing from Miller, it seems it could be: graz_ang = rad2deg(0.5*acos(real(u));

This formula doesn't retrieve grazing angle correctly. It's probably because Miller uses roots to solve grazing angle while Fujimura solves reflection point. But, it can be a way.

fgnievinski commented 1 year ago

check e=90-eps(90) or e=90-10*eps(90), it would be different than 90.

vitorhjr commented 1 year ago

Both ways have worked and Fujimura had success to solve the grazing angle in these cases. Both 90-eps(90) and 90-10*eps(90) have a difference from 90° of ~-1.42e-13. The grazing angle computed by Fujimura had this same precision.

vitorhjr commented 1 year ago

In this case, the geocentric angle used to compute the grazing angle will not be exactly zero, within machine precision. So the sine and cotangent can be solved.

fgnievinski commented 1 year ago

you could well do:

if e==90
    graz_ang = 90;
...
vitorhjr commented 1 year ago

Ok, it could be done. But, in this case, the grazing angle cannot be assessed as we simply define a value instead a formulation. What do you think?

fgnievinski commented 1 year ago

both special cases are a "hack".

the best would be to have no special case.

redraw Figure 16 of your dissertation with z1 and u as vectors in the complex plane.

the formula should be something like g = 90 - rad2deg(angle(z1/u-1));

vitorhjr commented 1 year ago

redraw Figure 16 of your dissertation with z1 and u as vectors in the complex plane.

Ok.

the formula should be something like g = 90 - rad2deg(angle(z1/u-1));

The formula works with a little adjustment. The formula is g = 90+rad2deg(angle(z1/u-1));. This formula works at zenith.

fgnievinski commented 1 year ago

great! to understand it, consider (z1-u)/u: the difference z1-u is the vector from specular point to receiving antenna and angle(a/b) gives the angle between any two complex numbers.

vitorhjr commented 1 year ago

great! to understand it, consider (z1-u)/u: the difference z1-u is the vector from specular point to receiving antenna and angle(a/b) gives the angle between any two complex numbers.

Thank you for the explanation. I understand it. I didn't remember to thought it as a vector.

redraw Figure 16 of your dissertation with z1 and u as vectors in the complex plane.

What is the priority to do that?

vitorhjr commented 1 year ago

Fujimura algorithm updated in the following commit https://github.com/vitorhjr/geo-alhazen/commit/094c5da43c9268c6fdb9fe52297a92acae3f68c2

fgnievinski commented 1 year ago

What is the priority to do that?

no longer necessary, although it might be good to emphasize the vectorial interpretation of complex numbers somewhere in the manuscript, I think a reviewer was puzzled about it.