tan_half_angle.cpp 930 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2018 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "tan_half_angle.h"
  9. #include <cmath>
  10. template < typename Scalar>
  11. IGL_INLINE Scalar igl::tan_half_angle(
  12. const Scalar & a,
  13. const Scalar & b,
  14. const Scalar & c)
  15. {
  16. // .
  17. // /|
  18. // c/ |
  19. // / |
  20. // / |
  21. // .α | a
  22. // \ |
  23. // \ |
  24. // b\ |
  25. // \|
  26. //
  27. // tan(α/2)
  28. // Fisher 2007
  29. return sqrt(((a-b+c)*(a+b-c))/((a+b+c)*(-a+b+c)));
  30. }
  31. #ifdef IGL_STATIC_LIBRARY
  32. // Explicit template instantiation
  33. // generated by autoexplicit.sh
  34. template double igl::tan_half_angle<double>(double const&, double const&, double const&);
  35. #endif