力
1.概述
力是一个向量,它使有质量的物体产生加速。
牛顿三大定律:
牛顿第一定律:物体有保持静止或运动的趋势。
牛顿第二定律:力等于质量乘以加速度。
牛顿第三定律:力总是成对出现,并且这两个力大小相等方向相反。
力的作用基于这三个定理实现。
2.拓展与应用
(1)纸飞机:风力+重力+摩擦力
纸飞机运动过程中受到风力、重力、摩擦力的作用。
重力大小由物体质量决定,风力大小统一,收到的摩擦力大大小受物体质量影响。
定义纸飞机:
class PaperPlane {
PImage img;
PVector position;
PVector velocity;
PVector acceleration;
float mass;
PaperPlane(float m, float x , float y) {
mass = m;
position = new PVector(x,y);
velocity = new PVector(0,0);
acceleration = new PVector(0,0);
}
//牛顿第二顶定律计算加速度
void applyForce(PVector force) {
PVector f = PVector.div(force,mass);
acceleration.add(f);
}
void update() {
velocity.add(acceleration);
position.add(velocity);
acceleration.mult(0);
}
void display() {
stroke(0);
strokeWeight(2);
fill(0,127);
drawplane(position.x,position.y);
}
void drawplane(float posx,float posy)
{
pushMatrix();
img = loadImage("飞机.png");
image(img,posx,posy,50,50);
popMatrix();
}
}
施加风力、重力、摩擦力
for (int i = 0; i < paperplanes.length; i++) {
PVector wind = new PVector(0.5, -0.3);
PVector gravity = new PVector(0, 0.1*paperplanes[i].mass);
float c = 0.1;
PVector friction = paperplanes[i].velocity.get();
friction.mult(-1);
friction.normalize();
friction.mult(c);
paperplanes[i].applyForce(friction);
paperplanes[i].applyForce(wind);
paperplanes[i].applyForce(gravity);
paperplanes[i].update();
paperplanes[i].display();
}
(2)小球:重力+流体阻力+弹力
受力分析:小球下落过程中持续受到重力,小球落入水中之后受到重力及流体阻力,小球接触底部是受到重力、流体阻力和弹力。
重力、流体阻力对位置的影响都是由牛顿第二定律计算加速度进而改变速度,从而改变小球位置,控制小球运动。
物体通过流体或者气体时同样会受摩擦力的作用,这种摩擦力有很多名字,如粘滞
力、阻力和流体阻力。
计算流体阻力:
//计算阻力
PVector drag(Mover m) {
//大小是系数*速度平方
float speed = m.velocity.mag();
float dragMagnitude = c * speed * speed;
// 方向与速度相反
PVector dragForce = m.velocity.get();
dragForce.mult(-1);
dragForce.normalize();
dragForce.mult(dragMagnitude);
return dragForce;
}
定义小球:
class Mover {
PVector position;
PVector velocity;
PVector acceleration;
float mass;//质量由大小决定
Mover(float m, float x, float y) {
mass = m;
position = new PVector(x, y);
velocity = new PVector(0, 0);
acceleration = new PVector(0, 0);
}
// 牛顿第二定律
void applyForce(PVector force) {
// 除以重力
PVector f = PVector.div(force, mass);
// 累积所有加速度
acceleration.add(f);
}
void update() {
velocity.add(acceleration);
position.add(velocity);
// 我们必须清除每帧的加速度
acceleration.mult(0);
}
void display() {
stroke(0);
strokeWeight(2*2.25);
fill(0,127,200);
ellipse(position.x, position.y, mass*16, mass*16);
}
// 窗口底部弹性
void checkEdges() {
if (position.y > height) {
velocity.y *= -0.7;
position.y = height;
}
}
}
施加重力、流体阻力
for (int i = 0; i < movers.length; i++) {
//是否在水里
if (liquid.contains(movers[i])) {
// 计算流体阻力
PVector dragForce = liquid.drag(movers[i]);
// 对物体施加流体阻力
movers[i].applyForce(dragForce);
}
// 重力按质量缩放的
PVector gravity = new PVector(0, 0.2*movers[i].mass);
//施加重力
movers[i].applyForce(gravity);
// 更新并显示
movers[i].update();
movers[i].display();
movers[i].checkEdges();
}