Euler-Cauchy Motion
Author: Win Aung ChoEuler-Cauchy form motion is a kind of Velocity Verlet Algorythm and used for the rigid body movement.
x(t+Δt) = x(t) + f(t)•Δt + O[Δt²]
Newton's motion equation can be written in discrete form as following.
x(t+Δt)=x(t)+Δt•v(t)+1/2•Δt²•F(x(t))/m + O[Δt⁴]
v(t+Δt)=v(t)+Δt•F(x(t))/m + O[Δt²]
x(t+Δt) = x(t) + f(t)•Δt + O[Δt²]
Newton's motion equation can be written in discrete form as following.
x(t+Δt)=x(t)+Δt•v(t)+1/2•Δt²•F(x(t))/m + O[Δt⁴]
v(t+Δt)=v(t)+Δt•F(x(t))/m + O[Δt²]
A point object that moves according to Euler motion can be modeled as following.
class Point { constructor(x, y, vx, vy) { this.pos = new Vector(x, y); this.vel = new Vector(vx || 0, vy || 0); // velocity x, y this.radius = 15; this.color = "e62a4f"; this.fixed = false; } update() { if (this.fixed) return; let acc = new Vector(0.0,0.0); acc.add(Gravity); this.vel.add(acc.mult(stepTime*stepTime*0.5)); this.pos.add(MUL(this.vel, stepTime)); //this.pos.add(Gravity); } checkborder() { if (this.fixed) return; if(this.pos.x > CANVAS_WIDTH - this.radius) { this.pos.x = CANVAS_WIDTH - this.radius; this.vel.x *= -1.0; } if(this.pos.x < this.radius) { this.pos.x = this.radius; this.vel.x *= -1.0; } if(this.pos.y > CANVAS_HEIGHT - this.radius) { this.pos.y = CANVAS_HEIGHT - this.radius; this.vel.y *= -1.0; } if(this.pos.y < this.radius) { this.pos.y = this.radius; this.vel.y *= -1.0; } } render(ctx) { ctx.beginPath(); ctx.fillStyle = this.color; ctx.arc(this.pos.x, this.pos.y, this.radius, 0, Math.PI * 2); ctx.fill(); ctx.closePath(); } }
Process wil run by following function.
Demo
function animate() { ctx.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); for(let d of dots) { d.update(); d.checkborder(); d.render(ctx); } requestAnimationFrame(animate); }
Demo
Author: Win Aung Cho
12-Jun-2022 08:00:56 PM*