I am trying to place some countries on a globe, but the points are deposited in completely wrong places. Germany DE and Austria AU are far apart and my local position is not placed in Germany.
Sorry, I should have read the note from the chatGPT…
Note that if you are working with latitude and longitude values in degrees, you need to convert them to radians before using the formula. The conversion from degrees to radians is done by multiplying the degree value by π/180.
let latitude = data.coords.latitude * Math.PI / 180;
let longitude = data.coords.longitude * Math.PI / 180;
VoilĂ !
The question now is, how can I wrap a world map around the sphere so that the points match the country positions?
You have to choose the projection to use and use the same one for your texture Map projection - Wikipedia
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
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