# translate coordinates on circle to percentage?

I'm coming more from a programming point of view but the question is pure math. The only strange thing, I guess, is that the coordinate system is like this:

0,0------->+x
|
|
|
|
+y


In other words, there is no such thing as -x or -y in this case.

Now, I have a circle which is drawn in this system, and I want to translate any given point on the circle to a percentage, i.e. assuming that the circle is drawn sequentially- such that the first drawn point is 0% and the last (connecting) point is 100%

Maybe the last important bit of info, those first and last points are right around +x (i.e. highest x) and +y/2. If I'm explaining it well enough, then it should be that the point on the circle closest to 0,0 would translate to 37.5% and the coordinates (+x/2, +y) would translate to 75% and (+x,+y/2) would be either 100% or 0%.

Happy for any solutions and/or help clarifying the question properly.

Thanks!

-

To avoid confusion, I'm going to call your "highest $x$" $x_\max$, instead of $+x$. Also, you didn't say whether $+x$ and $+y$ had to be the same, so my solution will not assume that and deal with an ellipse, rather than a circle.

From your description, it seems this ellipse should have center at $(x_\max/2,y_\max/2)$, and be tangent to $x=0$ and $y=0$. Also, your starting point is $(x_\max,y_\max/2)$, and you proceed counterclockwise in your coordinate system, which would have been clockwise if $y$ went up instead of down.

One parametrization of this normally-clockwise ellipse would be $((x_\max/2)\cos(-\theta)+(x_\max/2),(y_\max/2)\sin(-\theta)+(y_\max/2))$, where $\theta=0$ is the start and $\theta=2\pi$ is the end. However, we can simplify this a bit, using algebra and facts about trigonometric functions: $\left((x_\max/2)\left(1+\cos(\theta)\right),(y_\max/2)\left(1-\sin(\theta)\right)\right)$.

Since $\theta$ goes from $0$ to $2\pi$, it doesn't go from $0$ to $100$. So if the percentage is $p$ (where $100\%=1$, not $100$), then $\theta=2\pi p$, and we have $\left((x_\max/2)\left(1+\cos(2\pi p)\right),(y_\max/2)\left(1-\sin(2\pi p)\right)\right)$.

However, the above does the opposite of what you wanted: it takes the percentage as input and gives you the point. We need to go backwards, and we'll need atan2 (the key to conversion from Cartesian to Polar): $$(x,y)=\left(\frac{x_\max}2\left(1+\cos(2\pi p)\right),\frac{y_\max}2\left(1-\sin(2\pi p)\right)\right)$$ $$\Rightarrow\left(x-\frac{x_\max}2,y-\frac{y_\max}2\right)=\left(\frac{x_\max}2\cos(2\pi p),-\frac{y_\max}2\sin(2\pi p)\right)$$ $$\Rightarrow\left(\frac{x-x_\max/2}{x_\max/2},\frac{y-y_\max/2}{-y_\max/2}\right)=\left(\cos(2\pi p),\sin(2\pi p)\right)$$ $$\Rightarrow\left(\frac{2x}{x_\max}-1,1-\frac{2y}{y_\max}\right)=\left(\cos(2\pi p),\sin(2\pi p)\right)$$ $$\Rightarrow\mathrm{atan}2\left(\frac{2x}{x_\max}-1,1-\frac{2y}{y_\max}\right)=2\pi p$$ $$\Rightarrow\frac1{2\pi}\mathrm{atan}2\left(\frac{2x}{x_\max}-1,1-\frac{2y}{y_\max}\right)=p$$

It's not very pretty, but I believe the above formula is what you're looking for (although you may only care about it in the special case where $x_\max=y_\max$). You can multiply by 100 if you prefer "100" to "1" in the case of a full rotation.

-
Thanks- I will try to implement it! – davidkomer Dec 30 '13 at 6:54
@davidkomer Did it work/do anything unexpected? – Mark S. Jan 1 '14 at 16:44
To be completely honest, it turns out I was able to solve my problem a bit of a different way in the programming so I didn't need to try and implement this in the end. I will give it a go when I get back to the project again on Sunday/Monday and let you know. Thanks for the push! – davidkomer Jan 2 '14 at 17:03