-
-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transcendentals2 #554
Transcendentals2 #554
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,6 +21,27 @@ use base::{Matrix3, MatrixN, MatrixSlice, MatrixSliceMut, Unit, Vector3, Vector4 | |||||
|
||||||
use geometry::Rotation; | ||||||
|
||||||
/// Calculates the cardinal sine function | ||||||
#[inline] | ||||||
fn sinc<N: Real>(v: N) -> N { | ||||||
if v == N::zero() { | ||||||
N::zero() | ||||||
} | ||||||
else { | ||||||
v.sin() / v | ||||||
} | ||||||
} | ||||||
|
||||||
#[inline] | ||||||
fn sinhc<N: Real>(v: N) -> N { | ||||||
if v == N::zero() { | ||||||
N::zero() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
else { | ||||||
v.sinh() / v | ||||||
} | ||||||
} | ||||||
|
||||||
/// A quaternion. See the type alias `UnitQuaternion = Unit<Quaternion>` for a quaternion | ||||||
/// that may be used as a rotation. | ||||||
#[repr(C)] | ||||||
|
@@ -124,6 +145,12 @@ impl<N: Real> Quaternion<N> { | |||||
Self::from(self.coords.normalize()) | ||||||
} | ||||||
|
||||||
/// The imaginary part of this quaternion. | ||||||
#[inline] | ||||||
pub fn imag(&self) -> Vector3<N> { | ||||||
self.coords.xyz() | ||||||
} | ||||||
|
||||||
/// The conjugate of this quaternion. | ||||||
/// | ||||||
/// # Example | ||||||
|
@@ -135,13 +162,7 @@ impl<N: Real> Quaternion<N> { | |||||
/// ``` | ||||||
#[inline] | ||||||
pub fn conjugate(&self) -> Self { | ||||||
let v = Vector4::new( | ||||||
-self.coords[0], | ||||||
-self.coords[1], | ||||||
-self.coords[2], | ||||||
self.coords[3], | ||||||
); | ||||||
Self::from(v) | ||||||
Self::from_parts(self.w, -self.imag()) | ||||||
} | ||||||
|
||||||
/// Inverts this quaternion if it is not zero. | ||||||
|
@@ -506,6 +527,22 @@ impl<N: Real> Quaternion<N> { | |||||
pub fn normalize_mut(&mut self) -> N { | ||||||
self.coords.normalize_mut() | ||||||
} | ||||||
|
||||||
/// Calculates quaternionic sin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
#[inline] | ||||||
pub fn cos(&self) -> Self { | ||||||
let z = self.imag().magnitude(); | ||||||
let w = -self.w.sin() * sinhc(z); | ||||||
Self::from_parts(self.w.cos() * z.cosh(), self.imag() * w) | ||||||
} | ||||||
|
||||||
/// Calculates quaternionic sin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think "sine" and "cosine" are the most common spellings of these in English. |
||||||
#[inline] | ||||||
pub fn sin(&self) -> Self { | ||||||
let z = self.imag().magnitude(); | ||||||
let w = self.w.cos() * sinhc(z); | ||||||
Self::from_parts(self.w.sin() * z.cosh(), self.imag() * w) | ||||||
} | ||||||
} | ||||||
|
||||||
impl<N: Real + AbsDiffEq<Epsilon = N>> AbsDiffEq for Quaternion<N> { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.