// ===================================================================================================================== // fennec, a free and open source game engine // Copyright © 2025 Medusa Slockbower // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // ===================================================================================================================== /// /// \file trigonometric.h /// \brief the \ref fennec_math_trigonometric /// /// /// \details /// \author Medusa Slockbower /// /// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) /// /// #ifndef FENNEC_MATH_TRIGONOMETRIC_H #define FENNEC_MATH_TRIGONOMETRIC_H /// /// /// /// \page fennec_math_trigonometric Trigonometry /// /// \brief The Trigonometric Functions defined in the [OpenGL 4.6 Shading Language Specification](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.pdf). /// /// \code #include \endcode /// /// /// /// \section section_fennec_conversions Angle Conversions /// /// ///
Syntax /// Description ///

/// \ref fennec::degrees "genFType degrees(genFType x)" ///
/// \copydoc fennec::degrees /// ///

/// \ref fennec::radians "genFType radians(genFType x)" ///
/// \copydoc fennec::radians /// ///
/// /// /// /// \section section_fennec_trigonometric_functions Trigonometric Functions /// /// ///
Syntax /// Description ///

/// \ref fennec::sin "genFType sin(genFType x)" ///
/// \copydoc fennec::sin /// ///

/// \ref fennec::cos "genFType cos(genFType x)" ///
/// \copydoc fennec::cos /// ///

/// \ref fennec::tan "genFType tan(genFType x)" ///
/// \copydoc fennec::tan /// /// ///

/// \ref fennec::asin "genFType asin(genFType x)" ///
/// \copydoc fennec::asin /// ///

/// \ref fennec::acos "genFType acos(genFType x)" ///
/// \copydoc fennec::acos /// ///

/// \ref fennec::atan "genFType atan(genFType x)" ///
/// \copydoc fennec::atan /// ///
/// /// /// /// \section section_fennec_hyperbolic_functions Hyperbolic Functions /// /// ///
Syntax /// Description ///

/// \ref fennec::sinh "genFType sinh(genFType x)" ///
/// \copydoc fennec::sinh /// ///

/// \ref fennec::cosh "genFType cosh(genFType x)" ///
/// \copydoc fennec::cosh /// ///

/// \ref fennec::tanh "genFType tanh(genFType x)" ///
/// \copydoc fennec::tanh /// /// ///

/// \ref fennec::asinh "genFType asinh(genFType x)" ///
/// \copydoc fennec::asinh /// ///

/// \ref fennec::acosh "genFType acosh(genFType x)" ///
/// \copydoc fennec::acosh /// ///

/// \ref fennec::atanh "genFType atanh(genFType x)" ///
/// \copydoc fennec::atanh /// ///
/// /// /// /// /// #include namespace fennec { // Angle Conversions =================================================================================================== /// \name Angle Conversions /// @{ /// /// \brief Converts \f$degrees\f$ to \f$radians\f$, i.e., \f$degrees\cdot\frac{180}{\pi}\f$ /// /// \returns the angle \f$\theta\f$ in \f$radians\f$

/// \details Converts \f$degrees\f$ to \f$radians\f$, i.e., \f$degrees\cdot\frac{180}{\pi}\f$

/// /// \tparam genType floating point type /// \param degrees the angle \f$\theta\f$ in \f$degrees\f$ template constexpr genType radians(genType degrees) { return genType(degrees * 0.01745329251994329576923690768489); } template constexpr vector radians(const vector& degrees) { return vector(degrees * 0.01745329251994329576923690768489); } /// /// \brief Converts \f$radians\f$ to \f$degrees\f$, i.e., \f$radians\cdot\frac{\pi}{180}\f$ /// /// \returns the angle \f$\theta\f$ in \f$degrees\f$

/// \details Converts \f$radians\f$ to \f$degrees\f$, i.e., \f$radians\cdot\frac{\pi}{180}\f$

