Converting a set of Polar coordinates to Cartesian coordinates

810 Views Asked by At

Background

I'm a programmer working on a Geographical Information system. Part of our program outputs region data as a set of polar coordinates with associated data. For long and complicated performance reasons, we (Well, I) am tasked with re-writing this data to be rendered as an image. One problem among many is that our image drawing library takes Cartesian coordinates, not polar ones.

Questions

  • Given a set of polar coordinates, how would I convert them to flat (2D) Cartesian coordinates?

  • Given a known center-point (the data is always bounded to a circular area), how do I shift the coordinates such that the center-point is 0,0 on a 2D grid?

  • How can I avoid distortions of the coordinates near the poles?

I apologize if this is a trivial question, but it's well outside of my skillset. Thank you for your time.

1

There are 1 best solutions below

3
On

Assuming that the region in question is small enough compared to the Earth that it can be considered flat, the conversion from polar to Cartesian is \begin{eqnarray} x &=& r\cos\theta \\y &=& r\sin\theta \end{eqnarray}

However, as you noticed in your third question, if your data is a grid in $r$ and $\theta$, this will not give you a grid in $x$ and $y$. If this is a problem (perhaps because your image program requires a grid), you'll have to interpolate this data set to a grid. There should be software libraries that can do this more effectively than anything you can write. If for some reason you must write your own, you should be able to code up a simple plane interpolation between the three nearest data points.

As for your second question, if you are given a set of points bounded by a circle in terms of polar coordinates whose origin is not the center of the circle, I would ask whoever's taking the data what on earth he was thinking. The solution is to transform to Cartesian, then apply the translation by subtracting off the coordinates of the center.

EDIT: It appears the question was about transforming latitude and longitude data into Cartesian, which changes the answer to my question considerably.

For a small, circular area of the Earth, you'll want to use an azimuthal projection. Although any of them will probably work fine for small areas, I'd recommend either the gnomonic projection, the unique projection that maps great circles to straight lines, or the stereographic projection, which is locally shape-preserving. The formulas for the transforms can be found in the links.