How to calculate 3D arc between two lines 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? 

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

 A: 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.
A: Sketch of an algorithm, too long for a comment. Maybe someone will edit to provide the actual linear algebra.


*

*Translate the three points by $-P2$ to move $P2$ to the origin.

*Rotate to move (the translates of) $P1$ and $P3$ to the $x-y$ plane.

*Solve the two dimensional problem.

*Rotate and translate the answer back.
A: This is a 2-D problem in disguise, so let’s solve it there first. Assuming that $P_2$ is the vertex, the center of the arc must lie somewhere on the angle bisector of $\angle{P_1P_2P_3}$. Let $\mathbf u_{21}={P_1-P_2\over\|P_1-P_2\|}$ and $\mathbf u_{23}={P_3-P_2\over\|P_3-P_2\|}$, the unit vectors in the directions of the two given rays. Then $\mathbf v=\mathbf u_{21}+\mathbf u_{23}$ is their angle bisector, and so $P_c=P_2+\lambda\mathbf v$. The arc has a given radius $r$, so we just need to find the value of $\lambda$ for which the distance of $P_c$ from either of the lines $\overline{P_2P_1}$ or $\overline{P_2P_3}$ is equal to $r$. This distance is equal to the length of the orthogonal rejection of $\lambda\mathbf v$ from either $\mathbf u_{21}$ or $\mathbf u_{23}$, i.e., $$\|\lambda\mathbf v-(\lambda\mathbf v\cdot\mathbf u)\mathbf u\|=r.$$ By construction $\lambda\ge0$, so this gives $$\lambda = {r\over\|\mathbf v-(\mathbf v\cdot\mathbf u)\mathbf u\|}.$$ With $\lambda$ in hand, we can compute the three points of interest: $$P_c=P_2+\lambda\mathbf v \\ P_a = P_2+\lambda(\mathbf v\cdot\mathbf u_{21})\mathbf u_{21} \\ P_b = P_2+\lambda(\mathbf v\cdot\mathbf u_{23})\mathbf u_{23}.$$ (The last two are just the projections of $P_c$ onto the two given rays.)  
Nothing in the above solution relies on the points and vectors being two-dimensional, so it transfers directly to 3-D. Depending on how precise your values for the initial points are, you might get a better result in practice by computing $\lambda$ using each of the two unit vectors and taking the average of the two resulting values.  
It may help with the computations to note that $$\mathbf v\cdot\mathbf u_{21}=\mathbf v\cdot\mathbf u_{23}=1+\mathbf u_{21}\cdot\mathbf u_{23}$$ and so $$\mathbf v-(\mathbf v\cdot\mathbf u_{23})\mathbf u_{23} = \mathbf u_{21}-(\mathbf u_{21}\cdot\mathbf u_{23})\mathbf u_{23} \\ \mathbf v-(\mathbf v\cdot\mathbf u_{21})\mathbf u_{21} = \mathbf u_{23}-(\mathbf u_{21}\cdot\mathbf u_{23})\mathbf u_{21}$$ that is, the orthogonal rejection of $\mathbf v$ from one of the unit vectors is equal to the orthogonal rejection of the other unit vector from it (which, by symmetry, all have equal lengths). Thus, computing $\mathbf v$ explicitly might not be necessary (although it’s only a couple of additions). However, I don’t see a good way to avoid having to compute three square roots when following this approach.
A: The equation of a sphere is $(x-x_0) ^2 + (y - y_0)^2 + (z-z_0)^2 = r^2$ where the center of the sphere is $(x_0, y_0, z_0)$. This should give you three equations (one for each point) with three unknowns. You can then solve for the unknowns. Can you take it from here?
Bob
