Point_2D Bspline::cc(float u){ std::list<Point_2D>::iterator it = ctrlPointsNDC.begin(); float leftRatio, rightRatio; int I; //build a table Point_2D lb[numberOfCtrlPoints][numberOfCtrlPoints], c_t; for(int c = 0; c < numberOfCtrlPoints; c++, it++){ lb[0][c] = (*it); } //init the 0th generation(j=0) control points //determine which segment I does the u lies in for(int i = 0 ; i < k+numberOfCtrlPoints; i++){ if( u < knotValues[i]){ I = i-1; break; } } //DPRINT("I: %d\n",I); for(int j = 1 ; j <= k-1; j++){ //starting from the first generation for(int i = (I - (k-1)) ; i <= I-j; i++){ rightRatio = (knotValues[i+k] - u) / (knotValues[i+k] - knotValues[i+j]) ; leftRatio = (u - knotValues[i+j]) / (knotValues[i+k] - knotValues[i+j]) ; lb[j][i] = add( multByScalar( lb[j-1][i], rightRatio ) , multByScalar( lb[j-1][i+1], leftRatio ) ); } } c_t.x = lb[k-1][I-(k-1)].x * (graph->window_width - 1); c_t.y = lb[k-1][I-(k-1)].y * (graph->window_height -1); return c_t; }
void applyingRightHouseHolder(Vector* w, Vector** A_n, int nlins){ int i, j; Vector *aux; float lambda, wt_a_2; lambda = dotProduct(w,w); aux = createVector(A_n[0]->len); for(i = 0; i < nlins; i++){ cpyVectors(w, aux); /* wt_a_2 = dotProduct(w, A_n[i]) * 2;*/ wt_a_2 = 0; for(j = 0; j < A_n[0]->len; j++){ wt_a_2 += w->data[j]*A_n[j]->data[i]; } wt_a_2 *= 2; /***/ if(lambda != 0.0) multByScalar((wt_a_2 / lambda), aux); /*subVectors(A_n[i], aux, A_n[i]);*/ for(j = 0; j < A_n[0]->len; j++){ A_n[j]->data[i] -= aux->data[j]; } /***/ } free(aux); }
Vector normalize(Vector v){ float l = length(v); if(l > 1){ float inverse = 1 / l; Vector norm; norm = multByScalar(v, inverse); return norm; } return v; }
void applyingLeftHouseHolder(Vector* w, Vector** A_n, int ncols){ int j; Vector *aux; float lambda, wt_a_2; lambda = dotProduct(w,w); aux = createVector(A_n[0]->len); for(j = 0; j < ncols; j++){ cpyVectors(w, aux); wt_a_2 = dotProduct(w, A_n[j]) * 2; if(lambda != 0.0) multByScalar((wt_a_2 / lambda), aux); subVectors(A_n[j], aux, A_n[j]); } free(aux); }