Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reason for the do...while loop in toLatLon(), utm.js #119

Open
Ant1882 opened this issue Apr 30, 2024 · 0 comments
Open

Reason for the do...while loop in toLatLon(), utm.js #119

Ant1882 opened this issue Apr 30, 2024 · 0 comments

Comments

@Ant1882
Copy link

Ant1882 commented Apr 30, 2024

More of a query than an issue. Does the do...while loop here serve much purpose?

geodesy/utm.js

Lines 135 to 142 in 761587c

do {
const σi = Math.sinh(e*Math.atanh(e*τi/Math.sqrt(1+τi*τi)));
const τiʹ = τi * Math.sqrt(1+σi*σi) - σi * Math.sqrt(1+τi*τi);
δτi = (τʹ - τiʹ)/Math.sqrt(1+τiʹ*τiʹ)
* (1 + (1-e*e)*τi*τi) / ((1-e*e)*Math.sqrt(1+τi*τi));
τi += δτi;
} while (Math.abs(δτi) > 1e-12); // using IEEE 754 δτi -> 0 after 2-3 iterations
// note relatively large convergence test as δτi toggles on ±1.12e-16 for eg 31 N 400000 5000000

The reason I ask is that I converted the code (UTM <--> Lat/Lon) to embedded C, which works fine apart from this loop. If I take out the loop then I get the correct answer anyways, it appears as though my loop condition is incorrect, and I don't understand enough about what it is doing to change it, I wrote as:

} while(fabs(delTaui) > 1e-12); // using IEEE 754 δτi -> 0 after 2-3 iterations

Where "delTaui" is of type double.

Would it be possible to explain to me the need for this loop? I'm not very mathematically minded but I appreciate things are done for a reason and me just running the loop once and getting the correct answer doesn't mean I always will... I guess it depends on the location?

Many thanks,

Ant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant