// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2014 Daniele Panozzo , Olga Diamanti // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #include "rotation_matrix_from_directions.h" #include #include template IGL_INLINE Eigen::Matrix igl::rotation_matrix_from_directions( const Eigen::Matrix v0, const Eigen::Matrix v1) { Eigen::Matrix rotM; const double epsilon=1e-8; Scalar dot=v0.normalized().dot(v1.normalized()); ///control if there is no rotation if ((v0-v1).norm()::Identity(); return rotM; } if ((v0+v1).norm()::Identity(); rotM(0,0) = 1.; std::cerr<<"igl::rotation_matrix_from_directions: rotating around x axis by 180o"< axis; axis=v0.cross(v1); axis.normalize(); ///construct rotation matrix Scalar u=axis(0); Scalar v=axis(1); Scalar w=axis(2); Scalar phi=acos(dot); Scalar rcos = cos(phi); Scalar rsin = sin(phi); rotM(0,0) = rcos + u*u*(1-rcos); rotM(1,0) = w * rsin + v*u*(1-rcos); rotM(2,0) = -v * rsin + w*u*(1-rcos); rotM(0,1) = -w * rsin + u*v*(1-rcos); rotM(1,1) = rcos + v*v*(1-rcos); rotM(2,1) = u * rsin + w*v*(1-rcos); rotM(0,2) = v * rsin + u*w*(1-rcos); rotM(1,2) = -u * rsin + v*w*(1-rcos); rotM(2,2) = rcos + w*w*(1-rcos); return rotM; } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation template Eigen::Matrix igl::rotation_matrix_from_directions(const Eigen::Matrix, const Eigen::Matrix); #endif