public
Last active

Rendering great circle arcs in Processing between two coordinates

  • Download Gist
greatcirclearc.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
void drawPath(float lat1, float lon1, float lat2, float lon2) {
stroke(0);
strokeWeight(5);
noFill();
lat1 *= PI/180;
lon1 *= PI/180;
lat2 *= PI/180;
lon2 *= PI/180;
beginShape();
float d, f, A, B, x, y, z, latN, lonN;
int n;
d = 2*asin(sqrt( pow((sin((lat1-lat2)/2)),2) + cos(lat1)*cos(lat2)*pow((sin((lon1-lon2)/2)),2)));
println(d);
for (n = 0 ; n < (SENSITIVITY + 1) ; n++ ) {
f = (1/SENSITIVITY) * n;
A = sin((1-f)*d)/sin(d);
B = sin(f*d)/sin(d);
x = A*cos(lat1)*cos(lon1) + B*cos(lat2)*cos(lon2);
y = A*cos(lat1)*sin(lon1) + B*cos(lat2)*sin(lon2);
z = A*sin(lat1) + B*sin(lat2);
latN = atan2(z,sqrt(pow(x,2)+pow(y,2)));
lonN = atan2(y,x);
latN /= PI / 180;
lonN /= PI / 180;
vertex(lonN, -latN);
println(latN + " " + lonN);
}
endShape();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.