-
Notifications
You must be signed in to change notification settings - Fork 217
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
Direct Formula returns wrong results #542
Comments
Hi @barendgehrels, this is a known issue of That is, this is a "feature" of the formula since for azimuth values close to I see a few different directions here: (i) try to come up with some formula for that special case (I do not know whether we can come up with something as efficient as it is know though), (ii) use Note: for direct there is no andoyer formula but we get a 1st order approximation from a special case of |
Hi @vissarion thanks for your answer and the backgrounds. I see the problem. But for users of the formula, like I'm now, this can cause quite a problem. For the buffer around a point I can work around it. Because if I start the buffer at 0 degree, which I did, I get a at 180 degree (if there is an even number of points). But I can also start at 0.01 degree and then the chance is quite low. However, as soon as the buffer implementation extends to linestrings/polygons, or the number of points in a corner or around a point becomes very high, then the chance of such a 180 degree point is of course high. I would advocate for (i), a specific handling for that case. I can think of something which is indeed not so efficient: 2 or 5 times slower: calculate two points around (so with pi - offset and pi + offset) and average the points to get the result ("a") So that is twice as slow, but not accurate enough. Then you can also calculate three other points: 0 - offset, 0, o + offset and calculate the northwards displacement of the 0 point (probably two other is enough). That displacement can be subtracted from the previous result ("a") to get a more accurate result ("b"). So this most probably gives a satisfactory result (if you want I can try it). And because it is an exception, and "only" 4 times slower (Vincenty is perhaps slower than that, but I don't know that), it is probably acceptable. IMO option (ii) is not so nice, using a completely other formula makes strategies intertwined, and I can imagine that the result is maybe different, so you will get a kind of discontinuity there. Option (iii) is also not so nice because people will just consider it as a bug, and probably don't understand how to work with a shortcoming of the underlying algorithm. |
One simple workaround for this behavior could be to normalize the input to always use |azimuth| <= 90 deg in formula. So if |azimuth| > 90 switch latitudes/hemispheres and use either opposite azimuth or azimuth symmetrical wrt equator, calculate for the altered azimuth and then switch back the result accordingly. And to be clear, what I'm saying is: this is how it could be fixed in the formula. |
That sounds a lot simpler than the workaround I described above. Yes, let's do that! |
The switching of latitudes was already done (see: https://github.com/boostorg/geometry/blob/develop/include/boost/geometry/formulas/thomas_direct.hpp#L94). The problem is that you're passing azimuth in range [0, 360] but valid range is [-180, 180]. This is also the range of azimuth returned from inverse formulas. There is also a utility for normalization of azimuth:
which can be called before before passing the azimuth to formulas. I could put an assertion there but technically this is not something worthy of termination of the program, only inaccuracy. Another solution is to normalize azimuth automatically inside formula. EDIT: on the other hand formulas are for internal use and there is no need to normalize inputs that should be correct. |
I lean towards putting an assertion in formulas and do not add more complexity by normalization. The caller of the formulas should take care of the correctness of the formula input. |
I proposed a fix for this in PR #572. I decided to not normalize automatically but to check assertion. I modified geographic buffer point strategy to pass correct azimuth. The problem with starting from 0 still remains i.e. very inaccurate area is calculated but AFAIU this is not caused by the direct formula. |
The fix for this issue was merged so I'm closing. |
Hi @vissarion , @awulkiew ,
When I, for buffer, try to calculate the coordinates of a point, at 180 degrees, there is an error.
See this minimal reproduction scenario:
Delivering:
You notice that at 179.999 the latitude coordinate is quite off.
I'm using andoyer, I did not try other systems yet.
Note that this is not the reason for the failing area formule, just reported in another issue. Because I'm now starting at 0.0001 to avoid coordinate 180.000 - the generation is then correct. But this is a workaround.
The text was updated successfully, but these errors were encountered: