Skip to content

Instantly share code, notes, and snippets.

@cemre
Created October 22, 2011 22:36

Revisions

  1. Cemre Güngör created this gist Oct 22, 2011.
    38 changes: 38 additions & 0 deletions greatcirclearc.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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();
    }