All pastes #953738 Raw Edit

Unnamed

public cpp v1 · immutable
#953738 ·published 2008-03-23 09:05 UTC
rendered paste body
double blend(int k, int t, K_NOT u, double v){  // calculate the blending value  double value;  if (t==1){    if ((u[k]<=v) && (v<u[k+1]))      value=1;    else      value=0;        }else{    if ((u[k+t-1]==u[k]) && (u[k+t]==u[k+1]))  // check for divide by zero      value = 0;    else    if (u[k+t-1]==u[k]) // if a term's denominator is zero,use just the other      value = (u[k+t] - v) / (u[k+t] - u[k+1]) * blend(k+1, t-1, u, v);    else    if (u[k+t]==u[k+1])      value = (v - u[k]) / (u[k+t-1] - u[k]) * blend(k, t-1, u, v);    else      value = (v - u[k]) / (u[k+t-1] - u[k]) * blend(k, t-1, u, v) +              (u[k+t] - v) / (u[k+t] - u[k+1]) * blend(k+1, t-1, u, v);  }  return value;}void BSpline(int quality, const T_PointVector & points, T_PointVector & line_points , const BSplineDescription & bsplinedsc ){  line_points.clear();	int size = (int)points.size();	if (size<2) return;	double t=0.0;	double step=1.0/quality;	//T_PointVector P(size);	S_Point P;		for (int p=0; p<=quality; p++, t+=step){	  P.x=0;	  P.y=0;	  if(t>=1) t=0.99999;	  		for (int j=0; j<size - 1; j++){			for (int i=0; i<size-1-j;i++){				double N = blend(i, bsplinedsc.k, bsplinedsc.U, t);				P.x=P.x + points[i].x * N;				P.y=P.y + points[i].y * N;											}		}				line_points.push_back(P);	}}