# Connect circle and ray

source : geometry.puzzles "circle + ray" From : green_thumb_wannabe

We want to connect an oriented circle to a ray by an oriented circle with given radius.
I will discard the convention for "negative radius" and just keep the problem simpler as :

Given a circle (C), centered in C with radius rC,
A point R on this circle and a ray (R) from R with angle Ra with horizontal.
To connect the circle and the ray by a circle (E) with given radius rE so that the path can be walked continuously starting from (C) anticlockwise, then (E) clockwise, then on the ray, in direction of the ray.

Without the orientation constraint, the problem is easy, and has at most 8 solutions. With the given orientation, there is only one.
The problem is then to find (construct, calculate) directly this correct solution, without the need to "choose" among the 8.

Consider what happens at contact point between (C) and (E). We change direction from clockwise to anticlockwise, this just implies that the circles touch externally.
Hence center E lies on a circle (C'), centered in C with radius |rC| + |rE|.
Now, at contact point between (E) and ray (R), anticlockwise to ray direction simply means that circle (E) lies "on the left" of the ray, looking from R in direction of the ray.
Center E lies then on a parallel ray (R'), with the same direction as (R), and starting at a point K with |RK| = |rE|, and oriented angle ((R), RK) = +90°.

Hence the construction, with notes on how it is done with JavaSketchpad :

We start from a point C and radius rC.
The rC point is constrained on a horizontal Cx ray (hidden) as a "Point on object".
These two draggable points define circle (C).
Choose a point R on this circle (draggable "Point on object")
A hidden circle and a draggable "Point on object" Ra allows to fix the direction of ray (R) (oriented from R to Ra).
On (hidden) ray Cx, a draggable "Point on object" rE defines rE.
That's all for the data.

C_rE is copied at R (VectorTranslation), then rotated to lie on ray (R), then rotated further by +90° to get point K.
A parallel ray (with same direction then) to (R) is drawn from K.
Circle (C') with center C and radius |rC| + |rE| is drawn
E is 1st intersect (Intersect1) of ray from K with this circle.
With these orientations, Intersect1 always exist, and is the correct one :
K also lies inside circle (C') as locus of K for various R is a translated circle from (C), in direction Ra+90°, and by |rE|.
Intersect 2 is outside the ray (on the line extension).

Then it is easy to construct the contact points by intersecting (R) and a perpendicular to (R) from E
and intersecting circle (C) with segment CE.
From center E and contact point H, we draw circle (E)

#### Other solutions

If we replace "ray" by "line", we get two solutions.
Then, rotating to K by -90° instead of +90° (that is the reflection from line (R)) gives two more solutions.
Then replacing |rC| + |rE| by |rC| - |rE|, doubles the solutions, for a total of up to 8 solutions.
All the eight solutions are possible only if rE is "small enough", and there is "enough room" between (R) and (C). Otherwise there are less.

#### Calculations

From this, it is easy to get the direct calculation process for coordinates of E :
Define K as :
 xK = xR + rE.cos(Ra + 90°), yK = yR + rE.sin(Ra + 90°)

Then the ray from K can be parametric defined as :
 x = xK + t.cos(Ra) y = yK + t.sin(Ra) t > 0

Intersecting this line (solving the quadratic in t) with circle x² + y² = (|rC| + |rE|)² gives two solutions,
but the only one we want is for t >0 (on the ray from K) so in the quadratic, we choose the + sqrt.