great circle arc
in
Programming Questions
•
1 year ago
I've been trying to create a great circle arc between the US and China but I can't get the algorithm/code right. I tried changing the return line to converting latN and lonN to degree but that wasnt right either... so I just kept it how it is in the js code. You can download the example I wrote at
http://ekeneijeoma.com/processing/GreatCircleTest.zip
- float[] interpolate(float[] latlon1, float[] latlon2, float f) {
- float lat1 = radians(latlon1[1]);
- float lon1 = radians(latlon1[0]);
- float lon2 = radians(latlon2[1]);
- float lat2 = radians(latlon2[0]);
- float d = 2 * asin(sqrt(pow(sin((lat1 - lat2) / 2), 2) + cos(lat1)
- * cos(lat2) * pow(sin((lon1 - lon2) / 2), 2)));
- float bearing = atan2(sin(lon1 - lon2) * cos(lat2), cos(lat1)
- * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon1 - lon2))
- / -(PI / 180);
- bearing = bearing < 0 ? 360 + bearing : bearing;
- float A = sin((1 - f) * d) / sin(d);
- float B = sin(f * d) / sin(d);
- float x = A * cos(lat1) * cos(lon1) + B * cos(lat2) * cos(lon2);
- float y = A * cos(lat1) * sin(lon1) + B * cos(lat2) * sin(lon2);
- float z = A * sin(lat1) + B * sin(lat2);
- float latN = atan2(z, sqrt(pow(x, 2) + pow(y, 2)));
- float lonN = atan2(y, x);
- return new float[] {
- radians(latN), radians(lonN)
- };
- }
1