简体   繁体   中英

Trying to convert longitude/latitude to Cartesian coordinates

i am trying to convert a city's longitude/latitude position to Cartesian so i can then convert it to pixel position to display on a pygame screen, but i am having trouble figuring it out.

def ConvertPoint(self, Long, Lat, height, width):
    self.x = Long
    self.y = Lat
    self.x = angleToPointX(self.x, self.y, 3959)
    self.y = angleToPointY(self.x, self.y, 3959)
    pygame.draw.circle(self.window, (255,0,0), (int(self.x), int(self.y)), 5)
    print(self.x, self.y)

functions:

def angleToPointX(lat, long, magnitude=1.0):
    V = (math.cos(lat) * math.cos(long))
    return V

def angleToPointY(lat, long, magnitude=1.0):
    V = (math.sin(lat))
    return V

What map projection are you using? Latitude/longitude can be used directly as y/x in a cylindrical projection - that's the simplest way to go for a game. Otherwise, the conversion will be entirely dependent on the choice of projection.

I've faced similar problems in the past and this is what helped me through it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM