I’m trying to move a shape along an equirectangular projection by converting the pixels into spherical coordinates, moving them, and then converting them back. Its been a while since I’ve done any kind of mathematics like this, so I’m sure I’m doing something wrong or using the wrong equations or something, I just don’t know what.
This is what I’m trying to achieve:
when the sphere in 3d space looks like:
here’s the code for moving the points:
def __move_point(point, width, height, dx, dy): # dx and dy are in degrees
lat, long = __convert_to_lat_long(point[0], point[1], width, height)
new_lat = lat + dy
new_long = long - dx
new_lat = np.clip(new_lat, -90, 90) # np is numpy
if new_long < -180:
new_long += 360
elif new_long > 180:
new_long -= 360
return __convert_to_xy(new_lat, new_long, width, height)
def __convert_to_lat_long(x, y, width, height):
latitude = (0.5 - (y / height)) * 180
longitude = ((x / width) - 0.5) * 360
return (latitude, longitude)
def __convert_to_xy(lat, long, width, height):
x = (long / 360 + 0.5) * width
y = (0.5 - lat / 180) * height
return (int(x), int(y))
This however doesn’t cause any polar distortion, only translates the shape up/down. Before image:
and after I run the code:
There’s a lot of information on how to do this with Cartesian coordinates, but I’m not using Cartesian coordinates on purpose.