Question

I went through the vectors tutorial on the open frameworks tutorial page and did some experiment .With the code i wrote ,i found out that the circle slows down as it reaches its destination,like its de-accelerating .why is it de-accelerating even though i did not write any code for de-acceleration? Here is the code:

#inlcude"testApp.h"

ofVec2f V1(500,500);
ofVec2f V2(500,500);
ofVec2f V3(2,2);

void testApp::draw(){

ofEnableSmoothing();

ofSetColor(0, 0, 0);
ofFill();

ofCircle(V1[0], V1[1], 10);

if(V1[0] < 3 && V1[1] < 3)
{
    V1 = V2;
}
else
{
    V1 = V1 + (0.009)*(V3 - V1);
}

ofSetColor(0, 0, 0);
ofFill();
ofCircle(144, 900, 10);

}
Was it helpful?

Solution

Each frame, you move V1 by 0.9% of the distance between V1 and V3 towards V3. (V1 = V1 + (0.009)*(V3 - V1);)
As V1 gets closer to V3, 0.009 * (V3 - V1) also gets smaller, so you actually did write code for deceleration :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top