I'm trying to implement Bowyer-Watson algorithm. Currently performance is stuck behind calculating the circumsphere of a tetrahedron.
I tried using this http://mathworld.wolfram.com/Circumsphere.html. It works but it is slow.
Next i tried this https://www2.mps.mpg.de/homes/daly/CSDS/t4h/tetra.htm#Q1-1-7. But this has the problem of not always returning a solution. For example vertices (-1000, 0, -1000), (1000,0,-1000), (0,0,1000), (0,1000,0). I mostly keep getting -Infinity or NaN.
Is there a way to make the first one faster (leave some equations out, make some equations simpler), or make the second one always work (so that the linear equation system can handle vectors that can have 2 coordinates 0)? Or is there some third way that is even better?
EDIT
THe way i tried using to solve the linear system.
2d1x*x + 2d1y*y + 2d1z*z = d1^2 (1)
2d2x*x + 2d2y*y + 2d2z*z = d2^2 (2)
2d3x*x + 2d3y*y + 2d3z*z = d3^2 (3)
(2) - d2x/d1x *(1)
(3) - d3x/d1x *(1)
2d1x*x + 2d1y*y + 2d1z*z = d1^2 (1)
0 + d2x/d1x * 2d2y*y + d2x/d1x * 2d2z*z = d2x/d1x * d2^2 (2)
0 + d3x/d1x * 2d3y*y + d3x/d1x * 2d3z*z = d3x/d1x * d3^2 (3)
(3) - (d2y*d3x)/(d2x*d3y) *(2)
2d1x*x + 2d1y*y + 2d1z*z = d1^2 (1)
0 + d2x/d1x * 2d2y*y + d2x/d1x * 2d2z*z = d2x/d1x * d2^2 (2)
0 + 0 + (d3x*d3y)/(d2x*d2y) * 2d3z*z = dx3/d1x * 2d2y * d3^2 (3)

Following are some alternatives.
Alternative I - compute barycentric coordinates of circumcenter $O$ directly.
Given a tetrahedron $T$ with vertices $v_0, v_1, v_2, v_3$. Let
Once you have computed $V$ and $S_i$, the circumradius $R$ is given by the formula${}^{\color{blue}{[1]}}$.
$$6VR = \sqrt{p(p-aa_1)(p-bb_1)(p-cc_1)} \quad\text{ where }\quad \begin{cases} a &= \ell_{01}, a_1 = \ell_{23}\\ b &= \ell_{02}, b_1 = \ell_{31}\\ c &= \ell_{03}, c_1 = \ell_{12}\\ p &= \frac12(aa_1 + bb_1 + cc_1) \end{cases} $$ The circumradii $R_i$ for the faces can be computed by corresponding $2$-d counterparts: $$4S_i R_i = \prod_{j < k;\\ j \ne i,k\ne i}\ell_{jk} \quad\iff\quad \begin{cases} 4 S_0 R_0 &= \ell_{12}\ell_{13}\ell_{23} = a_1b_1c_1\\ 4 S_1 R_1 &= \ell_{02}\ell_{03}\ell_{23} = a_1 b c \\ 4 S_2 R_2 &= \ell_{01}\ell_{03}\ell_{13} = ab_1 c\\ 4 S_3 R_3 &= \ell_{01}\ell_{02}\ell_{13} = ab c_1 \end{cases} $$ The barycentric coordinates for circumcenter $O$, i.e. those four numbers $\lambda_0,\ldots,\lambda_3$ such that
$$O = \sum_{i=0}^3 \lambda_i v_i\quad\text{ with }\quad \sum_{i=0}^3 \lambda_i = 1$$
is then given by the formula
$$3V\lambda_i = S_i\sqrt{R^2 - R_i^2}$$
Alternative II - compute circumcenter $O$ using dot and cross products.
Same notation as previous alternative. Let $u_i = v_i - v_0$ for $i = 1,2,3$ and $p = O - v_0$.
We have $$R^2 = \|p\|^2 = \| u_1 - p \|^2 = \| u_2 - p \|^2 = \| u_3 - p \|^2$$ Cancelling the common term $R^2$ from these equalities, we obtain $$ u_1 \cdot p = \frac12\ell_{01}^2,\quad u_2 \cdot p = \frac12\ell_{02}^2,\quad\text{ and }\quad u_3 \cdot p = \frac12\ell_{03}^2, $$ We can invert these equations using the dual basis for the three vectors $u_1, u_2, u_3$. The end result is following expression of $O$ which only need dot and cross products among vectors $u_k$.
$$O = v_0 + \frac{ \ell_{01}^2 ( u_2 \times u_3 ) + \ell_{02}^2 ( u_3 \times u_1 ) + \ell_{03}^2 ( u_1 \times u_2 )}{ 2 u_1\cdot(u_2 \times u_3)} $$
Notes/References