Last active
March 2, 2020 14:21
-
-
Save Firzen7/4bcbb55db9e85d69605e9ed2a6af41e3 to your computer and use it in GitHub Desktop.
Java implementation of https://gist.github.com/amites/3718961
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private GPSPoint gpsCentre(Collection<GPSPoint> points) { | |
float x = 0; | |
float y = 0; | |
float z = 0; | |
for(GPSPoint pt : points) { | |
final float lat = (float) pt.getLatitude(); | |
final float lon = (float) pt.getLongitude(); | |
x += Math.cos(lat) * Math.cos(lon); | |
y += Math.cos(lat) * Math.sin(lon); | |
z += Math.sin(lat); | |
} | |
x = (float) (x / points.size()); | |
y = (float) (y / points.size()); | |
z = (float) (z / points.size()); | |
return new GPSPoint(Math.atan2(y, x), Math.atan2(z, Math.sqrt(x * x + y * y))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment