coordinates.cpp

00001 #include <geometry/coordinates.h>
00002 #include <cmath>
00003 
00004 
00005 namespace geometry
00006 {
00007   using std::max;
00008   using std::abs;
00009 
00010   Point3d cartesianToBarycentric(const Point3d& pos,
00011                                  const Point3d& p1, const Point3d& p2, const Point3d& p3)
00012   {
00013     Point3d p = pos;
00014     int index_one;
00015     const Matrix3d& face_mat = cartesianToBarycentric_matrix(p1, p2, p3, index_one);
00016     p[index_one] = 1;
00017     return face_mat*p;
00018   }
00019 
00020   Matrix3d cartesianToBarycentric_matrix(const Point3d& p1, const Point3d& p2, const Point3d& p3,
00021                                          int& index_one)
00022   {
00023     Point3d prep_mat[3] = {p1,p2,p3};
00024     Matrix3d face_mat(prep_mat);
00025     face_mat = util::transpose(face_mat);
00026     Point3d d12 = p2-p1;
00027     Point3d d13 = p3-p1;
00028     //Point3d d23 = p3-p2;
00029     Point3d n = d12 ^ d13;
00030     double dx = abs(n.x());
00031     double dy = abs(n.y());
00032     double dz = abs(n.z());
00033     if(dx > dy and dx > dz)
00034     {
00035       face_mat(0,0) = 1;
00036       face_mat(0,1) = 1;
00037       face_mat(0,2) = 1;
00038       index_one = 0;
00039     }
00040     else if(dy > dz)
00041     {
00042       face_mat(1,0) = 1;
00043       face_mat(1,1) = 1;
00044       face_mat(1,2) = 1;
00045       index_one = 1;
00046     }
00047     else
00048     {
00049       face_mat(2,0) = 1;
00050       face_mat(2,1) = 1;
00051       face_mat(2,2) = 1;
00052       index_one = 2;
00053     }
00054     face_mat = util::inverse(face_mat);
00055     return face_mat;
00056   }
00057 
00058   Point3d barycentricToCartesian(const Point3d& barycentric,
00059                                  const Point3d& p1, const Point3d& p2, const Point3d& p3)
00060   {
00061 //    const Matrix3d& face_mat = barycentricToCartesian_matrix(p1, p2, p3);
00062 //    return face_mat*barycentric;
00063     return barycentric.x()*p1 + barycentric.y()*p2 + barycentric.z()*p3;
00064   }
00065 
00066   Matrix3d barycentricToCartesian_matrix(const Point3d& p1, const Point3d& p2, const Point3d& p3)
00067   {
00068     Point3d prep_mat[3] = {p1,p2,p3};
00069     Matrix3d face_mat(prep_mat);
00070     face_mat = util::transpose(face_mat);
00071     return face_mat;
00072   }
00073 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:37:50 2013 for VVE by  doxygen 1.6.3