曲线平滑-B样条曲线

3D空间曲线三次B样条平滑示例:

struct D_DOT3D //D_DOT3D示例,未完全实现  
{  
    double x,y,z;  
} 

double GetThreeBSplineValue(double p0, double p1, double p2, double p3, double t)
{
	double A0 = (p0 + 4*p1 + p2) / 6;
	double A1 = - (p0 - p2)/2;
	double A2 = (p0 - 2*p1 + p2) / 2;
	double A3 = - (p0 - 3*p1 + 3*p2 - p3)/6;
	return A0 + A1 * t + A2 * t*t + A3 * t*t*t;
}

D_DOT3D GetThreeBSplineValue(D_DOT3D p0, D_DOT3D p1, D_DOT3D p2, D_DOT3D p3 , double t)
{
	D_DOT3D dot;
	dot.x = GetThreeBSplineValue(p0.x, p1.x, p2.x, p3.x, t);
	dot.y = GetThreeBSplineValue(p0.y, p1.y, p2.y, p3.y, t);
	dot.z = GetThreeBSplineValue(p0.z, p1.z, p2.z, p3.z, t);

	return dot;
}

long ThreeBSplineCurve( vector<D_DOT3D> &line )
{
	if (line.size()<4)
		return 0;

	vector<D_DOT3D> vout;
	for (int i=0; i<line.size()-3; ++i)
	{
		D_DOT3D p0(line[i]);
		D_DOT3D p1(line[i+1]);
		D_DOT3D p2(line[i+2]);
		D_DOT3D p3(line[i+3]);
		if(0 == i)
		{
			D_DOT3D dot1 = GetThreeBSplineValue(p0, p1, p2, p3, 0.0);
			vout.push_back(dot1);
		}

		D_DOT3D dot2 = GetThreeBSplineValue(p0, p1, p2, p3, 1/3.0);
		D_DOT3D dot3 = GetThreeBSplineValue(p0, p1, p2, p3, 2/3.0);
		D_DOT3D dot4 = GetThreeBSplineValue(p0, p1, p2, p3, 1.0);

		vout.push_back(dot2);
		vout.push_back(dot3);
		vout.push_back(dot4);
	}

	line = vout;

	return 1;
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BleuRever/article/details/52386598
个人分类: 计算机图形学
想对作者说点什么? 我来说一句

B-spline曲线详解

2012年03月09日 159KB 下载

没有更多推荐了,返回首页

不良信息举报

曲线平滑-B样条曲线

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