Exploring the wonders of three.js
I am currently working on rendering objects at specific geocoordinates on a large sphere. I am close to finding a solution, but I am struggling to determine the correct xyz position from latitude and longitude.
I have created a test case on jsfiddle with two coordinates
latlons = [[40.7142700,-74.0059700], [52.5243700,13.4105300]];
representing New York and Berlin.
Below is the function I am using to calculate xyz from latitude, longitude, and radius
function calcPosFromLatLonRad(lat,lon,radius){
// Attempt1
var cosLat = Math.cos(lat * Math.PI / 180.0);
var sinLat = Math.sin(lat * Math.PI / 180.0);
var cosLon = Math.cos(lon * Math.PI / 180.0);
var sinLon = Math.sin(lon * Math.PI / 180.0);
var rad = radius;
y = rad * cosLat * sinLon;
x = rad * cosLat * cosLon;
z = rad * sinLat;
// Other attempts...
console.log([x,y,z]);
return [x,y,z];
}
However, none of my attempts yield the correct xy positions (z is always accurate).
Could someone please assist me in finding the right approach? I am unsure where I am going wrong.
Here is the fiddle for experimentation