💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.1 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_PHYSICS_LIGHT_REFRACTION_HPP
  20. #define ANTKEEPER_PHYSICS_LIGHT_REFRACTION_HPP
  21. namespace physics {
  22. namespace light {
  23. /// Index of refraction formulas.
  24. namespace ior {
  25. /**
  26. * Two-term form of Cauchy's transmission equation.
  27. *
  28. * @param lambda Wavelength of light, in micrometers.
  29. * @param a First coefficient of the medium.
  30. * @param b Second coefficient of the medium.
  31. * @return Refractive index.
  32. *
  33. * @see https://en.wikipedia.org/wiki/Cauchy%27s_equation
  34. */
  35. template <class T>
  36. T cauchy(T lambda, T a, T b)
  37. {
  38. return a + b / (lambda * lambda);
  39. }
  40. /**
  41. * Three-term form of Cauchy's transmission equation.
  42. *
  43. * @param lambda Wavelength of light, in micrometers.
  44. * @param a First coefficient.
  45. * @param b Second coefficient.
  46. * @param c Third coefficient.
  47. * @return Refractive index.
  48. *
  49. * @see https://en.wikipedia.org/wiki/Cauchy%27s_equation
  50. */
  51. template <class T>
  52. T cauchy(T lambda, T a, T b, T c)
  53. {
  54. const T lambda2 = lambda * lambda;
  55. return a + b / lambda2 + c / (lambda2 * lambda2);
  56. }
  57. /**
  58. * Two-term form of the Sellmeier equation.
  59. *
  60. * @param lambda Wavelength of light, in micrometers.
  61. * @param b1 B1 coefficient.
  62. * @param c1 C1 coefficient.
  63. * @param b2 B2 coefficient.
  64. * @param c2 C2 coefficient.
  65. * @return Refractive index.
  66. *
  67. * @see https://en.wikipedia.org/wiki/Sellmeier_equation
  68. */
  69. template <class T>
  70. T sellmeier(T lambda, T b1, T c1, T b2, T c2)
  71. {
  72. const T lambda2 = lambda * lambda;
  73. const T t1 = (b1 * lambda2) / (lambda2 - c1);
  74. const T t2 = (b2 * lambda2) / (lambda2 - c2);
  75. return std::sqrt(T(1) + t1 + t2);
  76. }
  77. /**
  78. * Three-term form of the Sellmeier equation.
  79. *
  80. * @param lambda Wavelength of light, in micrometers.
  81. * @param b1 B1 coefficient.
  82. * @param c1 C1 coefficient.
  83. * @param b2 B2 coefficient.
  84. * @param c2 C2 coefficient.
  85. * @param b3 B3 coefficient.
  86. * @param c3 C3 coefficient.
  87. * @return Refractive index.
  88. *
  89. * @see https://en.wikipedia.org/wiki/Sellmeier_equation
  90. */
  91. template <class T>
  92. T sellmeier(T lambda, T b1, T c1, T b2, T c2, T b3, T c3)
  93. {
  94. const T lambda2 = lambda * lambda;
  95. const T t1 = (b1 * lambda2) / (lambda2 - c1);
  96. const T t2 = (b2 * lambda2) / (lambda2 - c2);
  97. const T t3 = (b3 * lambda2) / (lambda2 - c3);
  98. return std::sqrt(T(1) + t1 + t2 + t3);
  99. }
  100. } // namespace ior
  101. } // namespace light
  102. } // namespace physics
  103. #endif // ANTKEEPER_PHYSICS_LIGHT_REFRACTION_HPP