Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rigid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod float {
// = R' * T' * T2
// = R' * T''
//
// (R2^-1 * T2 * R2^) = T' = T2 rotated by R2
// (R2^-1 * T1 * R2) = T' = T2 rotated by R2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My approval of this change is a rubber stamp. The rest actually makes sense to me.

// R1 * R2 = R'
// T' * T2 = T'' = vector addition of translations T2 and T'

Expand Down
13 changes: 10 additions & 3 deletions src/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ where
T: Copy,
{
/// Returns the vector part (i, j, k) of this quaternion.
///
/// The vector part represents the axis of the rotation.
#[inline]
pub fn vector_part(&self) -> Vector3D<T, UnknownUnit> {
vec3(self.i, self.j, self.k)
Expand Down Expand Up @@ -807,9 +809,14 @@ mod rotation3d_float {
#[inline]
/// Returns the angle of rotation about the stored axis.
pub fn get_angle(&self) -> Angle<T> {
let two = T::one() + T::one();
let angle = two * self.r.acos();
return Angle::radians(angle);
let one = T::one();
let two = one + one;
// Clamp r to acos's safe range [-1, 1] to avoid NaNs if float precision
// causes the value to be slightly out of range.
let r = self.r.max(-one).min(one);
let angle = two * r.acos();

Angle::radians(angle)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/transform3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use serde::{Deserialize, Serialize};
/// ```text
/// |x'| | m11 m12 m13 m14 | |x|
/// |y'| | m21 m22 m23 m24 | |y|
/// |z'| = | m31 m32 m33 m34 | x |y|
/// |z'| = | m31 m32 m33 m34 | x |z|
/// |w | | m41 m42 m43 m44 | |1|
/// ```
///
Expand Down
Loading