Created
December 11, 2012 14:35
-
-
Save edofic/4258985 to your computer and use it in GitHub Desktop.
coordinates transformer
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
class Point{ | |
final double x,y; | |
Point(a,b){ | |
x=a; | |
y=b; | |
} | |
....... | |
//transformx lat,lon to unit circle with hard limit | |
Point[] transform(Point[] points, Point center, double maxMeters){ | |
final int n = points.length; | |
double maxLog = Math.log(maxMeters); | |
Point[] q = new Point[n]; | |
for(int i=0; i<n; i++){ | |
double x = (points[i].x - center.x) * 111319; //to distance in meters | |
double y = (points[i].y - center.y) * 111319; | |
double r = Math.hypot(x,y); | |
double phi = Math.atan(y/x); | |
if(r>maxMeters) r = maxMeters; | |
r = Math.log(r+1) | |
r /= maxLog; | |
x = r*Math.cos(phi); | |
y = r*Math.sin(phi); | |
q[i] = new Point(x,y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment