Calculate center of circle tangent to two lines in space

Good afternoon everyone! I am facing a problem which is straining my memory of linear algebra. I have:

• Three points with known coordinates, forming a triangle in space. Let the coordinates be R(top), P(left bottom) and Q(right bottom) (only rough positions)
• I'm not interested in the triangle as such, but in its two lines QP and QR
• These lines are tangent to a circle of known radius (basically I'm trying to smooth the angle via a radius, like in CAD)

I need the equation of the circle, so I can pick any point I want between P and R to smooth out the angle. The angle is <180°, so there should exist one solution (correct me if I'm wrong)

I found an image which illustrates my problem: You can see my points R,P,Q, aswell as my circle which is tangent to both rays originating in Q. Please note, that PQ does not necessarily have to be horizontal and that the angle $\alpha$ is not always 50°. My goal is to calculate the origin O and thus the complete equation of my circle in the form $\vec{r}(t)=\vec{c}+r\cdot\cos{\varphi}\cdot\vec{a}+r\cdot\sin{\varphi}\cdot\vec{b}$

Plan I have made so far:

1. Calculate $\vec{PR}$
2. Calculate $a=\arccos{\frac{\vec{QP}\bullet\vec{QR}}{\left|\vec{QP}\right|\cdot\left|\vec{QR}\right|}}$
3. Calculate $b=\frac{\pi}{2}-a$

From here on it gets tricky. I know, that the origin is on the ray seperating the angle in Q in exact half. If I project that ray on my line $\vec{PQ}$, will I end up in the exact middle? Couldn't I just do something like "rotate $\frac{\vec{PR}}{2}$ around an axis through P by b degrees ccw, where the axis is perpendicular to the triangles plane"

I start to get lost here.

• The perpendicular vector would be $\vec{QP}\times\vec{QR}$, wouldn't it?
• The German Wikipedia suggests for rotating via an rotation-matrix $R_{\hat{n}}(\alpha)\vec{x}=\hat{n}(\hat{n}\cdot\vec{x})+\cos\left(\alpha\right)(\hat{n}\times\vec{x})\times\hat{n}+\sin\left(\alpha\right)(\hat{n}\times\vec{x})$ where $\vec{n}$ is the unity-normal-vector around which to rotate. Can I use this formula?
• How do I finally compile my circle-equation?

Edit: And yes, I have seen this, but it didn't help :-)

• R and P should not belong to the circle, as it makes the drawing confusing. – ja72 May 16 '14 at 13:07
• Well, R and P are the points the lines are tangent to the circle in. This is not my sketch anyway, I found it while researching my problem and found it quite handy. – lhiapgpeonk May 16 '14 at 13:09
• If P and R are defined the problem is over constrained. If the radius is defined also, it is super over constrained.You can get the radius from the distance QR using the triangle $QOR$ – ja72 May 16 '14 at 13:24
• I suppose the image I chose is quite confusing after all. And my description aswell. I use the radius to roughly(!) create points P and Q. That doesn't make very much sense either now, does it? – lhiapgpeonk May 16 '14 at 13:30

What you want is the tangent, tangent, radius algorithm. One way to handle this is as follows:

1. Measure the angle $$\alpha = \widehat{RQP}$$. This is done using the cross product and dot product from the coordinates of the points.
2. Construct the bisector of the angle and note that if the radius is known as $$h$$ the distance from the vertex to the circle center $$QA$$ is $$s=\frac{h}{\sin \frac{\alpha}{2}}$$
3. Numerically create a vector of length $$s$$ along $$QR$$ and rotate it by $$\frac{\alpha}{2}$$ to find point $$A$$. • That looks lovely, I'll give it a try! Do you have a hint on how to rotate a vector "easyly"? – lhiapgpeonk May 16 '14 at 13:26
• $(x',y') = (x \cos \theta - y \sin \theta, x \sin \theta + y \cos \theta)$ – ja72 May 16 '14 at 14:19
• That pointed me the right direction. Although I did choose a slightly different implementation this is the best answer to my question. Thank you! – lhiapgpeonk May 22 '14 at 6:48
• Is s arc length? Where is O? – dustin Nov 1 '16 at 13:19
• O = Q. I suppose I made a typo. And s=AQ – ja72 Nov 1 '16 at 17:10

I would suggest something like this to find the center of your circle: Since you know the coordinates of $P$ and $Q$, you can find a normalized vector that is perpendicular to $\vec{QP}$, using the inner product. You also said that $PQ$ is a tangent line meaning, the vector $\vec{PO}$ is perpendicular to $\vec{PQ}$. Given the fact you can calculate a vector perpendicular to $PQ$ means you only have to travel along this vector over a lenght of your (known) radius. If you start in $P$ you will end up exactly at the center of your cirlce.

• Ah yes. I was wondering if I could use the dot-product, but somehow I am lost on how to calculate this normal vector. The dot-product would give me $a_1b_1+a_2b_2+a_3b_3$. There are a great many variables in that aren't there? In the end I want to program a general solution, so I would have to solve any equations symbolically first to keep calculation time low. – lhiapgpeonk May 16 '14 at 13:13
• @lhiapgpeonk You were speaking of a triangle, wich is a two-dimensional object living in a certain plain, meaning the dot product wil result in a single vector. To succesfully do this you need to calculate the plain you are in first. This would result in more calculations, yes. But eventually the can be transformed in to formulae depending only on your three point and you radius. – gebruiker May 16 '14 at 13:22

Another way to solve this, if you know the radius $$r$$, is to offset the two tangent lines by that amount and find where they intersect. That would be the center of the circle. Consider the given circle with the radius $$r_1$$ as a scaled version of the inscribed circle of the given $$\triangle ABC$$ with the inradius $$r$$. Then we have a scaling factor

\begin{align} k&=\frac {r_1}r , \end{align}

and the center of the given circle is \begin{align} I_1&=B+k\cdot\vec{BI} . \end{align}

Reminder: the center of the inscribed circle in terms of the points $$A,B,C$$ and side lengths $$a,b,c$$ is found as

\begin{align} I&=\frac{a\,A+b\,B+c\,C}{a+b+c} , \end{align}

and the tangential points of the incircle \begin{align} A_t&=\tfrac12\cdot(B+C)+\frac{b-c}{2a}\cdot(B-C) ,\\ C_t&=\tfrac12\cdot(A+B)+\frac{a-b}{2c}\cdot(A-B) . \end{align}

There is no unique solution to this problem. There are infinitely many circles which will be tangent to the two given lines. The centre's of these circles, as pointed in the solution given, will be on the angle bisector. See the animation below: 