Projections of the Earth's globe on screen.

Viewing 3D in 2D.

A three dimensional globe can be projected onto a 2D mapping in all sorts of ways.And with Google Globe etcweare used to doing so in real time and at high resolution. But how is all the geometry worked out? Welcome to the world of map projections- Mercator, Molleweide, azimuthal, et al!

Byte magazine published an edition centred on graphics and map projection. Back then I didn't have acceess to an adequate computer, nor to the necessary data. It stayed on my back-burner as a 'to-do'. I kept that copy, even though I threw away most of the other months and years.

In the last year I experimented with scanning text and OCR-ing it to recover text. The ( early) BASIC had been printed on a dot-matrix printer for Byte, and not with 100% clarity. However I was able to make a good enough version to be able to correct the OCR and edit to the more modern Liberty BASIC. And remove all those line numbers, labels, and capital letters! I also found that the published version had some errors and contradictions in the published sub-routines, and confused radians and degrees.

Nowadays you can easily download lat/lon data off the 'net. I found a file of all large population centres in the world, and edited out the un-needed extra columns, leaving me a text file of lat/lon/pop'n data.

It took quite while to sort out, but I'm pleased with it so far. By looping round looking from different longitudes I was able to make a nice animated GIF. The cies are coarsely color-coded for population size.

Now to tackle different projection geometries!

It has also been fun looking through the magazine- the old adverts for early personal computers are very evocative. And I found also, even older, the first language manual I tried to understand- Titan Autocode on Cambridge University Atlas in 1967.


Code

    nomainwin

    WindowWidth  =900
    WindowHeight =740

    graphicbox #w.g,1, 1, 898, 738

    open "World Views" for window as #w

    #w   "trapclose quit"


    global pi:    pi    =3.14159265
    global twoPi: twoPi =2 *pi


    R   =300    '   RADIUS OF GRAPHIC IN SCREEN PIXELS


    'L0  = 80    '   LONGITUDE OF OBSERVER IN DEGREES.
for L0  =0 to 360 step 10
    #w.g "cls ; goto 450 350 ; down ; fill 60 60 60 ; size 1 ; color white ; circle 300 ; flush"
    #w.g "color white ; size 1 ; down"

    '   Add loop through range of P and LA to generate screen grid of lat /lon
[grid]
    for lat =-90 to 90 step  10 '   BOTH IN DEGREES. EAST OF MERIDIAN +ve. NORTH +ve.
        for long = -180 to 180 step 10
            L   =long
            P   =lat
            '#w.g "set "; int( 450 +2 *long); " "; int( 350 +3 *lat)
            gosub [findPoint]
        next long
    next lat

    #w.g "flush"

[dataShow]
    #w.g "color 180 180 100 ; size 2"

    open "LatLon2.txt" for input as #fIn

    line input #fIn, g$

    for k =2 to 7343
        line input #fIn, g$
        L   =val( word$( g$, 2, ","))
        P   =val( word$( g$, 1, ","))
        pop =val( word$( g$, 3, ","))
        gosub [findPoint]
    next k

    close #fIn

    #w.g "flush"
    #w.g "getbmp scr 1 1 898 738"
    bmpsave "scr", "globe-" +right$( "000" +str$( L0), 3) +".bmp"

    scan
next L0

    wait

[findPoint]
    ' SUBROUTINE TO COMPUTE MAP COORDINATES FOR ORTHOGRAPHIC EQUATORIAL PROJECTION.

    ' THE FOLLOWING VARIABLES MUST BE DEFINED BEFORE THIS SUBROUTINE IS CALLED:
    '   P  IS THE GEOGRAPHIC LATITUDE         IN DEGREES OF THE POINT BEING CONVERTED.
    '   L  IS THE GEOGRAPHIC LONGITUDE        IN DEGREES OF THE POINT BEING CONVERTED.
    '   R  IS THE RADIUS OF THE FINISHED MAPS IN PIXELS.

    ' THE FOLLOWING VARIABLES ARE COMPUTED BY THIS SUBROUTINES
    '   S  IS THE OFF-SCALE FLAG.             S =0 MEANS ON-SCALE S =1 MEANS OFF-SCALE.
    '   R1 IS TEMPORARY STORAGE.
    '   X  1S THE MAP X-COORDINATE IN PIXELS.
    '   Y  IS THE MAP Y=COORDINATE IN PIXELS.

    S   = 0

    ' ROTATE THE GEOGRAPHIC LONGITUDE OF THE POINT FROM THE DATA BASE TO REFERENCE IT TO THE MAP CENTER LONGITUDE
    '       AND CONVERT TO RADIANS.
    L   = ( L -L0) *pi /180
    P   =   P      *pi /180

    ' NORMALIZE THE ROTATED LONGITUDE BETWEEN ~180 DEGREES AND +180 DEGREES (-PI AND +PI)
    IF L >pi           THEN L   = L - twoPi
    IF L <( 0 -pi)     THEN L   = L + twoPi

    ' IF OFF-SCALE (OUTSIDE THE RANGE FROM -P1/2 TO +pi/2 SET FLAG AND RETURN
    IF L  <( 0 -pi /2) THEN S = 1: RETURN
    IF L  >(    pi /2) THEN S = 1: RETURN

    ' COMPUTE THE MAP COORDINATES FROM THE GEOGRAPHIC COORDINATES.
    '       L IN RANGE -pi/2..pi/2    P IN RANGE -pi/pi.
    R1      =  R * sin( ( pi /2 -abs( P)))

    X       = R1 * sin( L)
    Y       =  R * sin( P)

    select case
        case pop >1E7
            col$ ="red":    size =3
        case pop >1E6
            col$ ="yellow": size =2
        case pop >1E5
            col$ ="green":  size =1
        case else
            col$ ="cyan":   size =1
    end select
    #w.g "color "; col$
    #w.g "size "; size
    #w.g "set "; int( 450 +X); " "; int( 350 -Y)
    RETURN

    END

sub quit h$
    close #h$
    end
end sub