EduCSE Blog

Share

Axially Deformable Elastic Link

Author: Win Aung Cho
Now link will be modeled to act as a truss bar. Origionally Link element is extended to a BorderLink through which particles can't pass. If a particle hit the BoderLink, both of link and particle get response of reaction which means that reactive forces from hitting particle and link will be shared to both of link and particle.

Origional Link Element is …
class Link {
		constructor(p1, p2, length) {
			this.p1 = p1;
			this.p2 = p2;
			this.color = 'f5476a';
			// if the length is not given then calculate the distance based on position
			if(!length) {
				this.length = this.p1.pos.dist(this.p2.pos);
			} else {
				this.length = length;
			}
		}
		update() {
			const dir = SUB(this.p1.pos, this.p2.pos);
			const dist = dir.mag();
			const percent = (this.length - dist) / dist / 2;
			const offset = dir.mult(percent);
			let mt = this.p1.mass + this.p2.mass;
			let m2 = this.p1.mass / mt;
			let m1 = this.p2.mass / mt;
			if(!this.p1.fixed) {
				this.p1.pos.add(offset.copy().mult(m1));
			}
			if(!this.p2.fixed) {
				this.p2.pos.sub(offset.copy().mult(m2));
			}
		}
		render(ctx) {
			ctx.beginPath();
			ctx.strokeStyle = this.color;
			let sp1 = Screen(this.p1.pos.x, this.p1.pos.y);
			let sp2 = Screen(this.p2.pos.x, this.p2.pos.y);
			ctx.moveTo(sp1.x, sp1.y);
			ctx.lineTo(sp2.x, sp2.y);
			ctx.stroke();
			ctx.closePath();
		}
	}
Axially deformable elastic link
BorderLink share the reaction from hitting with particle by means of acceleration with respect to hitting velocity and propotionality of mass.
class BorderLink extends Link {
		constructor(p1, p2, length) {
			super(p1, p2, length);
			this.border = true;
			this.r = {};
		}
		surfaceNormal() {
			//alert("nor");
			return Math.atan2(this.p2.pos.y - this.p1.pos.y, this.p2.pos.x - this.p1.pos.x) - Math.PI * 0.5;
		}
		update() {
			super.update();
		}
		render(ctx) {
			super.render(ctx);
		}
		circleLineCollision(n) {
			var r = pointonline(n.pos, this.p1.pos, this.p2.pos);
			this.r = r;
			if(r.t <= 1.0 && r.t >= 0.0) {
				if(r.dist <= n.radius) return true;
			}
			return false;
		}
		collide(n, dt) {
			if(n == this.p1 || n == this.p2) return;
			if(this.border && !n.fixed) {
				var i = 0;
				while(this.circleLineCollision(n) && i < 100) {
					var vx = (n.pos.x - n.oldpos.x) / dt * (n.groundFriction);
					var vy = (n.pos.y - n.oldpos.y) / dt * (n.groundFriction);
					var speed = Math.sqrt(vx * vx + vy * vy);
					n.oldpos.x = n.pos.x;
					n.oldpos.y = n.pos.y;
					n.pos.x += this.r.normal.x * speed * dt;
					n.pos.y += this.r.normal.y * speed * dt;
					if(!this.p1.fixed) {
						this.p1.pos.x -= this.r.normal.x * speed * dt * (1 - this.r.t);
						this.p1.pos.y -= this.r.normal.y * speed * dt * (1 - this.r.t);
					}
					if(!this.p2.fixed) {
						this.p2.pos.x -= this.r.normal.x * speed * dt * this.r.t;
						this.p2.pos.y -= this.r.normal.y * speed * dt * this.r.t;
					}
					i++;
				}
			}
		}
	}
Collision response of circle with circle
Elastic deformation is calculated for the ElasticLink. Stiffness is applied to get the axial force of the link and reactive forces of axial force are responsed to both end particles of ElasticLink.
ElasticLink is extended from BorderLink.
class elasticLink extends BorderLink {
		constructor(p1, p2, length) {
			super(p1, p2, length);
			this.stiffness = 0.3;
		}
		surfaceNormal() {
			return super.surfaceNormal();
		}
		render(ctx) {
			super.render(ctx);
		}
		circleLineCollision(n) {
		    return super.circleLineCollision(n);
		}
		collide(n, dt) {
		    super.collide(n, dt);
		}
		update() {
			const dir = SUB(this.p1.pos, this.p2.pos);
			const dist = dir.mag();
			const deform = (this.length - dist);
			const force = deform*this.stiffness;
			const offset = dir.mult(force/dist);
			
			let m1 = this.p1.mass;
			let m2 = this.p2.mass;
			if(!this.p1.fixed) {
				this.p1.pos.add(MUL(offset.copy().mult(1/m1), stepTime*stepTime));
				//alert("ok");
			}
			if(!this.p2.fixed) {
				this.p2.pos.sub(MUL(offset.copy().mult(1/m2), stepTime*stepTime));
			}
			
		}
	}


Demo

Truss Bridge Model


It is written in java script, a program that solves Newton's motion equation using Verlet integration. This is an example of applying force to the axle of a wheel and passing it across a truss bridge and rigid link, flexible link.



Author: Win Aung Cho
13-Jun-2022 04:11:14 AM*