Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_TETRAHEDRON_INSCRIBED_SPHERE_H
00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_TETRAHEDRON_INSCRIBED_SPHERE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_matrix3x3.h>
00013 #include <OpenTissue/core/math/math_invert4x4.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace geometry
00018 {
00019
00046 template<typename vector3_type, typename real_type>
00047 void compute_tetrahedron_inscribed_sphere(
00048 vector3_type const & pi
00049 , vector3_type const & pj
00050 , vector3_type const & pk
00051 , vector3_type const & pm
00052 , vector3_type & center
00053 , real_type & radius
00054 )
00055 {
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 vector3_type nm = unit( (pj-pi)%(pk-pi) );
00091 vector3_type ni = unit( (pm-pj)%(pk-pj) );
00092 vector3_type nj = unit( (pm-pk)%(pi-pk) );
00093 vector3_type nk = unit( (pm-pi)%(pj-pi) );
00094
00095 real_type wm = nm*pi;
00096 real_type wi = ni*pj;
00097 real_type wj = nj*pk;
00098 real_type wk = nk*pi;
00099
00100 real_type M[4][4];
00101
00102 M[0][0] = nm(0); M[0][1] = nm(1); M[0][2] = nm(2); M[0][3] = -1;
00103 M[1][0] = ni(0); M[1][1] = ni(1); M[1][2] = ni(2); M[1][3] = -1;
00104 M[2][0] = nj(0); M[2][1] = nj(1); M[2][2] = nj(2); M[2][3] = -1;
00105 M[3][0] = nk(0); M[3][1] = nk(1); M[3][2] = nk(2); M[3][3] = -1;
00106
00107 math::invert4x4(M);
00108
00109 center(0) = M[0][0]*wm + M[0][1]*wi + M[0][2]*wj + M[0][3]*wk;
00110 center(1) = M[1][0]*wm + M[1][1]*wi + M[1][2]*wj + M[1][3]*wk;
00111 center(2) = M[2][0]*wm + M[2][1]*wi + M[2][2]*wj + M[2][3]*wk;
00112 radius = M[3][0]*wm + M[3][1]*wi + M[3][2]*wj + M[3][3]*wk;
00113 }
00114
00115 }
00116 }
00117
00118
00119 #endif