Physics engine with "angular stiffness" at joints

In summary, the conversation discusses the use of a reference angle in physics engines, specifically for JavaScript. The speaker mentions their experimentation with a minimal physics engine, verlet.js, but expresses a desire to switch to a more versatile and feature-rich engine. They also mention a feature they would like to use, involving assigning a reference angle to segments and the use of three particles in the engine. The conversation then shifts to a discussion of JS physics engine comparisons and the dominance of Box2d and Matter.js in the 2D physics arena. Finally, the speaker brings up a potential question for asking suggestions on implementing the desired feature, and it is suggested to ask in the context of Box2D or Matter.js instead of verlet.js.
  • #1
Swamp Thing
Insights Author
907
572
I have been experimenting with a minimal "toy" physics engine for JavaScript, called verlet.js but now I want to switch to a more versatile and feature rich engine.

One feature I would like to use is the ability to assign a reference angle to a pair of segments (i.e. links, i.e. distance constraints), so that there will be a proportional restoring torque that will try to rotate the links back to the reference angle whenever they are bent away from that original angle. For example if we set 180 degrees for each joint in a chain, we get a cantilever that resists being bent away from a straight line. In the engine referred to above, this is done by specifying three particles (a, b, c), and the angle between ab and bc, plus a stiffness parameter. You do this for each set of three successive particles forming the cantilever.

Which JS engines support this feature or an equivalent feature?

More generally, I couldn't find any recent comparison between different open source JS physics engines -- the ones I did find are several years old. Is there a recent comparative review of JS physics engines, e.g. box2d, matter.js etc?
 
Last edited:
Technology news on Phys.org
  • #2
Swamp Thing said:
Which JS engines support this feature or an equivalent feature?
Not sure but I'd start looking at Phaser or Impact.

Swamp Thing said:
Is there a recent comparative review of JS physics engines, e.g. box2d, matter.js etc?
I don't know of one but you can find a list of open source ones at https://github.com/collections/javascript-game-engines
 
  • #3
pbuk said:
Not sure but I'd start looking at Phaser or Impact...
...you can find a list of open source (engines) at https://github.com/collections/javascript-game-engines
Those are mostly game engines. Many of them use Box2d or Matter.JS for their physics simulations.
The latter two seem to dominate the 2D physics arena in JS at present.

Swamp Thing said:
One feature I would like to use is the ability to assign a reference angle to a pair of segments (i.e. links, i.e. distance constraints), so that there will be a proportional restoring torque that will try to rotate the links back to the reference angle whenever they are bent away from that original angle.
Box2d had a feature request for this, but the fork that tried to implement it never made it into the mainstream. There are non-ideal workarounds that various people have suggested for Box2d and Matter.JS.

Meanwhile, the physics engine that I have been playing with (verlet.js, that I linked to in the OP) does try to provide angle constraints but there seems to be a flaw in it. When the joint is bent or extended, the system acquires some angular momentum.



This is not surprising, because it just rotates the three points on each time step without taking into account their distances from each other, which means it is ignoring the moment of inertia of the particles around the C.G.

(Also it assigns the same mass to all particles in the simulation).

Code:
AngleConstraint.prototype.relax = function(stepCoef) {
    var angle = this.b.pos.angle2(this.a.pos, this.c.pos);
    var diff = angle - this.angle;
   
    if (diff <= -Math.PI)
        diff += 2*Math.PI;
    else if (diff >= Math.PI)
        diff -= 2*Math.PI;

    diff *= stepCoef*this.stiffness;
   
    this.a.pos = this.a.pos.rotate(this.b.pos, diff);
    this.c.pos = this.c.pos.rotate(this.b.pos, -diff);
    this.b.pos = this.b.pos.rotate(this.a.pos, diff);
    this.b.pos = this.b.pos.rotate(this.c.pos, -diff);
}

If I want to post a question asking for suggestions as to how to implement this, should I put it here or in Classical Physics?
 
  • #4
Swamp Thing said:
If I want to post a question asking for suggestions as to how to implement this, should I put it here or in Classical Physics?
Probably here but I suspect it is too small a niche for anywhere on PF. In any case isn't the implementation going to be more governed by the paradigms of the engine you are working within? I would have thought raising in the context of Box2D and/or Matter.js would be more fruitful. verlet.js appears to be dead, I wouldn't waste your time there.
 

1. What is a "physics engine"?

A physics engine is a software program designed to simulate real-world physical systems, such as gravity, friction, and collisions, in a virtual environment. It is commonly used in video games and simulations to create realistic movements and interactions between objects.

2. What is "angular stiffness" in a physics engine?

Angular stiffness refers to the resistance of a joint in a physics engine to rotation or bending. It is a measure of how much force is needed to change the angle of a joint, and it helps determine the stability and rigidity of an object's movements.

3. How does a physics engine with "angular stiffness" at joints work?

In a physics engine with "angular stiffness" at joints, the software uses mathematical equations and algorithms to calculate the forces and movements of objects based on their mass, shape, and the stiffness of their joints. It takes into account factors such as gravity, friction, and collisions to simulate realistic movements and interactions between objects.

4. What are the benefits of using a physics engine with "angular stiffness" at joints?

Using a physics engine with "angular stiffness" at joints allows for more realistic and accurate simulations of physical systems. It also allows for more control over the movements and interactions of objects, which can be useful in creating realistic and challenging gameplay in video games or in engineering and scientific simulations.

5. Are there any limitations to using a physics engine with "angular stiffness" at joints?

One limitation of using a physics engine with "angular stiffness" at joints is that it may require more computational power and resources to run, especially for complex simulations with many objects and interactions. Additionally, the accuracy of the simulation may also be affected by the limitations of the software and the simplifications made in the mathematical models used.

Similar threads

  • Programming and Computer Science
Replies
29
Views
3K
  • Special and General Relativity
2
Replies
40
Views
2K
  • STEM Career Guidance
Replies
8
Views
2K
  • STEM Academic Advising
Replies
6
Views
1K
  • Programming and Computer Science
Replies
10
Views
3K
  • Quantum Interpretations and Foundations
Replies
25
Views
1K
Replies
16
Views
2K
  • STEM Academic Advising
Replies
2
Views
1K
  • STEM Career Guidance
Replies
5
Views
4K
  • Beyond the Standard Models
Replies
14
Views
3K
Back
Top