I wanted to pass on towards acceleration or velocity towards mouse, but then decided that it made more sense to begin with force.

Well , any object stays at it is, at rest or in motion, unless an external force acts on it. So, if you have one force acting, the object will move in it’s direction, if you have many forces acting, it will move in the direction of the resolved forces.

So, just apply a force, and the object will move. Secondly,

The net force being applied varies directly with the acceleration.

F = m * a

m the mass will remain constant, so we can invent a value for it.

2ndly we see that by playing with acceleration, we are directly modifying . . . froce applied !

That’s what we’ll be doing

Bouncing ball using only acceleration

PVector location;
PVector velocity;
PVector acceleration;

void setup(){
size(400,400);
location=new PVector(200,height);
velocity = new PVector(0,0);
acceleration=new PVector(0,0);
}

void draw(){
background(0);
location.add(velocity);
velocity.add(acceleration);

acceleration.add(0,0.001);
velocity.limit(5);

fill(255);
ellipse(location.x,location.y,30,30);

if (location.x < 0 || location.x >width ){
velocity.x *= -1;
}
if (location.y < 0 || location.y >height ){
velocity.y *= -1;
}

}

The location only specifies  the begining point, else all motion is the result of acceleration.

The balls bounces up and down up and down .  . .  with only alteration on acceleration which in turns affects force .

for a mass of 1kg, F =a

accff

There is a 3rd law, if body A exerts a force on body B, body B exerts an equal but opposite force.

Note : In the above code, the is just a fault. our acceleration gets too crazy. we correct that by a velocity.limit();

 

 

 

Advertisements