diff options
| author | Sébastien Crozet <developer@crozet.re> | 2023-12-10 22:08:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-10 22:08:07 +0100 |
| commit | 9ac3503b879f95fcdf5414470ba5aedf195b9a97 (patch) | |
| tree | 5551e86f366f53bfaa24a266f082ff332d74e52b /src/utils.rs | |
| parent | c33b4eeb5c113b8f8509cd866c4ab48e5d6c5eaa (diff) | |
| parent | 2fba50c297987dac6971452d877c1609cee43a98 (diff) | |
| download | rapier-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.rs | 10 |
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) +} |
