September 7, 2016

The Circle Tutorial

Things at rest tend to stay at rest, Things in motion tend to hit the walls!

There are a couple of Physics related issues we need to discuss. The first one is Newton’s first law: An object at rest remains at rest unless acted upon by a force. An object in motion remains in motion, and at a constant velocity, unless acted upon by a force. In our earlier examples we generally drove continuously. You don’t necessarily need to do this. On earth we want to drive smoothly just like your driving instructor told you, but in space it’s the opposite. In space if we need to be somewhere by a given time, we can save a lot of fuel by accelerating hard, drifting and braking hard. Let’s try this, just to get the feel of it. In a new program “Drag Race” create our old “time” variable (remember: int time; time=0; time++;). Then in the loop() function add a couple of vectors “go” and “stop”, “go” should be set to (-1,0,0) and “stop” should be set to (1,0,0). Now add code so that when time is less than 5 we setForces() with “go” and if time greater than 9 and less than 15 we setForces() with “stop.”

Did you get that all worked out?

Did it drive to the right and then stop?

This is my version.

int time;
void init(){
void loop(){
    float go[] = {0,0,.13};
    float stop[] = {0,0,-.13};
    if(time<5) api.setForces(go);
    if(time>9 && time<15) api.setForces(stop);

The important lesson here is that if you stop driving you don’t stop moving.