JavaScript Physics engine with "angular stiffness" at joints

AI Thread Summary
The discussion focuses on the need for a JavaScript physics engine that supports angular stiffness at joints, specifically the ability to assign a reference angle to segments for restoring torque. The user is transitioning from verlet.js to a more versatile engine and is seeking recent comparisons of open-source engines like Box2D and Matter.js, which dominate the 2D physics space. While Box2D had a feature request for angular constraints, it has not been fully implemented, and workarounds exist. The user notes issues with verlet.js, particularly its failure to account for angular momentum and moment of inertia. Suggestions for posting implementation questions lean towards Box2D or Matter.js due to their more active development and community support.
Swamp Thing
Insights Author
Messages
1,032
Reaction score
770
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.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Back
Top