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

Mechanical energy is lost when setting initial velocities or applying impulses #308

Open
paulsinnett opened this issue Aug 19, 2024 · 1 comment

Comments

@paulsinnett
Copy link

Library and Version

PhysX v5.4.1

Operating System

Windows 11

Steps to Trigger Behavior

  1. Download this sample program
  2. Compile and debug
  3. Examine the output

Expected Behavior

The mechanical energy (kinetic energy + potential energy) should remain constant.

Actual Behavior

A significant amount of energy is lost during the simulation which causes the ball to fall short of its intended height by about 4cm.

Investigation

This appears to be caused by a lag in the velocity value compared to the position. If the calculation of mechanical energy is adjusted for this lag, the energy remains constant throughout the simulation (however, the same loss shows immediately after the first frame.) If a correcting velocity value is calculated to cancel out the difference during the first frame, the simulation runs without any appreciable energy loss and the ball reaches the target height. This correction is included in the sample program.

@paulsinnett
Copy link
Author

paulsinnett commented Aug 21, 2024

I have created a simplified physics integrator to play with solutions to this issue. I think it can be handled fairly transparently by adjusting how bodies are updated on the first update after waking. Technically this is known as the leapfrog method, but really all that means is adjusting the accelerations applied during the first update frame.

https://github.com/paulsinnett/SymplecticIntegrator

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