Home > Mathematica, Mathematics > Triangles, Circles and Spheres

## Triangles, Circles and Spheres

The ‘real world` has provided precious few opportunities for musings. The following is motivated by a question on Mathematica Stackexchange.

The following code aims to find the circumcentre of a triangle defined by 3 points in $R^3$.
``` cc[{p_, q_, r_}] := Module[ {v1, v2, b1, b2, norm, n1, n2, cntr, rad, un}, v1 = Normalize@(q - p); v2 = Normalize@(r - p); b1 = (p + q)/2; b2 = (r + p)/2; norm = Cross[v1, v2]; n1 = Normalize@Cross[norm, v1]; n2 = Normalize@Cross[norm, v2]; cntr = b1 + s n1 /. First@Solve[b1 + s n1 == b2 + t n2, {s, t}]; rad = Norm[p - cntr]; un = Normalize@Cross[norm, v1]; {cntr, rad, v1, un} ]```

``` ```

```plcc[{p_, q_, r_}] := Module[{ctr, radius, un1, un2, p1, p2}, {ctr, radius, un1, un2} = cc[{p, q, r}]; p1 = Graphics3D[{{Black, PointSize[Large], Point@{p, q, r}}, {Polygon[{p, q, r}]}, {Red, PointSize[Large], Point@ctr}, {Opacity[0.3], Sphere[ctr, radius]}}]; p2 = ParametricPlot3D[ ctr + radius Cos[t] un1 + radius Sin[t] un2, {t, 0, 2 Pi}]; Show[p1, p2, Axes -> True]] ```

Testing on 100 random triples:

Peace to all…