Countries on a sphere

i did it in python before , and it worked perfectly ( i didnt write the “llarToWorld” function … found it online ) anyway , maybe some of the code helps :wink:

def llarToWorld(lat, lon, alt, rad):
    # see: http://www.mathworks.de/help/toolbox/aeroblks/llatoecefposition.html
    f  = 0                              # flattening
    ls = math.atan((1 - f)**2 * math.tan(lat))    # lambda

    x = rad * math.cos(ls) * math.cos(lon) + alt * math.cos(lat) * math.cos(lon)
    y= rad * math.cos(ls) * math.sin(lon) + alt * math.cos(lat) * math.sin(lon)
    z = rad * math.sin(ls) + alt * math.sin(lat)

    return (x, y, z)

d = "Moscow,55.755826,37.6173,London,51.5073509,-0.1277583,Paris,48.856614,2.3522219,New York,40.7127837,-74.0059413,Saint Petersburg,27.7518284,-82.6267345"

da = d.split(",");
vd = []
vd_names = []
i = 0

while i < len(da):
    vd_names.append(da[i])
    vd.append(llarToWorld(math.radians(eval(da[i+1])),math.radians(eval(da[i+2])),0.0,1.0))    
    i += 3

ps , i found I had to rotate my globe by -90 deg on the upright axis to get the texture map to match the code … might be different for you in JS and babylon

1 Like