Skip to content

Instantly share code, notes, and snippets.

@cemre
Created October 22, 2011 22:36
Show Gist options
  • Save cemre/1306578 to your computer and use it in GitHub Desktop.
Save cemre/1306578 to your computer and use it in GitHub Desktop.
Rendering great circle arcs in Processing between two coordinates
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment