#include "unproject_on_line.h" #include "projection_constraint.h" template < typename DerivedUV, typename DerivedM, typename DerivedVP, typename Derivedorigin, typename Deriveddir> void igl::unproject_on_line( const Eigen::MatrixBase & UV, const Eigen::MatrixBase & M, const Eigen::MatrixBase & VP, const Eigen::MatrixBase & origin, const Eigen::MatrixBase & dir, typename DerivedUV::Scalar & t) { using namespace Eigen; typedef typename DerivedUV::Scalar Scalar; Matrix A; Matrix B; projection_constraint(UV,M,VP,A,B); // min_z,t ‖Az - B‖² subject to z = origin + t*dir // min_t ‖A(origin + t*dir) - B‖² // min_t ‖A*t*dir + A*origin - B‖² // min_t ‖D*t + C‖² // t = -(D'D)\(D'*C) Matrix C = A*origin.template cast() - B; Matrix D = A*dir.template cast(); // Solve least squares system directly const Matrix t_mat = D.jacobiSvd(ComputeFullU | ComputeFullV).solve(-C); t = t_mat(0,0); } template < typename DerivedUV, typename DerivedM, typename DerivedVP, typename Derivedorigin, typename Deriveddir, typename DerivedZ> void igl::unproject_on_line( const Eigen::MatrixBase & UV, const Eigen::MatrixBase & M, const Eigen::MatrixBase & VP, const Eigen::MatrixBase & origin, const Eigen::MatrixBase & dir, Eigen::PlainObjectBase & Z) { typedef typename DerivedZ::Scalar Scalar; typename DerivedUV::Scalar t; unproject_on_line(UV,M,VP,origin,dir,t); Z = origin + dir*Scalar(t); } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation // generated by autoexplicit.sh template void igl::unproject_on_line, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); // generated by autoexplicit.sh template void igl::unproject_on_line, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); template void igl::unproject_on_line, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::Matrix::Scalar&); #endif