#include "geometry.h"


//----------------------------------------------------------
ofVec3f interpolatePt(ofVec3f pts[4], float pctx, float pcty){


	// .... it's like this:
	// 3 2
	// 0 1 
	
	ofVec3f diffx0 = pts[1] - pts[0];
	ofVec3f diffx1 = pts[2] - pts[3];
	ofVec3f ptx0 = pts[0] + pctx * diffx0;
	ofVec3f ptx1 = pts[3] + pctx * diffx1;
	
	return ( (pcty)*ptx0 + (1-pcty)*ptx1);

}




//-----------------------------------------------------
ofVec3f getBezierPt( ofVec3f* cp, float t ){
    float   ax, bx, cx;
    float   ay, by, cy;
    float   tSquared, tCubed;
    ofVec3f result;

    /* calculate the polynomial coefficients */

    cx = 3.0 * (cp[1].x - cp[0].x);
    bx = 3.0 * (cp[2].x - cp[1].x) - cx;
    ax = cp[3].x - cp[0].x - cx - bx;
        
    cy = 3.0 * (cp[1].y - cp[0].y);
    by = 3.0 * (cp[2].y - cp[1].y) - cy;
    ay = cp[3].y - cp[0].y - cy - by;
        
    /* calculate the curve point at parameter value t */
        
    tSquared = t * t;
    tCubed = tSquared * t;
        
    result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
    result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
        
    return result;
}