liabru / matter-js

a 2D rigid body physics engine for the web ▲● ■
MIT License
16.83k stars 1.96k forks source link

How to get a Perfect-Elastic-Collision system? #626

Closed ljt1469 closed 6 years ago

ljt1469 commented 6 years ago

I tried to get a system of one particle within a container.

I am sure that the options of the particle and the wall is set correctly, such as friction is 0, restitution is 1. But, I found the velocity of the particle became slow when it collided with the container wall(the wall is a rectangle).It means that the kinetic energy of particle reduce when the collision happen.

So why and how to make the collision between particle and wall Perfect Elastic Collision?

jared83 commented 6 years ago

This is an issue I am struggling with myself. Not sure why this is the case, but the problem may be to be related to rounding errors (in the Verlet integration engine of matter.js?). The workaround I devised is to transfer velocity manually at each collision. Kinda works, but is very hacky and won't work as expected if masses of collided particles differ (unless you take it under consideration in your custom, perfectly-elastic velocity transferring function). Not to mention the performance impact of such calculations on top of what matter.js is doing...

liabru commented 6 years ago

See thread #256, which discusses this with some suggestions around this issue. Please leave any further comments there as I'm closing this as a duplicate, thanks for raising though.