nalgebra/nalgebra-glm/src/trigonometric.rs

79 lines
2.3 KiB
Rust
Raw Normal View History

2021-04-11 17:00:38 +08:00
use na::{self, RealField};
2019-03-23 21:29:07 +08:00
use crate::aliases::TVec;
2018-09-22 19:21:02 +08:00
/// Component-wise arc-cosinus.
2021-04-11 17:00:38 +08:00
pub fn acos<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|e| e.acos())
}
2018-09-22 19:21:02 +08:00
/// Component-wise hyperbolic arc-cosinus.
2021-04-11 17:00:38 +08:00
pub fn acosh<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|e| e.acosh())
}
2018-09-22 19:21:02 +08:00
/// Component-wise arc-sinus.
2021-04-11 17:00:38 +08:00
pub fn asin<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|e| e.asin())
}
2018-09-22 19:21:02 +08:00
/// Component-wise hyperbolic arc-sinus.
2021-04-11 17:00:38 +08:00
pub fn asinh<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|e| e.asinh())
}
2018-09-22 19:21:02 +08:00
/// Component-wise arc-tangent of `y / x`.
2021-04-11 17:00:38 +08:00
pub fn atan2<T: RealField, const D: usize>(y: &TVec<T, D>, x: &TVec<T, D>) -> TVec<T, D> {
y.zip_map(x, |y, x| y.atan2(x))
}
2018-09-22 19:21:02 +08:00
/// Component-wise arc-tangent.
2021-04-11 17:00:38 +08:00
pub fn atan<T: RealField, const D: usize>(y_over_x: &TVec<T, D>) -> TVec<T, D> {
y_over_x.map(|e| e.atan())
}
2018-09-22 19:21:02 +08:00
/// Component-wise hyperbolic arc-tangent.
2021-04-11 17:00:38 +08:00
pub fn atanh<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|e| e.atanh())
}
2018-09-22 19:21:02 +08:00
/// Component-wise cosinus.
2021-04-11 17:00:38 +08:00
pub fn cos<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.cos())
}
2018-09-22 19:21:02 +08:00
/// Component-wise hyperbolic cosinus.
2021-04-11 17:00:38 +08:00
pub fn cosh<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.cosh())
}
2018-09-22 19:21:02 +08:00
/// Component-wise conversion from radians to degrees.
2021-04-11 17:00:38 +08:00
pub fn degrees<T: RealField, const D: usize>(radians: &TVec<T, D>) -> TVec<T, D> {
radians.map(|e| e * na::convert(180.0) / T::pi())
}
2018-09-22 19:21:02 +08:00
/// Component-wise conversion fro degrees to radians.
2021-04-11 17:00:38 +08:00
pub fn radians<T: RealField, const D: usize>(degrees: &TVec<T, D>) -> TVec<T, D> {
degrees.map(|e| e * T::pi() / na::convert(180.0))
}
2018-09-22 19:21:02 +08:00
/// Component-wise sinus.
2021-04-11 17:00:38 +08:00
pub fn sin<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.sin())
}
2018-09-22 19:21:02 +08:00
/// Component-wise hyperbolic sinus.
2021-04-11 17:00:38 +08:00
pub fn sinh<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.sinh())
}
2018-09-22 19:21:02 +08:00
/// Component-wise tangent.
2021-04-11 17:00:38 +08:00
pub fn tan<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.tan())
}
2018-09-22 19:21:02 +08:00
/// Component-wise hyperbolic tangent.
2021-04-11 17:00:38 +08:00
pub fn tanh<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.tanh())
}