2

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
CRS
  • 827
  • 2
  • 13
  • 20
  • 1
    possible duplicate of [Converting from longitude\latitude to Cartesian coordinates](http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates) – Justin ᚅᚔᚈᚄᚒᚔ Apr 09 '12 at 20:55
  • Like Lev said, what's the problem? – Joel Cornett Apr 09 '12 at 20:56
  • the problem is that once i do the conversion what should the magnitude be to multiply it by – CRS Apr 09 '12 at 21:46
  • In your angleToPoint functions, which are suspect to begin with, so regardless of lat/long passed in, your return values are going to be very small (-1 to +1 range). Try multiplying the return value by something like the pixel width of the area you're trying to position the cities in. But be aware that your angleToPointX gives you a very unusual choice of projection. – Russell Borogove Apr 09 '12 at 21:52

2 Answers2

1

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.

Russell Borogove
  • 18,516
  • 4
  • 43
  • 50
0

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

inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241