#include "Physics.as"
_root.onLoad = function() {
ball1.ForcedirectionX(0);
ball1.ForcedirectionY(0);
ball1.VdirectionX(0);
ball1.VdirectionY(0);
ball1.CreateBasicPhysicsFeature(5, 0, 0, 0);
ball2.CreateBasicPhysicsFeature(10, 0, 0, 0);
ball1.CreateExtendMotionFeature(0, 0, 0, 0);
ball1.ForcedirectionX(0);
ball1.ForcedirectionY(0);
G = 1000;
}
///***Fundamental Function***///
function Getdistance(mc1, mc2) {
return Math.sqrt((mc1._x-mc2._x)*(mc1._x-mc2._x)+(mc1._y-mc2._y)*(mc1._y-mc2._y));
}
function StardandlizeAngle(mc1, mc2) {// b)计算出MC1到MC2的方向向量:
var l = Getdistance(mc1, mc2);
mc1.ForcedirectionX = (mc2._x-mc1._x)/l;
mc1.ForcedirectionY = (mc2._y-mc1._y)/l;
}
function normal_vector(mc) {
// 求MC1沿顺时针绕MC2转的法向向量。
mc.VdirectionX = mc.ForcedirectionY;
mc.VdirectionY = -mc.ForcedirectionX;
}
///***Combine Function***///
function doForce_n() {
r = Getdistance(ball1, ball2);
var Force_n = G*ball1.m*ball2.m/(r*r);
ball1.v = Math.sqrt(Force_n*r/ball1.m);//根据向心力求匀速圆周运动速度
}
function doMove_Circle() {
StardandlizeAngle(ball1, ball2);
normal_vector(ball1);
ball1.vx = ball1.v*ball1.VdirectionX;
ball1.vy = ball1.v*ball1.VdirectionY;
ball1._x += ball1.vx;
ball1._y += ball1.vy;
}
_root.onEnterFrame = function() {
doForce_n();
doMove_Circle();
};