[ad_1]
Chapter: 2
Official book website:
Twitter:
This video covers attraction forces (modeled after gravity) between objects.
Read along:
Help us caption & translate this video!
[ad_1]
Chapter: 2
Official book website:
Twitter:
This video covers attraction forces (modeled after gravity) between objects.
Read along:
Help us caption & translate this video!
by
Tags:
Hi Daniel, when I try with multiple movers I get this error "The constructor simple_atraction_varios_movers.Mover(float, float, float) is undefined"
Do I need to change something in the Mover class???
Mover[] movers = new Mover[10];
Attractor a;
void setup() {
size(400, 400);
for (int i = 0; i< movers.length; i++) {
movers[i] = new Mover(random(0.1, 2), random(width), random(height));
}
a = new Attractor();
}
void draw() {
background(255);
a.display();
for (int i = 0; i< movers.length; i++) {
//{!1} Calculate an attraction force for each Mover object.
PVector force = a.attract(movers[i]);
movers[i].applyForce(force);
movers[i].update();
movers[i].display();
}
}
——————
class Mover {
PVector location;
PVector velocity;
PVector acceleration;
float mass;
Mover() {
location = new PVector(5, 0);
velocity = new PVector(0, 1);
acceleration = new PVector(0, 0);
mass = random(0.1,3);
}
//// Newton´s 2nd Law with mass!
void applyForce(PVector force) {
PVector f = PVector.div(force,mass);
acceleration.add(f);
}
void update() {
//acceleration = PVector.random2D();
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
//velocity.limit(50);
}
void edges() {
if (location.x > width) {
location.x = width;
velocity.x *= -1;
}
else if (location.x < 0){
velocity.x *= -1;
location.x = 0;
}
if (location.y > height) {
velocity.y *= -1;
location.y = height;
}
//if (location.x>width) location.x=width;
//if (location.x<0) location.x =width;
//if (location.y >height) location.y=0;
//if (location.y<0) location.y=height;
}
//
void display() {
fill (127);
ellipse(location.x, location.y, mass*20, mass*20);
stroke(50);
strokeWeight(1);
}
}
Universal Gravitational Constant = 6.67408 × 10^-11 m^3 kg^-1 s^-2
Dan, these videos are great, they really have helped me a lot.
Your video it's amazing Daniel!
You've brought back the passion for physics and spawned a passion for the coding.
I'm really glad to have bought your books!
you are one of the good guys thx
Thankyou for all your hard work. Really enjoying
Dan,
I really enjoy the "physics" approach in these videos. Do you have a favorite Physics book, other than NOC?
your github does not exist.
what is the point of normalizing? doesnt it change the magnitude to 1? if so why not just set the mag to 1?
Great series so far, but I have to say, when you used constrict it made me feel really uneasy. You could have just increased the gravitational constant, or the masses of the objects. If for some reason that would have caused some strange behavior because of the objects moving too fast, constricting the maximum velocity of the movers would have been a better option, because that at least has an analog in the real world, while forces that stop getting weaker, don't.
I watched the first two chapters and learned more then in one year in school. The for that
Although the lesson is very much explanatory, I feel I should learn this section form the book.
Excelent, I didn't undestand a sheep from my class. 🙁
Great videos, Daniel! You are clear, detailed and hilarious, so keep the vids coming!
Leave a Reply