I'm wondering if the texture to my sphere is somehow not being applied correctly, and if I can offset it somehow? I am trying to place a box at Sydney, Australia by supplying the lat/lon and converting to cartesian xyz coordinates. However, the box is not places in the correct location. My guess is since the original image is a Mercator map, when it's being applied to the sphere the lat/lon center point is not correct.
The code below is a minimal re-produceable example.
- I am loading an earth image and applying it to the sphere (radius = 400).
- I am then supplying the latitude/longitude for Sydney, Australia (33.8688, -151.2093) and converting to radians.
- Converting lat/lon to cartesian xyz (taken from: https://stackoverflow.com/a/1185413/3723165)
- Translating and pushing a box to that location.
Here's where that box is placed:
Re-produceable code
var img;
var theta = 0;
var r = 400;
function preload() {
img = loadImage('https://eoimages.gsfc.nasa.gov/images/imagerecords/79000/79765/dnb_land_ocean_ice.2012.3600x1800.jpg');
}
function setup() {
createCanvas(1600, 1200, WEBGL);
}
function draw() {
background(0);
rotateY(theta);
theta += 0.01;
texture(img);
sphere(r);
//Sydney, Australia Latitude/Longtidue
var lat = radians(33.8688);
var lon = radians(151.2093);
//cartesian coordinates
var x = r * Math.cos(lat) * Math.cos(lon);
var y = r * Math.cos(lat) * Math.sin(lon);
var z = r * Math.sin(lat);
push();
translate(x, y, z);
fill(255);
box(100, 10, 10);
pop();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.16/p5.js"></script>