-
Notifications
You must be signed in to change notification settings - Fork 165
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
Perf improvement in LawOfCosines #80
Comments
You are right regarding needless subtraction of DEG_90_AS_RADS. I have since committed the tweaks you have here. You make a very good point about the Math.acos() call being redundant if the formula is being used to check if the distance is more than or less than another distance that is constant over many iterations (i.e. doing many point-in-circle tests). Addressing this is an API issue. The DistanceCalculator abstraction as it is currently formed isn't so great. Perhaps instead it should be named WithinDistanceCalculator and you initialize it with a point and distance. Not only would LawOfCosines benefit, but the others would too, I think. I'll create another issue. |
Happy to see your quick response. Thanks! |
When I use LawOfCosines calacutator, I found the perf is worse than Haversine and Vincenty.
I found the heaviest part of LawOfCosines is acos
public static double distLawOfCosinesRAD(double lat1, double lon1, double lat2, double lon2) {
//TODO validate formula
}
In most scenarios, we use distLawOfCosinesRAD as a distance filter.
For within calculation, we don't need get the angle, we can just compare the cosine value of the angles, since cosine function is monotonic decreasing.
We can just compare whether cosB is bigger than cos(radius) while cos(radius) can be computed only once for a query.
Another improvement is, when I change
to
double cosB = (Math.sin(lat1) * Math.sin(lat2))
which is the same result, but the performance is much better if latitude and longitude is random distributed in China or US region.
I am wondering what is the purpose of DEG_90_AS_RADS convert here.
The text was updated successfully, but these errors were encountered: