Esempio n. 1
0
void CurveLut::update() {
	vector<float> sd = getSecondDerivative();
	int m = controlPoints.size();
	ofVec2f& first = controlPoints.front();
	ofVec2f& last = controlPoints.back();
	for(int x = 0; x < first.x; x++) {
		lut[x] = first.y;
	}
	for(int i = 0; i < m - 1; i++) {
		ofVec2f& cur = controlPoints[i];
		ofVec2f& next = controlPoints[i+1];
		for (int x = cur.x; x < next.x; x++) {
			float t = (x-cur.x) / (next.x-cur.x);
			float a = 1-t;
			float b = t;
			float h = next.x-cur.x;
			lut[x] = (a*cur.y + b*next.y + (h*h/6)*((a*a*a-a)*sd[i]+(b*b*b-b)*sd[i+1]));
		}
	}
	for(int x = last.x; x < n; x++) {
		lut[x] = last.y;
	}
	for(int x = 0; x < n; x++) {
		lut[x] = ofClamp(lut[x], 0, n - 1);
	}
	lutNew = true;
}
Esempio n. 2
0
 iSpline3D* otPolyLineSpline3::getNormal()
 {
   unsigned int count = getPointList().getCount();
   
   otPolyLineSpline3* normalSpline = new otPolyLineSpline3(count);
   otPolyLineSpline3* derivativeSpline = (otPolyLineSpline3 *)getDerivative();
   otPolyLineSpline3* secondDerivativeSpline = (otPolyLineSpline3 *)getSecondDerivative();
   
   normalSpline->setPoint(points[0].x,*(new otVector3));
   for(unsigned int i=1;i<count-1;i++)
   {
     otVector3 derivative=derivativeSpline->getPointList()[i].y;
     otVector3 secondDerivative=secondDerivativeSpline->getPointList()[i].y;
     normalSpline->setPoint(points[i].x,(secondDerivative -derivative*((derivative|secondDerivative))).normalize() );
   }
   return normalSpline;
 }
Esempio n. 3
0
 iSpline1D* otPolyLineSpline3::getCurvature()
 {
   unsigned int count = getPointList().getCount();
   
   otPolyLineSpline* curvatureSpline = new otPolyLineSpline(count);
   
   otPolyLineSpline3* secondDerivativeSpline = (otPolyLineSpline3 *)getSecondDerivative();
   otPolyLineSpline3* normalSpline = (otPolyLineSpline3 *)getNormal();
   
   curvatureSpline->setPoint(points[0].x,0);
   for(unsigned int i=1;i<count-1;i++)
   {
     otVector3 normal=normalSpline->getPointList()[i].y;
     otVector3 secondDerivative=secondDerivativeSpline->getPointList()[i].y;
     curvatureSpline->setPoint(points[i].x,(normal|secondDerivative));
   }
   return curvatureSpline;
 }