/// /// \tparam genType floating point type /// \param radians the angle \f$\theta\f$ in \f$radians\f$ template constexpr genType degrees(genType radians) { return genType(radians * 57.29577951308232087679815481410517); } template constexpr vector degrees(const vector& radians) { return genType(radians * 57.29577951308232087679815481410517); } /// @} // Trigonometric ====================================================================================================== /// \name Trigonometric Functions /// @{ /// /// \brief The standard trigonometric sine /// /// \returns the sine of \f$\theta\f$ in the range \f$\left[-1,\,1\right]\f$

/// \details The standard trigonometric sine

/// /// \tparam genType floating point type /// \param x the angle \f$\theta\f$ in \f$radians\f$ template constexpr genType sin(genType x) { return ::sin(x); } template constexpr vector sin(const vector& x) { return vector(fennec::sin(x[i]) ...); } /// /// \brief The Standard Trigonometric Cosine /// /// \returns the cosine of \f$\theta\f$ in the range \f$\left[-1,\,1\right]\f$

/// \details The Standard Trigonometric Cosine

/// /// \tparam genType floating point type /// \param x the angle \f$\theta\f$ in \f$radians\f$ template constexpr genType cos(genType x) { return ::cos(x); } template constexpr vector cos(const vector& x) { return vector(fennec::cos(x[i]) ...); } /// /// \brief The Standard Trigonometric Tangent /// /// \returns The Tangent of \f$\theta\f$ in the Range \f$\left[-\inf,\,\inf\right]\f$

/// \details The Standard Trigonometric Tangent

/// /// \tparam genType floating point type /// \param x The Angle \f$\theta\f$ in \f$radians\f$ template constexpr genType tan(genType x) { return ::tan(x); } template constexpr vector tan(const vector& x) { return vector(fennec::tan(x[i]) ...); } /// @} /// \name Inverse Trigonometric Functions /// @{ /// /// \brief Arc Sine. Returns an angle \f$\theta\f$ whose sine is /a x. /// /// \returns an angle \f$\theta\f$ whose sine is /a x.

/// \details Arc Sine. The range of values returned by this functions is /// \f$\left[-\pi/2,\pi/2\right]\f$. Results are undefined if \f$\left|x\right|\,>\,1\f$.

/// /// \tparam genType floating point type /// \param x The Sine Value produced by \f$\theta\f$ template constexpr genType asin(genType x) { return ::asin(x); } template constexpr vector asin(const vector& x) { return vector(fennec::asin(x[i]) ...); } /// /// \brief Arc Cosine. Returns an angle \f$\theta\f$ whose cosine is /a x. /// /// \returns an angle \f$\theta\f$ whose cosine is /a x. /// \details Arc Cosine. The range of values returned by this functions is /// \f$\left[0,\pi\right]\f$. Results are undefined if \f$\left|x\right|\,>\,1\f$. /// /// \tparam genType floating point type /// \param x The Cosine Value produced by \f$\theta\f$ template constexpr genType acos(genType x) { return ::acos(x); } template constexpr vector acos(const vector& x) { return vector(fennec::acos(x[i]) ...); } /// /// \brief Arc Tangent. Returns an angle \f$\theta\f$ whose tangent is /a y_over_x. /// /// \returns an angle \f$\theta\f$ whose tangent is /a y_over_x. /// \details Arc Tangent. The range of values returned by this functions is /// \f$\left[\frac{-\pi}{2},\frac{\pi}{2}\right]\f$. Results are undefined if \f$\left|x\right|\,>\,1\f$. /// /// \tparam genType floating point type /// \param y_over_x The Cosine Value produced by \f$\theta\f$ template constexpr genType atan(genType y_over_x) { return ::atan(y_over_x); } template constexpr vector atan(const vector& y_over_x) { return vector(fennec::atan(y_over_x[i]) ...); } /// /// \brief Arc Tangent. Returns an angle whose tangent is \f$\frac{y}{x}\f$. /// /// \returns an angle whose tangent is \f$\frac{y}{x}\f$.

