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

Use implicit Euler for gyroscopic torque #420

Merged
merged 2 commits into from
Jul 13, 2024
Merged

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Jul 12, 2024

Objective

Fixes #400.

Gyroscopic motion is currently accounted for with a gyroscopic term computed using semi-implicit Euler. However, this sometimes leads to the torque just blowing up and making angular velocities essentially infinite, because semi-implicit Euler extrapolates velocities, and the gyroscopic torque is quadratic in angular velocity.

This manifested as angular velocities blowing up and rotation becoming invalid for objects with non-uniform inertia, especially when spinning at high speeds, as seen in the videos below:

2024-07-13.02-24-29.mp4
2024-07-13.02-23-23.mp4

Solution

Use implicit Euler for computing the gyroscopic torque in a much more stable way. The Newton Raphson method is used to solve the resulting non-linear equations. See Erin Catto's GDC 2015 slides on Numerical Methods for more information.

This fixes the big explosions and produces higher quality simulation:

2024-07-13.02-19-21.mp4
2024-07-13.02-30-28.mp4

Implicit Euler is slightly more expensive for this, but it should be acceptable in this case. We could explore other options in the future, like making gyroscopic motion optional, or trying an adaptive approach that only uses implicit Euler as a fallback.

@Jondolf Jondolf added bugfix A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on labels Jul 12, 2024
@Jondolf Jondolf merged commit 2a25e51 into main Jul 13, 2024
4 checks passed
@Jondolf Jondolf deleted the stable-gyroscopic-motion branch July 13, 2024 12:51
@Jondolf Jondolf added C-Bug Something isn't working and removed bugfix labels Jul 19, 2024
Jondolf added a commit that referenced this pull request Aug 10, 2024
# Objective

Fixes #474.

The angular locked axes are applied to the inertia instead of the inverse inertia in gyroscopic torque computations introduced in #420, causing incorrect behavior.

## Solution

Apply the locked axes correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spawn objects randomly disappears
1 participant