Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert coordinates on a circle to coordinates on a square?

I'm currently working on a game in LBP2 that has modify the way a controller gives input. This question: How can I convert coordinates on a square to coordinates on a circle? Has helped me quite a lot with what I am doing, but I do have one problem. I need the inverse function of the one they give. They go from square -> circle, and I've tried searching all over for how to map a circle to a square.

The function given in the previous question is:

xCircle = xSquare * sqrt(1 - 0.5*ySquare^2)

yCircle = ySquare * sqrt(1 - 0.5*xSquare^2)

From Mapping a Square to a Circle

My question is given xCircle and yCircle... how do I find xSquare and ySquare?

I've tried all of the algebra I know, filled up two pages of notes, tried to get wolfram alpha to get the inverse functions, but this problem is beyond my abilities.

Thank you for taking a look.

like image 826
Jonathan Gawrych Avatar asked Nov 03 '12 17:11

Jonathan Gawrych


People also ask

How do you turn a square into a circle?

How do I convert a square to a circle? Converting a square to a circle refers to finding a circle with the same area as the square. So if we want to convert a square to a round figure, the radius of the resulting circle will be s/√π , where s is the side of the square.

What is coordinates of a circle?

The general form of the equation of a circle is: x2 + y2 + 2gx + 2fy + c = 0. This general form is used to find the coordinates of the center of the circle and the radius, where g, f, c are constants.


2 Answers

x = ½ √( 2 + u² - v² + 2u√2 ) - ½ √( 2 + u² - v² - 2u√2 )
y = ½ √( 2 - u² + v² + 2v√2 ) - ½ √( 2 - u² + v² - 2v√2 )

Note on notation: I'm using x = xSquare , y = ySquare, u = xCircle and v = yCircle;

i.e. (u,v) are circular disc coordinates and (x,y) are square coordinates.

grid mapping

For a C++ implementation of the equations, go to
http://squircular.blogspot.com/2015/09/mapping-circle-to-square.html

See http://squircular.blogspot.com for more example images.
Also, see http://arxiv.org/abs/1509.06344 for the proof/derivation

This mapping is the inverse of

u = x √( 1 - ½ y² )
v = y √( 1 - ½ x² )


P.S. The mapping is not unique. There are other mappings out there. The picture below illustrates the non-uniqueness of the mapping.

Boston Celtics squared

like image 151
Ch Fong Avatar answered Sep 24 '22 02:09

Ch Fong


if you have xCircle and yCircle that means that you're on a circle with radius R = sqrt(xCircle^2 + yCircle^2). Now you need to extend that circle to a square with half-side = R,

if (xCircle < yCircle)
     ySquare = R, xSquare = xCircle * R/yCircle
else
     xSquare = R, ySquare = yCircle * R/xCircle

this is for the first quadrant, for others you need some trivial tweaking with the signs

like image 23
panda-34 Avatar answered Sep 22 '22 02:09

panda-34