⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bezier3d.cpp

📁 This is a simple code sample to interpolate a 3d set of points using the bezier algorithm minimized
💻 CPP
字号:
#include "Bezier3d.h"

void bezier3d::Interpolate(Vec3d *list, int size, int iterations)
{
	int pos_0, pos_1, pos_2, pos_3;
	vector3d p_0, p_1, p_2, p_3, d_0, d_1, d_2;

	if(size>4)
	{
		for(int i=0; i<iterations; i++)
		{

			for(int j=0; j<size-3; j++)
			{
				if(j==size-3)
				{
					pos_0 = j;
					pos_1 = j+1;
					pos_2 = j+2;
					pos_3 = 0;
				}
				else if(j==size-2)
				{
					pos_0 = j;
					pos_1 = j+1;
					pos_2 = 0;
					pos_3 = 1;
				}
				else if(j==size-1)
				{
					pos_0 = j;
					pos_1 = 0;
					pos_2 = 1;
					pos_3 = 2;
				}
				else
				{
					pos_0 = j;
					pos_1 = j+1;
					pos_2 = j+2;
					pos_3 = j+3;
				}

				p_0.set(list[pos_0].x,list[pos_0].y,list[pos_0].z);
				p_1.set(list[pos_1].x,list[pos_1].y,list[pos_1].z);
				p_2.set(list[pos_2].x,list[pos_2].y,list[pos_2].z);
				p_3.set(list[pos_3].x,list[pos_3].y,list[pos_3].z);

				forwdiff(4,p_0,p_1,p_2,p_3,d_0,d_1,d_2);

				list[pos_1].x = list[pos_0].x + d_0.x;
				list[pos_1].y = list[pos_0].y + d_0.y;
				list[pos_1].z = list[pos_0].z + d_0.z;

				d_0.x += d_1.x;
				d_0.y += d_1.y;
				d_0.z += d_1.z;

				d_1.x += d_2.x;
				d_1.y += d_2.y;
				d_1.z += d_2.z;

				list[pos_2].x = list[pos_1].x + d_0.x;
				list[pos_2].y = list[pos_1].y + d_0.y;
				list[pos_2].z = list[pos_1].z + d_0.z;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -