Error in `slerp()` formula for `UnitComplex`?
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 565
- PR merge metrics
- No merged PRs in 30d
Description
So I was poking through the code for rotational interpolation, and I saw the definition for `slerp()` for `UnitComplex` was
```rust
pub fn slerp(&self, other: &Self, t: T) -> Self {
Self::new(self.angle() * (T::one() - t.clone()) + other.angle() * t)
}
```
However, this causes some really weird behavior with certain pairs of complex numbers where they will rotate the long way around.
For instance, if you `slerp()` from e^(-3pi/4) to e^(3pi/4), this code will interpolate the angle *counter clockwise* from -135° to 135° even though going clockwise is the shorter path.
```rust
use std::f64::consts::PI;
let c1 = UnitComplex::new( -135.0f64.to_radians() );
let c2 = UnitComplex::new( 135.0f64.to_radians() );
// left = Complex { re: 1.0, im: 0.0 }
// right = Complex { re: -1.0, im: 1.2246467991473532e-16 }
assert_relative_eq!(c1.slerp(&c2, 0.5), UnitComplex::new(PI), epsilon=2e-10);
```
Of course, do say so if this is intended, but I would imagine going clockwise here would be the more natural choice?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.