// Project P1a // Implement the following functions as suggested (do not use f7 to implement them) // constant speed in [0,1] float f1(float t) {return(t);} // constant acceleration in [0,0.5], then constant deceleration (Hint: solve second degree equation for the accelration value) float f2(float t) { if (t <= .5) return(4*.5*t*t); // replace this with your own else return(-.5 + 2*t - .5 * 4 * (t-.5) * (t-.5)); } // more dynamic than f2: more acceleration at first and breaks later (Hint: use cos) float f3(float t) { return(-(cos(3*t)/2.0 - .5)); } // heavy car: slow start then breaks hard (Hint: use cos power or rational function) float f4(float t) { return(pow(cos(t-1),9)); } // wind up first and overshoot a bit (Hint: use cubic Bezier) // bezier equation from wikipedia.org (http://en.wikipedia.org/wiki/B%C3%A9zier_curve) float f5(float t) { float p0=0, p1=-.2, p2=.5, p3=1, b; float oneminust = (1-t); b = p0 * oneminust*oneminust*oneminust + 3 * p1 * t *oneminust*oneminust + 3 * p2 * t*t * oneminust + p3 * t*t*t; return(b); } // start with high speed, then slows down (Hint: use cubic with different values) float f6(float t) { float p0=0, p1=.8, p2=.9, p3=1, b; float oneminust = (1-t); b = p0 * oneminust*oneminust*oneminust + 3 * p1 * t *oneminust*oneminust + 3 * p2 * t*t * oneminust + p3 * t*t*t; return(b); }