aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2023-12-10 22:08:07 +0100
committerGitHub <noreply@github.com>2023-12-10 22:08:07 +0100
commit9ac3503b879f95fcdf5414470ba5aedf195b9a97 (patch)
tree5551e86f366f53bfaa24a266f082ff332d74e52b /src/utils.rs
parentc33b4eeb5c113b8f8509cd866c4ab48e5d6c5eaa (diff)
parent2fba50c297987dac6971452d877c1609cee43a98 (diff)
downloadrapier-9ac3503b879f95fcdf5414470ba5aedf195b9a97.tar.gz
rapier-9ac3503b879f95fcdf5414470ba5aedf195b9a97.tar.bz2
rapier-9ac3503b879f95fcdf5414470ba5aedf195b9a97.zip
Merge pull request #422 from pellico/Fix_Revolute-joint-motor-target-position-is-broken-at-and-beyond-90-degree-angles
Fix #378 Added one example join_motor_position
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 4cbc398..90401a4 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -804,3 +804,13 @@ impl<T> IndexMut2<usize> for [T] {
}
}
}
+
+/// Calculate the difference with smallest absolute value between the two given values.
+pub fn smallest_abs_diff_between_sin_angles<N: WReal>(a: N, b: N) -> N {
+ // Select the smallest path among the two angles to reach the target.
+ let s_err = a - b;
+ let sgn = s_err.simd_signum();
+ let s_err_complement = s_err - sgn * N::splat(2.0);
+ let s_err_is_smallest = s_err.simd_abs().simd_lt(s_err_complement.simd_abs());
+ s_err.select(s_err_is_smallest, s_err_complement)
+}