I want to find the circumcenter of a triangle. Wolfram only shows how to find the circumcircle of a triangle in R2. How can I find the circumcenter of a triangle in R3?
Answer
The circumcenter of a triangle can be found by the following formula, which I mined from an old posting by Jonathan Shewchuk from the Geometry Junkyard
$$\begin{align} &\text{Triangle in } \Bbb R^3\text{:}\\ &m = a + \frac {\lVert c-a\rVert^2 \left[(b-a) \times (c - a) \right] \times (b-a) + \lVert b-a\rVert^2 \left[(c-a) \times (b - a) \right] \times (c-a)} {2 \lVert (b - a) \times (c - a) \rVert^2} \end{align}$$
Where \$m\$ is the circumcenter of the triangle.
Some C++ code, given Vector3f's with overloaded +, -,
Vector3f a,b,c // are the 3 pts of the tri
Vector3f ac = c - a ;
Vector3f ab = b - a ;
Vector3f abXac = ab.cross( ac ) ;
// this is the vector from a TO the circumsphere center
Vector3f toCircumsphereCenter = (abXac.cross( ab )*ac.len2() + ac.cross( abXac )*ab.len2()) / (2.f*abXac.len2()) ;
float circumsphereRadius = toCircumsphereCenter.len() ;
// The 3 space coords of the circumsphere center then:
Vector3f ccs = a + toCircumsphereCenter ; // now this is the actual 3space location
Here is a picture of a triangle and its circumsphere
No comments:
Post a Comment