nalgebra/nalgebra-glm/src/trigonometric.rs

95 lines
2.8 KiB
Rust
Raw Normal View History

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