OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why is there a loss of energy in matter.js newtons cradle?

  • Thread starter Thread starter texi
  • Start date Start date
T

texi

Guest
In the live simulation available at https://brm.io/matter-js/demo/#newtonsCradle, how can the issue of energy loss be resolved? Despite setting friction to zero, energy loss still occurs.

Does anyone have an idea?

Code:
/**
* Creates a composite with a Newton's Cradle setup of bodies and constraints.
* @method newtonsCradle
* @param {number} xx
* @param {number} yy
* @param {number} number
* @param {number} size
* @param {number} length
* @return {composite} A new composite newtonsCradle body
*/
Example.newtonsCradle.newtonsCradle = function(xx, yy, number, size, length) {
    var Composite = Matter.Composite,
        Constraint = Matter.Constraint,
        Bodies = Matter.Bodies;

    var newtonsCradle = Composite.create({ label: 'Newtons Cradle' });

    for (var i = 0; i < number; i++) {
        var separation = 1.9,
            circle = Bodies.circle(xx + i * (size * separation), yy + length, size, 
                { inertia: Infinity, restitution: 1, friction: 0, frictionAir: 0, slop: size * 0.02 }),
            constraint = Constraint.create({ pointA: { x: xx + i * (size * separation), y: yy }, bodyB: circle });

        Composite.addBody(newtonsCradle, circle);
        Composite.addConstraint(newtonsCradle, constraint);
    }

    return newtonsCradle;
};

The full code is freely accessible through their github page or the provided link > code icon.

<p>In the live simulation available at <a href="https://brm.io/matter-js/demo/#newtonsCradle" rel="nofollow noreferrer">https://brm.io/matter-js/demo/#newtonsCradle</a>, how can the issue of energy loss be resolved? Despite setting friction to zero, energy loss still occurs.</p>
<p>Does anyone have an idea?</p>
<pre><code>/**
* Creates a composite with a Newton's Cradle setup of bodies and constraints.
* @method newtonsCradle
* @param {number} xx
* @param {number} yy
* @param {number} number
* @param {number} size
* @param {number} length
* @return {composite} A new composite newtonsCradle body
*/
Example.newtonsCradle.newtonsCradle = function(xx, yy, number, size, length) {
var Composite = Matter.Composite,
Constraint = Matter.Constraint,
Bodies = Matter.Bodies;

var newtonsCradle = Composite.create({ label: 'Newtons Cradle' });

for (var i = 0; i < number; i++) {
var separation = 1.9,
circle = Bodies.circle(xx + i * (size * separation), yy + length, size,
{ inertia: Infinity, restitution: 1, friction: 0, frictionAir: 0, slop: size * 0.02 }),
constraint = Constraint.create({ pointA: { x: xx + i * (size * separation), y: yy }, bodyB: circle });

Composite.addBody(newtonsCradle, circle);
Composite.addConstraint(newtonsCradle, constraint);
}

return newtonsCradle;
};
</code></pre>
<p>The full code is freely accessible through their github page or the provided link > code icon.</p>
 

Latest posts

Top