MCPcopy Create free account
hub / github.com/Kitware/VTK / Circumcircle

Method Circumcircle

Common/DataModel/vtkTriangle.cxx:805–865  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Compute the circumcenter (center[3]) and radius squared (method return value) of a triangle defined by the three points x1, x2, and x3. (Note that the coordinates are 2D. 3D points can be used but the z-component will be ignored.)

Source from the content-addressed store, hash-verified

803// x3. (Note that the coordinates are 2D. 3D points can be used but
804// the z-component will be ignored.)
805double vtkTriangle::Circumcircle(
806 const double x1[2], const double x2[2], const double x3[2], double center[2])
807{
808 double n12[2], n13[2], x12[2], x13[2];
809 double *A[2], rhs[2], diff;
810
811 // calculate normals and intersection points of bisecting planes.
812 //
813 for (int i = 0; i < 2; i++)
814 {
815 n12[i] = x2[i] - x1[i];
816 n13[i] = x3[i] - x1[i];
817 x12[i] = (x2[i] + x1[i]) / 2.0;
818 x13[i] = (x3[i] + x1[i]) / 2.0;
819 }
820
821 // Compute solutions to the intersection of two bisecting lines
822 // (2-eqns. in 2-unknowns).
823 //
824 // form system matrices
825 //
826 A[0] = n12;
827 A[1] = n13;
828
829 rhs[0] = vtkMath::Dot2D(n12, x12);
830 rhs[1] = vtkMath::Dot2D(n13, x13);
831
832 // Solve system of equations
833 //
834 if (vtkMath::SolveLinearSystem(A, rhs, 2) == 0)
835 {
836 center[0] = center[1] = 0.0;
837 return VTK_DOUBLE_MAX;
838 }
839 else
840 {
841 center[0] = rhs[0];
842 center[1] = rhs[1];
843 }
844
845 // determine average value of radius squared
846 double sum = 0.0;
847 for (int i = 0; i < 2; i++)
848 {
849 diff = x1[i] - center[i];
850 sum += diff * diff;
851 diff = x2[i] - center[i];
852 sum += diff * diff;
853 diff = x3[i] - center[i];
854 sum += diff * diff;
855 }
856
857 if ((sum /= 3.0) > VTK_DOUBLE_MAX)
858 {
859 return VTK_DOUBLE_MAX;
860 }
861 else
862 {

Callers

nothing calls this directly

Calls 2

Dot2DFunction · 0.85
SolveLinearSystemFunction · 0.85

Tested by

no test coverage detected