• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/OpenTissue/OpenTissue/core/geometry/geometry_compute_inscribed_sphere.h

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 // OpenTissue Template Library
00005 // - A generic toolbox for physics-based modeling and simulation.
00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen.
00007 //
00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php
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       //--- The center of the inscreibed sphere is equidistant to each of the face
00058       //--- planes of the tetrahedron, and the distance is the radius of the inscribed
00059       //--- sphere. Let the center and radius of the inscreibed sphere be denoted by c and r.
00060       //---
00061       //---
00062       //--- Let the plane consisting of points j,k, and m be denoted by i then 
00063       //---
00064       //---    n_i * c - w_i = r
00065       //---
00066       //--- where
00067       //---
00068       //---    n_i = \frac{(p_m-p_j)\times(p_k-p_j)}{\norm{(p_m-p_j)\times(p_k-p_j)}}
00069       //---    w_i = n_i \cdot p_j
00070       //---
00071       //--- Similar we can setup three equations for the planes j,k and m (by permuting).
00072       //--- This results in the system of linear equations:
00073       //---
00074       //---   n_{m,x}  c_x + n_{m,y}  c_y + n_{m,z}  c_z - w_m = r
00075       //---   n_{i,x}  c_x + n_{i,y}  c_y + n_{i,z}  c_z - w_i = r
00076       //---   n_{j,x}  c_x + n_{j,y}  c_y + n_{j,z}  c_z - w_j = r
00077       //---   n_{k,x}  c_x + n_{k,y}  c_y + n_{k,z}  c_z - w_k = r
00078       //--- 
00079       //--- Or in as a matrix equation
00080       //---
00081       //--- | n_{m,x}   n_{m,y}   n_{m,z}  -1 | | c_x | = | w_m |
00082       //--- | n_{i,x}   n_{i,y}   n_{i,z}  -1 | | c_y | = | w_i |
00083       //--- | n_{j,x}   n_{j,y}   n_{j,z}  -1 | | c_z | = | w_j |
00084       //--- | n_{k,x}   n_{k,y}   n_{k,z}  -1 | |  r  | = | w_k |
00085       //--- 
00086       //---            A                           x    = b
00087       //---
00088       //--- This is four equations with four unknowns and can be solved by inversion of the A-matrix.
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   } // namespace geometry
00116 } // namespace OpenTissue
00117 
00118 //OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_TETRAHEDRON_INSCRIBED_SPHERE_H
00119 #endif

Generated on Thu Dec 1 2011 12:51:36 for HUMIM Tracker by  doxygen 1.7.1