// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2025 Alec Jacobson // // 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 "round_cone_signed_distance.h" #include "sign.h" template < typename Derivedp, typename Deriveda, typename Derivedb> IGL_INLINE typename Derivedp::Scalar igl::round_cone_signed_distance( const Eigen::MatrixBase & p, const Eigen::MatrixBase & a, const Eigen::MatrixBase & b, const typename Derivedp::Scalar & r1, const typename Derivedp::Scalar & r2) { // https://iquilezles.org/articles/distfunctions/ using Scalar = typename Derivedp::Scalar; using RowVector3S = Eigen::Matrix; // sampling independent computations (only depend on shape) const RowVector3S ba = b - a; const Scalar l2 = ba.dot(ba); const Scalar rr = r1 - r2; const Scalar a2 = l2 - rr*rr; const Scalar il2 = 1.0/l2; return round_cone_signed_distance(p,a,r1,r2,ba,l2,rr,a2,il2); } template < typename Derivedp, typename Deriveda, typename Derivedba> IGL_INLINE typename Derivedp::Scalar igl::round_cone_signed_distance( const Eigen::MatrixBase & p, const Eigen::MatrixBase & a, const typename Derivedp::Scalar & r1, const typename Derivedp::Scalar & r2, const Eigen::MatrixBase & ba, const typename Derivedp::Scalar & l2, const typename Derivedp::Scalar & rr, const typename Derivedp::Scalar & a2, const typename Derivedp::Scalar & il2) { using Scalar = typename Derivedp::Scalar; using RowVector3S = Eigen::Matrix; // sampling dependant computations const RowVector3S pa = p - a; const Scalar y = pa.dot(ba); const Scalar z = y - l2; const Scalar x2 = ( pa*l2 - ba*y ).squaredNorm(); const Scalar y2 = y*y*l2; const Scalar z2 = z*z*l2; // single square root! const Scalar k = sign(rr)*rr*rr*x2; if( sign(z)*a2*z2>k ) return sqrt(x2 + z2) *il2 - r2; if( sign(y)*a2*y2, 1, 3, true>::Scalar igl::round_cone_signed_distance, 1, 3, true>, Eigen::Block, 1, 3, true>, Eigen::Block, 1, 3, true>>(Eigen::MatrixBase, 1, 3, true>> const&, Eigen::MatrixBase, 1, 3, true>> const&, Eigen::MatrixBase, 1, 3, true>> const&, Eigen::Block, 1, 3, true>::Scalar const&, Eigen::Block, 1, 3, true>::Scalar const&); template Eigen::Matrix::Scalar igl::round_cone_signed_distance, Eigen::Block const, 1, 3, true>, Eigen::Block const, 1, 3, true>>(Eigen::MatrixBase> const&, Eigen::MatrixBase const, 1, 3, true>> const&, Eigen::Matrix::Scalar const&, Eigen::Matrix::Scalar const&, Eigen::MatrixBase const, 1, 3, true>> const&, Eigen::Matrix::Scalar const&, Eigen::Matrix::Scalar const&, Eigen::Matrix::Scalar const&, Eigen::Matrix::Scalar const&); #endif