/// \details Arc Tangent. The signs of \a x and \a y are used to determine what quadrant the angle is in. /// The range of values returned by this functions is \f$\left[-\pi,\pi\right]\f$

/// /// \tparam genType floating point type /// \param y The Sine Value produced by \f$\theta\f$ /// \param x The Cosine Value produced by \f$\theta\f$ template constexpr genType atan(genType y, genType x) { return ::atan2(y, x); } template constexpr vector atan(const vector& y, const vector& x) { return vector(fennec::atan(y[i], x[i]) ...); } /// @} // Hyperbolic Functions ================================================================================================ /// \name Hyperbolic Functions /// @{ /// /// \brief Returns the Hyperbolic Sine Function, \f$\frac{{e}^{x}-{e}^{-x}}{2}\f$ /// /// \returns The Hyperbolic Sine of \f$x\f$, \f$\frac{{e}^{x}-{e}^{-x}}{2}\f$

/// /// \tparam genType floating point type /// \param x The Hyperbolic Angle \f$\alpha\f$ template constexpr genType sinh(genType x) { return ::sinh(x); } template constexpr vector sinh(const vector& x) { return vector(fennec::sinh(x[i]) ...); } /// /// \brief Returns the Hyperbolic Cosine Function, \f$\frac{{e}^{x}+{e}^{-x}}{2}\f$ /// /// \returns The Hyperbolic Cosine of \f$x\f$, \f$\frac{{e}^{x}+{e}^{-x}}{2}\f$

/// /// \param x The Hyperbolic Angle \f$\alpha\f$ template constexpr genType cosh(genType x) { return ::cosh(x); } template constexpr vector cosh(const vector& x) { return vector(fennec::cosh(x[i]) ...); } /// /// \brief Returns the Hyperbolic Tangent Function, \f$\frac{\text{sinh}(x)}{\text{cosh}(x)}\f$ /// /// \returns The Hyperbolic Tangent of \f$x\f$, \f$\frac{{e}^{x}+{e}^{-x}}{2}\f$

/// /// \param x The Hyperbolic Angle \f$\alpha\f$ template constexpr genType tanh(genType x) { return ::tanh(x); } template constexpr vector tanh(const vector& x) { return vector(fennec::tanh(x[i]) ...); } /// @} /// \name Inverse Hyperbolic Functions /// @{ /// /// \brief The Inverse Hyperbolic Sine Function /// /// \returns the value \f$y\f$ that fulfills \f$x=\text{sinh}(y)\f$

/// \details The Inverse Hyperbolic Sine Function

/// /// \param x the hyperbolic angle \f$\alpha\f$ template constexpr genType asinh(genType x) { return ::asinh(x); } template constexpr vector asinh(const vector& x) { return vector(fennec::asinh(x[i]) ...); } /// /// \brief The Inverse Hyperbolic Cosine Function /// /// \returns the value \f$y\f$ that fulfills \f$x=\text{cosh}(y)\f$

/// \details The Inverse Hyperbolic Cosine Function

/// /// \param x the hyperbolic angle \f$\alpha\f$ template constexpr genType acosh(genType x) { return ::acosh(x); } template constexpr vector acosh(const vector& x) { return vector(fennec::acosh(x[i]) ...); } /// /// \brief The Inverse Hyperbolic Tangent Function /// /// \returns the value \f$y\f$ that fulfills \f$x=\text{atanh}(y)\f$

/// \details The Inverse Hyperbolic Tangent Function

/// /// \param x The Hyperbolic Angle \f$\alpha\f$ template constexpr genType atanh(genType x) { return ::atanh(x); } template constexpr vector atanh(const vector& x) { return vector(fennec::atanh(x[i]) ...); } /// @} } #endif // FENNEC_MATH_TRIGONOMETRIC_H