Constraint_Distance class
class Constraint_Distance implements Constraint { final Segment segment; double stiffness; double _distance2; Vector3 _stick = new Vector3.zero(); Constraint_Distance(this.segment, this.stiffness) { _distance2 = (segment.ps.position3d[segment.i1] - segment.ps.position3d[segment.i2]).length; } factory Constraint_Distance.fromParticles(ps, i1, i2, stiffness, [collide = 0]) { return new Constraint_Distance(new Segment(ps, i1, i2, collide), stiffness); } //get a => segment.ps.position3d[segment.i1]; //get b => segment.ps.position3d[segment.i2]; relax(stepCoef) { var a = segment.ps.position3d[segment.i1]; var b = segment.ps.position3d[segment.i2]; _stick.setFrom(a).sub(b); var l = _stick.length; var diff = ( _distance2 - l)/l; _stick.scale(diff * stiffness * stepCoef); var ma = segment.ps.mass[segment.i1]; var mb = segment.ps.mass[segment.i2]; var mw = (ma + mb);// * stiffness; a.add(_stick.scale(ma / mw)); b.sub(_stick.scale(mb / ma)); // _stick(mb / mw) } }
Implements
Constructors
new Constraint_Distance(Segment segment, double stiffness) #
Creates a new Object instance.
Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.
docs inherited from Object
Constraint_Distance(this.segment, this.stiffness) { _distance2 = (segment.ps.position3d[segment.i1] - segment.ps.position3d[segment.i2]).length; }
factory Constraint_Distance.fromParticles(ps, i1, i2, stiffness, [collide = 0]) #
factory Constraint_Distance.fromParticles(ps, i1, i2, stiffness, [collide = 0]) { return new Constraint_Distance(new Segment(ps, i1, i2, collide), stiffness); }
Methods
dynamic relax(stepCoef) #
relax(stepCoef) { var a = segment.ps.position3d[segment.i1]; var b = segment.ps.position3d[segment.i2]; _stick.setFrom(a).sub(b); var l = _stick.length; var diff = ( _distance2 - l)/l; _stick.scale(diff * stiffness * stepCoef); var ma = segment.ps.mass[segment.i1]; var mb = segment.ps.mass[segment.i2]; var mw = (ma + mb);// * stiffness; a.add(_stick.scale(ma / mw)); b.sub(_stick.scale(mb / ma)); // _stick(mb / mw) }