Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in slerp() formula for UnitComplex? #1093

Open
jsmith628 opened this issue Mar 21, 2022 · 0 comments
Open

Error in slerp() formula for UnitComplex? #1093

jsmith628 opened this issue Mar 21, 2022 · 0 comments

Comments

@jsmith628
Copy link
Contributor

So I was poking through the code for rotational interpolation, and I saw the definition for slerp() for UnitComplex was

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.

    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?

jsmith628 added a commit to jsmith628/nalgebra that referenced this issue Mar 21, 2022
jsmith628 added a commit to jsmith628/nalgebra that referenced this issue Mar 21, 2022
sebcrozet added a commit that referenced this issue Apr 26, 2022
smr97 pushed a commit to smr97/nalgebra that referenced this issue May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant