Projecting co-ordinates onto a round surface.

Little snippet of handy code (in perl), how to adjust 2 dimentional latitude / longitude co-ordinates for plotting on a sphere.

    rotAngle = 0;       # Rotational offset
    padX     = 0;       # Initial padding on Y axis
    padY     = 0;       # Initial padding on X axis

    posX = 0;
    posY = 0;

    posY = 0.5 * log( (1 + sin(lat)) / (1 - sin(lat)) );    # mercator latitude projection

    if (rotAngle != 0) {
    hyp = root((posX^2) + (posY^2));
    posX = ((cos rotAngle) * hyp);
    posY = ((sin rotAngle) * hyp);
    }

    posY += padY;
    posX += padX;

social