Tuesday, July 05, 2005

Mapping a Square to a Circle

I wanted to come up with a nice way to map all the points in the square

img1

to the points in the unit circle, such that the points along the axes are unchanged, and the corners get normalized. The way I went about this was to think of a line of constant x (as well as a line of constant y) getting mapped to an ellipse in the circle. So for our first requirement to hold true, the ellipse for some constant x has the equation

img2

Now we want to make sure that points along the curve at the top of the circle (from 45 degrees to 135 degrees) are all accounted for. So for x between -1 and 1, we want the ellipse to pass through the point

img3

So we'll plug that in, and that should give us the b coefficient for our ellipse

img4

So the ellipse for constant x is

img5

Similarly, for a line of constant y, we get the ellipse

img6

Solving the first for x', we get

img7

Plugging this into the second equation gives

img8

and by symmetry we can see that the mapping

img9

takes the square from -1 to 1 on the x and y axes, to the unit circle. Here's a demonstration of that mapping, which shows its effect on various grid lines.

slices

I'd like to find a way to map a cube to the unit sphere. Hopefully I can get that ready for the next post.

8 comments:

  1. Thanks for your work with finding this mapping, it saved a bit of time.

    ReplyDelete
  2. Hello, just wanted to ask; What will the inverse mapping be like?

    ReplyDelete
  3. What happens it we want the inverse result, if we got the circle coordinates and we want to obtain the related squared coords??

    ReplyDelete
  4. And what are the functions that let us to come back to square coordinates?

    What happen if we have circle coords tha we want to turn to their related circle coords??

    ReplyDelete
  5. hi
    what about mapping a circle to a square?
    thanks

    ReplyDelete
  6. I'm curious, would this work for squares with a longer side length?

    e.g.

    -2 <= x <= 2

    Simply by changing the final equation to the length of the half extents instead of 1?

    ReplyDelete
  7. Great work!

    ReplyDelete
  8. I know this is a really old post, but check this out http://www.math.purdue.edu/pow/spring2012/pdf/problem11.pdf

    ReplyDelete