Fixed issue causing NaN azimuth #4
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed issue causing NaN azimuth when azimuth was close to 0-360 or 180
Description:
The issue causing the azimuth to return NaN when it was close to 0-360 or 180 has been fixed.
Example of the problem:
CODE:
SERIAL OUTPUT:
How the issue was fixed:
The issue was in the following line of code:
The
acos()function accepts values only in the range of -1 to 1. Due to floating-point rounding errors, the expression((sin(lat) * cos(zen)) - sin(decl)) / (cos(lat) * sin(zen))could result in values slightly outside this range, which causes theacos()function to return NaN.For example, in some cases, the calculation produced values slightly greater than 1 or slightly less than -1:
Solution:
To address this issue, the calculation has been modified to clamp the result between -1 and 1 before passing it to
acos(). This ensures that the value remains within the valid range foracos()and prevents it from returning NaN:This adjustment prevents the expression from exceeding the allowable range for
acos(), thereby eliminating the errors and returning valid azimuth values.