Question

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
Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top