[Math] How to calculate 3D arc between two lines

3dgeometry

I have three known points P1,P2,P3 in X,Y,Z coordinates and known radius. How do I find the center point(Pc), start point(Pa) and end point(Pb) of the arc between two lines in 3D?
enter image description here

I could solve it for 2D, but it is confusing to calculate for 3D case.
enter image description here

Best Answer

In fact, it's a 2D problem, you just have to choose the right coordinate system. Let $$\vec{P_2P_1}=P_1-P_2$$ the vector pointing from $P_2$ to $P_1,$ and $$n_a=\frac{\vec{P_2P_1}}{|\vec{P_2P_1}|}$$ the normalized (length $1$) vector, $$\vec{P_2P_3}=P_3-P_2$$ the vector pointing from $P_2$ to $P_3,$ and $$n_b=\frac{\vec{P_2P_3}}{|\vec{P_2P_3}|}$$ the normalized vector. The angle $\alpha$ between these two directions is defined by the scalar product: $$\cos\alpha=n_a\cdot n_b.$$ Clearly, $P_c$ lies on the bisector of this angle. The distance from $P_2$ to $P_a$ and $P_b$ must be the same, $r/\tan\frac{\alpha}{2}$, so $$P_a=P_2+\frac{r}{\tan\frac{\alpha}{2}}\,n_a$$ and $$P_b=P_2+\frac{r}{\tan\frac{\alpha}{2}}\,n_b,$$ and you get $P_c$ from $$P_c=P_2+\frac{r}{\sin\alpha}\,(n_a+n_b).$$
While these formulas show the simple geometry more clearly, @Nominal Animal pointed out that it might be better to avoid calculating trigonometric functions. Indeed, we can use the cross product to express $\sin\alpha$: $$\sin\alpha=|n_a\times n_b|.$$ For calculating $P_a, P_b$, we can use $$\tan\frac{\alpha}{2}=\frac{\sin\alpha}{1+\cos\alpha}=\frac{|n_a\times n_b|}{1+n_a\cdot n_b}.$$ So everything can be determined by vector operations, alone.