# Drawing Segment using polar coordinates

I am trying to figure out a strategy for drawing a straight line using two intersecting rotating circles. (Imagine a turntable and it's arm, I need to figure out how to rotate them both in order for arm to draw a straight line on disc)

Here is what I am trying to do basically: https://youtu.be/VvTow_PRPis?t=10m11s

To simplify the problem. I have made this drawing:

There are 2 circles, with radiuses r (on the left) and R (on the right) R intersects r exactly at it's origin. Left circle is a rotating disc that I want to "draw" on. Right circle is representing an "arm" to draw "with".

Let's say I want to draw a segment AB on left circle.

point B is described by polar coordinates (alpha and "l") relative to circle "r" origin.

point A is currently at intersection arc. and is described by polar coordinates (beta and R) relative to circle "R" origin.

There should be a function "f prime" describing how angle of rotatoin of circle "r" changes over time. And there should be function f describing how angle of rotation of circle "R" changes over same period of time, in such a way that arm of "R" circle draws a straight line on the "r" disc.

I am curious first of all what kind of function is it (is it parabolic?), and how do I approach the figuring out of that equasions based on known variables (R, r, alpha, l, beta) Is this some kind of known problem? I am a software engineer trying to make an algorythm for that so, not really sure how to attack the math part of this. Would be happy if someone can suggest how to do this.

Thanks for taking a look!

Instead of drawing a line on the “turntable,” imagine the “tone arm” following a straight groove in the surface as the turntable rotates. For a given turntable rotation angle $\theta$, we want to find the tone-arm angle $\phi$ that keeps the business end of the tone arm in this groove.

Place the center of the turntable—the center of rotation—at the origin and the tone arm pivot (i.e., the center of the circle of radius $R$) at $\mathbf c=(-R,0)$, as pictured below. Note that we don’t really care about the radius $r$ of the turntable. It only serves to constrain the placement of the line segment’s endpoints.

We will first solve a slightly more general but simpler problem by extending our line segment to a line that is rotated around the origin. Define this line by its unit normal $\mathbf n_\theta=(\cos\theta,\sin\theta)$ and fixed distance $d\ge0$ from the origin. Here $\theta$ represents the angle that $\mathbf n_\theta$ makes with the positive $x$-axis. If you draw a perpendicular to this line through $\mathbf c$, it will be parallel to $\mathbf n_\theta$, so it, too, makes an angle of $\theta$ with the positive $x$-axis. Call the angle between this perpendicular and the tone arm, represented by the radial segment from $\mathbf c$ to the intersection of the line and circle, $\alpha$. The tone-arm angle is clearly $\phi=\theta-\alpha$. The signed distance from our rotating line to the tone-arm pivot $\mathbf c$ is given by $d-\mathbf n_\theta\cdot\mathbf c$ and so we have $$\cos\alpha={d-\mathbf n_\theta\cdot\mathbf c\over R}=\frac d R+\cos\theta.\tag{1}$$ Equipped with this relationship between turntable rotation and tone-arm angle, we can proceed with the specific problem.

Given the points $A=(x_a,y_a)$ and $B=(x_b,y_b)$, the unit normal of the line through them is $$\mathbf n=\pm\left({y_a-y_b\over\sqrt{(x_a-x_b)^2+(y_a-y_b)^2}},{x_b-x_a\over\sqrt{(x_a-x_b)^2+(y_a-y_b)^2}}\right).\tag{2}$$ The distance of this line from the origin is given by $\mathbf n\cdot A$ (also by $\mathbf n\cdot B$). Choose the sign for $\mathbf n$ that makes this quantity positive. Note that this sign choice matches the orientation of the triangle $\triangle{OBA}$, which is also the sign of the “cross product:” $s=\operatorname{sgn}(x_by_a-x_ay_b)$. This sign also tells us which way we’ll be rotating the turntable (positive being counterclockwise per the usual convention). I’ll leave working out the correct sign choice when the line passes through the origin to you.

Now we just need a range of valid values for the turntable rotation angle $\theta$ so that we stay on the segment $\overline{AB}$. Observe that $\theta$ doesn’t enter into equation (1) explicitly. As long as we have the line’s unit normal and its distance from the origin, we can compute the tone-arm angle. So, instead of calculating a unit normal for an absolute angle as we did above, we can take the initial unit normal that we computed in (2) and rotate it through some angle $\theta'$ to get the normal of the rotated line segment. This rotation can be effected using well-known formulas.

Since $A$ starts under the tone arm, the initial value of $\theta'$ is $0$. As we noted above, orientation of $\triangle{OBA}$ gives us our rotation direction, so it only remains to find the value of $\theta'$ that corresponds to having $B$ under the tone arm. It’s tempting to say that this is $\angle{AOB}$, but this is only true if $A$ and $B$ are at the same distance from the origin. Instead, we need the angle between $B$ and the intersection $B'$ of the tone-arm circle with a circle of radius $\|B\|$ centered on the origin. A straightforward calculation yields an $x$-coordinate of $-\|B\|^2/2R$ for this intersection, with corresponding $y$-coordinate $\pm\|B\|\sqrt{1-\|B\|^2/4R^2}$. We choose the sign here to match the sign of $A$’s $y$-coordinate. (As before, I leave sorting out the special case that $A$ lies on the $x$-axis to you.) Once we’ve chosen the correct $B'$, $\theta_{max}'$ is simply $\angle B'-\angle B$, normalized to lie in the interval $[-\pi,\pi]$.

We now have a way to compute a function $g:\theta'\mapsto\phi$ that gives us the tone-arm angle that tracks the rotating line segment. If the actual motion of the turntable is given by some arbitrary continuous function $f:t\mapsto\theta'$, the induced motion of the tone arm is then given by the composition $g\circ f$.

The above scheme doesn’t exactly match the problem’s setup or nomenclature, but I expect that you’ll be able to adapt it to them without any trouble.

• Wow! Thank you so much! this is more detailed than I could have expected! And yes, I think I can take it from here, I did made some calculations yesterday, but your approach seems to be requiring "less calculations" which is great because I will be needing to adapt this to a software that runs on limited power microcontroller. Thanks again! Nov 29 '16 at 6:46
• @AvetisZakharyan The problem intrigued me. My initial attempts involved computing the intersection of the rotated line segment and circle directly and got ugly quickly. Making the drawings with the extended line led me to look at the chord half-angle, after which things fell into place fairly quickly.
– amd
Nov 29 '16 at 8:23
• @AvetisZakharyan If you don’t need the value of the tone-arm angle $\phi$ per se, but only its sine and cosine, you might be able to speed things up by using the identities for trig functions of differences of angles. The unit normal $\mathbf n$ gives you $\cos\theta$ and $\sin\theta$ directly and you can get $\sin\alpha$ via the Pythagorean theorem. This computation involves a square root and some multiplication, but it might be faster than computing two trig functions and an inverse trig function.
– amd
Nov 29 '16 at 8:26
• I did the same initially! I tried to rotate the turntable linearly, and on each step get the line-circle intersection, which made something like a 2 pages of equations. So when I saw your method I instantly understood this is what I am looking for! :)) There is one other thing though that because in real life the motors move step by step, it means that the "further" from center the intersection is, the lower is "quality/resolution" of the image, thus I also need to kind of calculate a non-linear movement of turntable in order to move slower when points in question are further from center. Nov 29 '16 at 8:59
• as for the second comment, I do need exactly ϕ, because that's how I rotate the motors :) The way this works is at each very small iteration in time, I need to figure out to move or not move a motor by a single step (which is pretty small angle). So eventually I am changing ϕ over time. Nov 29 '16 at 9:01

I don't entirely understand what you are seeking, but it is not possible to draw a straight line with just two circles. A more complex mechanism is required, e.g., the Peaucellier linkage:

Image from Wikipedia article.

• Check this out: youtu.be/VvTow_PRPis?t=10m11s this is the kind of thing I want to do. this example seems to be doing it with just 2 circles, no? Nov 27 '16 at 18:08
• It's worth mentioning that the goal is to draw straight line ON the moving left circle. Nov 27 '16 at 18:33