/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { //HERMITE: p1=p0 p2=p1 p3=r0 p4=r1 //BEZIER: p1 = p0 p2 = other point 2 p3 = other point 1 p4 = p1 struct matrix * coefs = new_matrix(4, 1); struct matrix * inverse = new_matrix(4, 4); if (type == HERMITE_MODE){ coefs->m[0][0] = p1; coefs->m[1][0] = p2; coefs->m[2][0] = p3-p1; coefs->m[3][0] = p4-p2; inverse = make_hermite(); } else if (type == BEZIER_MODE){ coefs->m[0][0] = p1; coefs->m[1][0] = p3; coefs->m[2][0] = p2; coefs->m[3][0] = p4; inverse = make_bezier(); } matrix_mult(inverse, coefs); free_matrix(inverse); return coefs; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix *temp; temp = new_matrix(4,1); //Bezier Curve co if(type == 1){ temp->m[0][0] = p1; temp->m[1][0] = p2; temp->m[2][0] = p3; temp->m[3][0] = p4; struct matrix *newBez; newBez = make_bezier(); matrix_mult(newBez,temp); } if(type == 0){ temp->m[0][0] = p1; temp->m[1][0] = p3; temp->m[2][0] = p2-p1; temp->m[3][0] = p4-p3; struct matrix *newHerm; newHerm = make_hermite(); matrix_mult(newHerm,temp); } return temp; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * inverse; struct matrix * coefs; if ( type == BEZIER_MODE ) inverse = make_bezier(); else inverse = make_hermite(); coefs = new_matrix(4, 1); if ( type == BEZIER_MODE ) { coefs->m[0][0] = p1; coefs->m[1][0] = p2; coefs->m[2][0] = p3; coefs->m[3][0] = p4; } else { coefs->m[0][0] = p1; coefs->m[1][0] = p3; coefs->m[2][0] = p2 - p1; coefs->m[3][0] = p4 - p3; } matrix_mult(inverse, coefs); free_matrix(inverse); return coefs; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * bh;; struct matrix * given = new_matrix(4, 1); given->lastcol = 1; if (type == 0){ bh = make_bezier(); given->m[0][0] = p1; given->m[1][0] = p2; given->m[2][0] = p3; given->m[3][0] = p4; } else{ bh = make_hermite(); given->m[0][0] = p1; given->m[1][0] = p3; given->m[2][0] = p1 - p2; given->m[3][0] = p3 - p4; } matrix_mult(bh, given); free_matrix(bh); return given; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * coeffs = new_matrix(4, 1); //Hermite Curve if (type == 0) { struct matrix *h = make_hermite(); coeffs->m[0][0] = p1; coeffs->m[1][0] = p3; coeffs->m[2][0] = p2-p1; coeffs->m[3][0] = p4-p3; matrix_mult(h, coeffs); free_matrix(h); } //Bezier Curve if (type == 1) { struct matrix *b = make_bezier(); coeffs->m[0][0] = p1; coeffs->m[1][0] = p2; coeffs->m[2][0] = p3; coeffs->m[3][0] = p4; matrix_mult(b, coeffs); free_matrix(b); } return coeffs; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * m = new_matrix(4, 1); m->m[0][0] = p1; m->m[1][0] = p2; m->m[2][0] = p3; m->m[3][0] = p4; if (type == HERMITE_MODE) { matrix_mult(make_hermite(),m); } else { matrix_mult(make_bezier(),m); } return m; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix* coefs = new_matrix(4, 1); coefs -> m[0][0] = p1; coefs -> m[1][0] = p2; coefs -> m[2][0] = p3; coefs -> m[3][0] = p4; if (type == HERMITE_MODE) matrix_mult(make_hermite(), coefs); else matrix_mult(make_bezier(), coefs); return coefs; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( /*Hermite: p0 Bezier:p0*/ double p1, /*Hermite: p1 Bezier: p1*/ double p2, /*Hermite: r1 Bezier: p2*/ double p3, /*Hermite: r2 Bezier: p3*/ double p4, int type) { struct matrix *curve_coefs = new_matrix(4,1); curve_coefs->m[0][0] = p1; curve_coefs->m[1][0] = p2; curve_coefs->m[2][0] = p3; curve_coefs->m[3][0] = p4; if(type == HERMITE_MODE) matrix_mult(make_hermite(),curve_coefs); if(type == BEZIER_MODE) matrix_mult(make_bezier(),curve_coefs); return curve_coefs; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * g = new_matrix(4, 1); g->m[0][0] = p1; g->m[1][0] = p2; g->m[2][0] = p3; g->m[3][0] = p4; struct matrix *c; if (type == HERMITE_MODE) { c = make_hermite(); } if (type == BEZIER_MODE) { c = make_bezier(); } matrix_mult(c, g); return g; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * m = new_matrix(1, 4); struct matrix * hermite = make_hermite(); struct matrix * bezier = make_bezier(); m->m[0][0] = p1; m->m[0][0] = p2; m->m[0][0] = p3; m->m[0][0] = p4; if (type == 0) { //Hermite matrix_mult( hermite, m ); } else { //Bezier matrix_mult( bezier, m ); } return m; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * m = new_matrix(4, 4); if (type){ m->m[0][0]=p1; m->m[1][0]=p2; m->m[2][0]=p3; m->m[3][0]=p4; matrix_mult(make_bezier(),m); } else{ m->m[0][0]=p1; m->m[1][0]=p3; m->m[2][0]=p2-p1; m->m[3][0]=p4-p3; matrix_mult(make_hermite(),m); } m->lastcol=1; return m; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * m = new_matrix(1,4); if(HERMITE_MODE == type) { m->m[0][0] = p1; m->m[0][1] = p3; m->m[0][2] = (p2 - p1); m->m[0][3] = (p4 - p3); matrix_mult(make_hermite(), m); } else{ m->m[0][0] = p1; m->m[0][1] = p2; m->m[0][2] = p3; m->m[0][3] = p4; matrix_mult(make_bezier(), m); } return m; }
struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix *m; struct matrix *a = new_matrix(4,1); a->lastcol = 1; if(type==0){//hermite m = make_hermite(); a->m[0][0] = p1;//p0 a->m[1][0] = p3;//p1 a->m[2][0] = p2;//r0 a->m[3][0] = p4;//r1 }else{//bezier m = make_bezier(); a->m[0][0] = p1; a->m[1][0] = p2; a->m[2][0] = p3; a->m[3][0] = p4; } matrix_mult(m,a); return a; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * k = new_matrix(4,4); struct matrix * m = new_matrix(4, 1); if(type == 0){ //hermite m->m[0][0] = p1; m->m[1][0] = p2; m->m[2][0] = p3 - p1; m->m[3][0] = p4 - p2; k = make_hermite(); } else if(type == 1){ //bezier m->m[0][0] = p1; m->m[1][0] = p3; m->m[2][0] = p2; m->m[3][0] = p4; k = make_bezier(); } matrix_mult(k, m); free_matrix(k); return m; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * m = new_matrix(4,4); ident(m); struct matrix * points = new_matrix(4,1); if (type == 0 ){ points->m[0][0] = p1; points->m[1][0] = p2; points->m[2][0] = p2-p1; points->m[3][0] = p4-p3; matrix_mult(make_hermite(), points); } if (type == 1 ){ points->m[0][0] = p1; points->m[1][0] = p2; points->m[2][0] = p3; points->m[3][0] = p4; matrix_mult(make_bezier(), points); } return m; }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * inverse = new_matrix(4, 4); struct matrix * m = new_matrix(4, 1); m -> m[0][0] = p1; m -> m[1][0] = p4; m -> m[2][0] = (p2 - p1); m -> m[3][0] = (p4 - p3); if (type == 0) { inverse = make_hermite(); matrix_mult(inverse, m); return m; } else { inverse = make_bezier(); matrix_mult(inverse, m); return m; } }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix *B= new_matrix(4,1); B->m[0][0]=p1; B->m[0][1]=p2; B->m[0][2]=p3; B->m[0][3]=p4; struct matrix *A; if (type){//zero means hermite,1 is bezier A =make_bezier(); } else{ A = make_hermite(); } matrix_mult(A,B); return B; //now Matrtix B is in the form /* [a] [b] [c] [d] */ }
/*======== struct matrix * generate_curve_coefs() ========== Inputs: double p1 double p2 double p3 double p4 int type Returns: A matrix containing the values for a, b, c and d of the equation at^3 + bt^2 + ct + d for the curve defined by p1, p2, p3 and p4. Type determines whether the curve is bezier or hermite 03/16/12 14:42:46 jdyrlandweaver ====================*/ struct matrix * generate_curve_coefs( double p1, double p2, double p3, double p4, int type) { struct matrix * coef = new_matrix(4,1); coef->m[0][0] = p1; coef->m[1][0] = p2; coef->m[2][0] = p3; coef->m[3][0] = p4; if(type == HERMITE_MODE){ struct matrix * herm = make_hermite(); matrix_mult(herm, coef); free_matrix(herm); return coef; } else if(type == BEZIER_MODE){ struct matrix * bez = make_bezier(); matrix_mult(bez, coef); free_matrix(bez); return coef; } else{ return NULL; } }