I made this as a part of a bigger project. Its code for plotting latitude and longitude decimals, like ones twitter throws, into a 2D word projection named
Kavrayskiy . The formula was from wikipedia. The image was downloaded from wiki at this
link . It looks like this:
edit:
you can't see in image but the meridians are draw with dots and scalable. So you might run it without the image.
[EDIT2]
image now linked to web so is copy paste and run :)
- /*
- code for plotting decimals latitude and longitude
- into Kavrayskiy projection
- */
-
- PImage mapa;
-
- PVector tokyo, bras, londres, la, syd, rio, moskow, rome, ny, antan, hawaii, dakar, jakarta, cape;
- static float FACTOR = 234.0; // to scale to image size
- PFont font;
- float linesFactor = 234.0;// inicial mouseY value
- boolean moved = false; // wait user
-
-
-
-
- void setup()
- {
- size(1280, 743);
- mapa = loadImage("
- mapa = loadImage("http://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Kavraiskiy_VII_projection_SW.jpg/1280px-Kavraiskiy_VII_projection_SW.jpg");
- imageMode(CENTER); ");
- imageMode(CENTER);
-
- londres = new PVector(00.80, 51.00); // (longitude, lattitude) !!! makes sense with x and y
- la = new PVector(-118.00, 34.00); // data from http://www.findlatitudeandlongitude.com
- bras = new PVector(-47.00, -15.00);
- syd = new PVector(151.232, -33.87);
- tokyo = new PVector(139.00, 35.00);
- rio = new PVector(-43.22, -22.90);
- moskow = new PVector(37.69, 55.74);
- rome = new PVector(14.46, 41.90);
- ny = new PVector(-74.00, 40.71);
- antan = new PVector(47.52, -18.41);
- hawaii = new PVector(-155.66, 19.89);
- dakar = new PVector(-17.44, 14.68);
- jakarta = new PVector(106.87, -6.22);
- cape = new PVector(-163.54, 67,44);
-
- font = createFont("Verdana", 15);
- }
-
-
- void draw()
- {
- translate(width/2, height/2); // drawing at origin
- tint(120);
- image(mapa, 0, 0);
- for (int i = -180; i <= 180; i += 15)
- {
- for (int j = -180; j <= 180; j += 1)
- {
- float x = kavraX(convertToRadians(i), convertToRadians(j))*linesFactor;
- float y = kavraY(convertToRadians(i), convertToRadians(j))*linesFactor;
- stroke(220);
- point(x, y);
- }
- }
- setPoint(bras, "Brasília");
- setPoint(la, "LA");
- setPoint(londres, "London");
- setPoint(syd, "Sydney");
- setPoint(tokyo, "Tokyo");
- setPoint(rio, "Rio de Janeiro");
- setPoint(moskow, "Moscow");
- setPoint(rome, "Rome");
- setPoint(ny, "New York");
- setPoint(antan, "Antananarivo");
- setPoint(hawaii, "Hawaii");
- setPoint(dakar, "Dakar");
- setPoint(jakarta, "Jakarta");
- setPoint(cape, "Cape Krusenstern Monument");
-
- // wait user
- if (pmouseY != mouseY)
- {
- moved = true;
- }
-
- if (moved)linesFactor = mouseY;
- }
-
-
-
-
-
-
-
- void setPoint(PVector pv, String name)
- {
- noFill();
- stroke(255, 200, 10);
- ellipseMode(CENTER);
- float xp = kavraX(convertToRadians(pv.x), convertToRadians(pv.y))*FACTOR;
- float yp = kavraY(convertToRadians(pv.x), convertToRadians(pv.y))*FACTOR;
- ellipse(xp, yp, 10, 10);
- textFont(font, 15);
- text(name, xp +10, yp);
- }
-
-
-
-
- /// mapping
- float kavraX (float longitude, float latitude) // Kavra for Kavrayskiy
- // formula from http://en.wikipedia.org/wiki/Kavrayskiy_VII_projection
- {
- return ((3 * longitude) / TWO_PI)*sqrt(pow(PI, 2)/3 - pow(latitude, 2));
- }
-
- float kavraY (float longitude, float latitude)
- {
- return latitude*-1;
- }
-
-
- // the formula wants radians
- float convertToRadians(float decimalDegree)
- {
- return decimalDegree*PI/180;
- }