xxxxxxxxxx
126
let x1,y1,x2,y2,l1,l2,p1,p2,m1,m2,theta1,theta2,theta1vel,theta2vel,theta1Acc,theta2Acc;
let x1_,y1_,x2_,y2_,l1_,l2_,p1_,p2_,m1_,m2_,theta1_,theta2_,theta1vel_,theta2vel_,theta1Acc_,theta2Acc_;
const g = 2;
let x2p,y2p;
let x2p_,y2p_;
function setup() {
createCanvas(400, 400);
l1 = 100;
l2 = 100;
m1 = 10;
m2 = 10;
theta1 = PI/2;
theta2 = PI/2 + 16 * PI/180;
theta1Vel = 0;
theta2Vel = 0;
l1_ = 100;
l2_ = 100;
m1_ = 10;
m2_ = 10;
theta1_ = PI/2;
theta2_ = PI/2 + 18 * PI/180;
theta1Vel_ = 0;
theta2Vel_ = 0;
//background(220);
//frameRate(30);
}
function draw() {
background(220);
let nom = -g * (2 * m1 + m2)*sin(theta1) - m2*g*sin(theta1 - 2*theta2) - 2*sin(theta1 - theta2)*m2*(theta2Vel ** 2 * l2 + theta1Vel**2 * l1* cos(theta1 - theta2));
let den = l1*(2*m1 + m2 - m2*cos(2*theta1 - 2*theta2));
theta1Acc = nom/den;
nom = 2*sin(theta1 - theta2) * (theta1Vel**2 * l1 * (m1 + m2) + g*(m1 + m2) * cos(theta1) + theta2Vel**2 * l2 * m2 * cos(theta1 - theta2))
den = l2*(2*m1 + m2 - m2*cos(2*theta1 - 2*theta2))
theta2Acc = nom/den;
x1 = l1*sin(theta1);
y1 = l1*cos(theta1);
x2 = x1 + l2*sin(theta2);
y2 = y1 + l2*cos(theta1);
if(x2p == null){
x2p = x1 + l2*sin(theta2);
y2p = y1 + l2*cos(theta1);
}
// stroke(0,0,0,10);
translate(width/2,height/2);
//fill(100,100,100,10);
stroke(0);
fill(100)
line(0,0,x1,y1);
circle(x1,y1,m1);
line(x1,y1,x2,y2);
circle(x2,y2,m2);
//stroke(0);
//line(x2p,y2p,x2,y2);
theta1Vel += theta1Acc;
theta2Vel += theta2Acc;
// theta1Vel *= 0.99;
// theta2Vel *= 0.99;
theta1 += theta1Vel;
theta2 += theta2Vel;
x2p = x2;
y2p = y2;
//------\\
nom = -g * (2 * m1_ + m2_)*sin(theta1_) - m2_*g*sin(theta1_ - 2*theta2_) - 2*sin(theta1_ - theta2_)*m2_*(theta2Vel_ ** 2 * l2_ + theta1Vel_**2 * l1_* cos(theta1_ - theta2_));
den = l1_*(2*m1_ + m2_ - m2_*cos(2*theta1_ - 2*theta2_));
theta1Acc_ = nom/den;
nom = 2*sin(theta1_ - theta2_) * (theta1Vel_**2 * l1_ * (m1_ + m2_) + g*(m1_ + m2_) * cos(theta1_) + theta2Vel_**2 * l2_ * m2_ * cos(theta1_ - theta2_))
den = l2_*(2*m1_ + m2_ - m2_*cos(2*theta1_ - 2*theta2_))
theta2Acc_ = nom/den;
x1_ = l1_*sin(theta1_);
y1_ = l1_*cos(theta1_);
x2_ = x1_ + l2_*sin(theta2_);
y2_ = y1_ + l2_*cos(theta1_);
if(x2p_ == null){
x2p_ = x1_ + l2_*sin(theta2_);
y2p_ = y1_ + l2_*cos(theta1_);
}
// stroke(0,0,0,10);
//translate(width/2,height/2);
// fill(100,100,100,10);
stroke(0);
fill(255,0,0);
line(0,0,x1_,y1_);
circle(x1_,y1_,m1_);
line(x1_,y1_,x2_,y2_);
circle(x2_,y2_,m2_);
//stroke(255,0,0);
//line(x2p_,y2p_,x2_,y2_);
theta1Vel_ += theta1Acc_;
theta2Vel_ += theta2Acc_;
// theta1Vel_ *= 0.99;
// theta2Vel_ *= 0.99;
theta1_ += theta1Vel_;
theta2_ += theta2Vel_;
x2p_ = x2_;
y2p_ = y2_;
}