Skip to content

Commit

Permalink
Avoid matrix multiplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3vu0r committed Oct 11, 2024
1 parent 2aefae8 commit 0643c7f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/base/cg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,14 @@ where
SC: Storage<T, D> + Clone,
{
let (a, b, ab) = (from.as_ref(), to.as_ref(), from.dot(to));
let d = T::one() + ab;
let d = T::one() + ab.clone();
(d > T::default_epsilon().sqrt()).then(|| {
let k = &(b * a.transpose() - a * b.transpose());
let [at, bt] = &[a.transpose(), b.transpose()];
let [b_at, a_bt, a_at, b_bt] = &[b * at, a * bt, a * at, b * bt];
let [k1, k2] = [b_at - a_bt, (b_at + a_bt) * ab - (a_at + b_bt)];
// Codesido's Rotation Formula
// <https://doi.org/10.14232/ejqtde.2018.1.13>
//
// Equals `Self::identity() + k + k * k / d`:
let mut r = Self::identity() + k;
r.gemm(d.recip(), k, k, T::one());
r
Self::identity() + k1 + k2 / d
})
}
/// The n-dimensional rotation matrix described by an oriented minor arc and a signed angle.
Expand All @@ -120,7 +118,7 @@ where
.try_normalize(T::default_epsilon().sqrt())
.map(|ref b| {
let (sin, cos) = angle.sin_cos();
let [at, bt] = [&a.transpose(), &b.transpose()];
let [at, bt] = &[a.transpose(), b.transpose()];
let [k1, k2] = [b * at - a * bt, -(a * at + b * bt)];
// Simple rotations / Rotation in a two–plane
// <https://doi.org/10.48550/arXiv.1103.5263>
Expand Down

0 comments on commit 0643c7f

Please sign in to comment.