Physics engine with "angular stiffness" at joints

Click For Summary

Discussion Overview

The discussion revolves around the implementation of a physics engine feature that allows for angular stiffness at joints, specifically in the context of JavaScript engines. Participants explore the capability to assign reference angles to segments and the resulting restoring torque when segments deviate from these angles. The conversation also touches on the search for recent comparisons of various open-source JavaScript physics engines.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes their experience with a minimal physics engine (verlet.js) and expresses a desire to switch to a more feature-rich engine that supports angular stiffness.
  • Another participant suggests looking into Phaser or Impact as potential engines that may support the desired feature.
  • It is noted that many game engines utilize Box2D or Matter.js for physics simulations, which dominate the 2D physics space in JavaScript.
  • A participant mentions that Box2D had a feature request for angular stiffness, but the implementation was not integrated into the mainstream version, and there are non-ideal workarounds suggested by users.
  • Concerns are raised about flaws in verlet.js, particularly regarding its handling of angular momentum when joints are bent or extended, as it does not account for the distances between particles.
  • A participant questions whether to post a request for implementation suggestions in this thread or in Classical Physics, suggesting that the implementation might be better discussed in the context of Box2D or Matter.js.

Areas of Agreement / Disagreement

Participants express varying opinions on the best engines to use and the viability of verlet.js, with some suggesting it may not be worth pursuing further. There is no consensus on a single engine that meets the desired feature set, and the discussion remains open-ended regarding the best approach to implementation.

Contextual Notes

Participants highlight limitations in the current engines, such as the lack of integrated angular stiffness features and potential flaws in existing implementations. There is also a mention of the dependency on the paradigms of the engines being used, which may influence the implementation of the desired feature.

Swamp Thing
Insights Author
Messages
1,047
Reaction score
786
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
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
 
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?
 
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.
 

Similar threads

Replies
29
Views
5K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 40 ·
2
Replies
40
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 25 ·
Replies
25
Views
6K