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

Quaternion slerp returning nan values #68

Closed
SlidyBat opened this issue Apr 14, 2023 · 2 comments
Closed

Quaternion slerp returning nan values #68

SlidyBat opened this issue Apr 14, 2023 · 2 comments
Assignees
Labels

Comments

@SlidyBat
Copy link

Found that slerp can sometimes return nan values, caused by a division by 0 in the implementation.
To replicate:

auto r = slerp(
	quaternion( -0.0112188980, -0.0367633253, -0.00361495349, -0.999254525 ),
	quaternion( -0.0114078531, -0.0367971063, -0.00342923636, -0.999251783 ),
	0.691265166
);
assert( !any( isnan( r ) ) );
@redorav redorav self-assigned this Apr 14, 2023
@redorav redorav added the bug label Apr 14, 2023
@redorav
Copy link
Owner

redorav commented Apr 14, 2023

I'll take a look asap today. Thanks for reporting and a good repro case

@redorav
Copy link
Owner

redorav commented Apr 15, 2023

Hi @SlidyBat I've fixed this in b19c81b

There were two issues, one with vectors where the dot product is slightly beyond the range of acos, the other when the angle is 0 and we divide by it, both of which have been fixed and don't add that much cost.

After reading further about slerp I realized that most people seem to use a normalized lerp they call nlerp which has different properties but is a lot faster. If this is useful to you and you want to give it a go, there's an nlerp function now. I've also kept lerp in case you want to lerp multiple times, then normalize at the end which is the same as calling nlerp multiple times but is faster.

Hopefully this fixes your issue.

@redorav redorav closed this as completed Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants