DON'T PANIC

This is really very simple. It just looks complicated because of all the Greek symbols and what-not. *λ* (lambda) is the longitude, and φ (phi) is the latitude in radians. I'll stick with radians, as computers by default use radians, so no need to convert.

Right, from the get-go I can see that the y coordinate is merely the latitude. Happy days. The x coordinate is calculated as follows in code:

float x = (3.0 * lng / 2.0) * sqrt( (1.0 / 3.0) - sq(lat / PI));

The *sqrt()* and *sq()* functions are *square root* and *square* respectively.

Processing has the type *PVector, *which allows us to handle an x,y coordinate pair, which means I can create a function like so:

PVector getKavrayskiyVII(float lat, float lng)
{
float x = (3.0 * lng / 2.0) * sqrt( (1.0 / 3.0) - sq(lat / PI));
return new PVector(x, lat);
}

Which returns the x and y coordinates of a given longitude and latitude.

The problem I have now is that I'm looping through the x and y coordinates when I now need to loop through the longitude and latitude angles. The data is for 5° by 5° segments of the surface or π/36 radians. So my loops now need to look like:

float step = PI/36.0;
float halfPi = PI/2.0;
int latCount = 0;
int lngCount = 0;
for(float lng = -PI; lng < PI; lng+=step)
{
for(float lat = halfPi; lat > -halfPi; lat-=step)
{
float temperature = temperatureGrid[latCount][lngCount]/100.0;
latCount++;
}
latCount = 0;
lngCount++;
}

As I am working out four points surrounding a point on a sphere, I get the top-left, top-right, bottom-left, and bottom-right points like so:

float halfStep = step/2.0;
PVector tl = getKavrayskiyVII(lat + halfStep, lng - halfStep);
PVector tr = getKavrayskiyVII(lat + halfStep, lng + halfStep);
PVector bl = getKavrayskiyVII(lat - halfStep, lng - halfStep);
PVector br = getKavrayskiyVII(lat - halfStep, lng + halfStep);

To draw a four sided irregular polygon I'm using the *quad()* function where *s* scales it to a nice size:

float s = 170;
quad
(
tl.x * s, -tl.y * s,
tr.x * s, -tr.y * s,
br.x * s, -br.y * s,
bl.x * s, -bl.y * s
);

Which generates: