Coord ParamDistortion::ComputeBarycentric(const vector<ParamCoord>& tri_vtx_array, ParamCoord vtx_param_coord) { zjucad::matrix::matrix<double> coord_matrix(3, 3); for(size_t c=0; c<3; ++c) { coord_matrix(0, c) = tri_vtx_array[c].s_coord; coord_matrix(1, c) = tri_vtx_array[c].t_coord; coord_matrix(2, c) = 1.0; } inv(coord_matrix); zjucad::matrix::matrix<double> right_matrix(3, 1); right_matrix(0, 0) = vtx_param_coord.s_coord; right_matrix(1, 0) = vtx_param_coord.t_coord; right_matrix(2, 0) = 1.0; zjucad::matrix::matrix<double> result_matrix = coord_matrix*right_matrix; return Coord(result_matrix(0, 0), result_matrix(1, 0), result_matrix(2, 0)); }
Mat3d ReducedStVKCubatureForceModel::computeF_gradient(const int &ele,const int &vert_idx,const int &vert_idx_dim) const { //vert_idx denotes the j-th vertex, vert_idx_dim is the k-th coordinate of the j-th vertex //we get the result as dF_i/dx_j^k, which is the derivative force of vertex i to the vertex j on the coordinate k //identity vector definition if((vert_idx>4)||(vert_idx_dim>3)) { std::cout<<"the vert_idx or the vert_idx_dim is out of range, they should be smaller than 3"; } Mat3d result_matrix(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0); std::vector<Vec3d> e_vector; e_vector.resize(3,Vec3d(0.0,0.0,0.0)); e_vector[0][0]=1.0; e_vector[1][1]=1.0; e_vector[2][2]=1.0; Mat3d e_matrix(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0); Mat3d DmInv=computeDmInv(ele); //Mat3d DmInv(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0); //for j=1,2,3 we have dF/dx_j^k=e_k*e_j^T*Dm^-1 for(unsigned int row_idx=0;row_idx<3;++row_idx) { for(unsigned int col_idx=0;col_idx<3;++col_idx) { e_matrix[row_idx][col_idx]=e_vector[vert_idx_dim][row_idx]*e_vector[vert_idx][col_idx]; } } //compute dF/dx_4 if(vert_idx==3) { Mat3d vert_cord_matrix(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0); if(vert_idx_dim==0) { vert_cord_matrix[0][0]=vert_cord_matrix[0][1]=vert_cord_matrix[0][2]=-1.0; } else if(vert_idx_dim==1) { vert_cord_matrix[1][0]=vert_cord_matrix[1][1]=vert_cord_matrix[1][2]=-1.0; } else if(vert_idx_dim==2) { vert_cord_matrix[2][0]=vert_cord_matrix[2][1]=vert_cord_matrix[2][2]=-1.0; } else { } result_matrix=vert_cord_matrix*DmInv; } else { //compute dF/dx_j^k,j=1,2,3;k=1,2,3 result_matrix=e_matrix*DmInv; } return result_matrix; }
MatrixMxN<Scalar> MatrixMxN<Scalar>::transpose() const { unsigned int rows = (*this).rows(); unsigned int cols = (*this).cols(); Scalar *result = new Scalar[rows*cols]; for(unsigned int i = 0; i < rows; ++i) for(unsigned int j = 0; j < cols; ++j) result[j*rows+i] = (*this)(i,j); MatrixMxN<Scalar> result_matrix(cols,rows,result); delete result; return result_matrix; }
MatrixMxN<Scalar> MatrixMxN<Scalar>::operator* (Scalar scale) const { unsigned int rows = (*this).rows(); unsigned int cols = (*this).cols(); Scalar *result = new Scalar[rows*cols]; for(unsigned int i = 0; i < rows; ++i) for(unsigned int j = 0; j < cols; ++j) result[i*cols+j] = (*this)(i,j) * scale; MatrixMxN<Scalar> result_matrix(rows,cols,result); delete result; return result_matrix; }
MatrixMxN<Scalar> MatrixMxN<Scalar>::operator/ (Scalar scale) const { if(abs(scale)<std::numeric_limits<Scalar>::epsilon()) { std::cerr<<"Matrix Divide by zero error!\n"; std::exit(EXIT_FAILURE); } unsigned int rows = (*this).rows(); unsigned int cols = (*this).cols(); Scalar *result = new Scalar[rows*cols]; for(unsigned int i = 0; i < rows; ++i) for(unsigned int j = 0; j < cols; ++j) result[i*cols+j] = (*this)(i,j) / scale; MatrixMxN<Scalar> result_matrix(rows,cols,result); delete result; return result_matrix; }
MatrixMxN<Scalar> MatrixMxN<Scalar>::operator- (const MatrixMxN<Scalar> &mat2) const { unsigned int rows = (*this).rows(); unsigned int cols = (*this).cols(); unsigned int rows2 = mat2.rows(); unsigned int cols2 = mat2.cols(); bool size_match = (rows==rows2)&&(cols==cols2); if(!size_match) { std::cerr<<"Cannot subtract two matrix of different sizes!\n"; std::exit(EXIT_FAILURE); } Scalar *result = new Scalar[rows*cols]; for(unsigned int i = 0; i < rows; ++i) for(unsigned int j = 0; j < cols; ++j) result[i*cols+j] = (*this)(i,j) - mat2(i,j); MatrixMxN<Scalar> result_matrix(rows, cols, result); delete result; return result_matrix; }