Hi, I am trying to find the x and y coordinate for given longitude and latitude. I want to display cubes in my application using the x and y coordinates. I used the following formula:
public calcPosFromLatLonRad ( lat: number, lon: number, radius: number ) {
var phi = (90 - lat) * (Math.PI / 180);
var theta = (lon + 180) * (Math.PI / 180);
const x = -(radius * Math.sin(phi) * Math.cos(theta));
const z = (radius * Math.sin(phi) * Math.sin(theta));
const y = (radius * Math.cos(phi));
console.log('x Koordinate: ' + x + ' y Koordinate: ' + y + 'z Koordinate: ' + z);
return [x, y, z];
}
Then I tried:
const x1 = this.calcPosFromLatLonRad(52.387980, 9.719260, 100);
const pos1x = x1[0];
const pos1y = x1[1];
const pos1z = x1[2];
cube2.position.set(pos1x, pos1y, pos1z);
camera.position.z = 5;
scene.add( cube2);
const animate = () => {
requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
};
But I don’t see anything on my display. What I am doing wrong?