# Project line onto a circle

Say i have a straight line, how would you project it on to a circle as an arc length where by the centre normal of the line is fixed to (0,1)*r on the circle?

Basically what i am trying to do in my code is i have a mesh and i want to warp it around a circle, but i don't know the math for it.

Here is an image to visually show it:

I drew it with a mouse so its not great.

How do you figure out the position on the circumference, based from the local distance from the green marker for some circle with known origin and radius.

• Unclear: do you want to project the line (if yes which projection ?) or wrap it around, keeping the length ? – Yves Daoust Oct 15 '18 at 7:29
• I want to keep the length, does projection have a more specific meaning? – WDUK Oct 15 '18 at 8:13
• Yes it does. Nosrati's answer is an example. – Yves Daoust Oct 15 '18 at 8:22
• You are saying that you have a mesh but ask about a line. What is the connection ? – Yves Daoust Oct 15 '18 at 8:22
• @YvesDaoust i plan to do it for a 2D plane once i understood the math on a sphere but i wanted to start with a circle and a basic line mesh which is just a series of vertex positions in my application which is called the mesh. – WDUK Oct 15 '18 at 21:00

The point of abscissa $$s$$ on the line wraps to a point at curvilinear abscissa $$s$$ from the top point, which is also at an angle $$s$$ clockwise from that point.

In polar coordinates

$$\theta=\frac\pi2-s,\\\rho=1$$ and in Cartesian

$$x=\sin s,\\y=\cos s.$$

Let $$y=1$$ be your line and $$x^2+y^2=1$$ be the circle. Any point $$(x,1)$$ project to the point $$(\cos\operatorname{arccot} x, \sin\operatorname{arccot} x)$$ on the circle. Also any point $$(\cos t, \sin t)$$ on the circle project to the point $$(\cot t,1)$$ on line.

• I am a bit confused why you are using different trig functions to some other answers. I'm not familiar with arccot and cot – WDUK Oct 15 '18 at 21:01

The point that is $$g$$ to the right on the line corresponds to $$g$$ on the circumference in clockwise direction. Since the whole circumference is $$2\pi r$$, it is a ratio of $$\frac{g}{2\pi r}$$ that directly corresponds to the angle in radians $$\varphi = \frac{g}{r}$$.

Finally you need a polar transformation

$$x=r\sin\varphi = r \sin \frac{g}{r}$$

$$y=r\cos\varphi = r \sin \frac{g}{r}$$

Note that, in contrast the the usual definition of a polar transformation, the $$\varphi=0$$ is at the top and we use clockwise radians, so we switch $$sin$$ and $$cos$$.

For the left part of the line you do not have to change anything. A negative value of $$g$$ will result in a negative $$\varphi$$, but since $$cos$$ and $$sin$$ are periodic, this corresponds to a point on the circumference in the counterclockwise direction.

• Mind the typo . – Yves Daoust Oct 15 '18 at 8:21
• @YvesDaoust Feel free to edit! – koalo Oct 15 '18 at 8:36