1、题目:使用积累弦长法对下列曲线数据进行参数化,并对参数规格化。
11.2 52.3 38.5
14.2 51.9 36.8
17.0 51.4 35.0
19.6 50.9 33.3
22.2 50.4 31.6
24.7 49.8 29.9
27.0 49.2 28.2
29.3 48.6 26.6
31.6 48.1 25.0
33.8 47.5 23.4
2、积累弦长法
其中△Pi为两点之间的距离,即弦长,Tn为总的弦长。
代码如下:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<vector>
using namespace std;
struct point
{
float x, y, z;
};
int main()
{
point pt;
vector<point>pts;
int num = 0;
float p; //定义弦长
float Tn=0; //总的弦长
FILE *fp;
fp = fopen("1.txt", "r"); //将所有的数据点都保存在这个txt文档里
while (!feof(fp)) {
fscanf_s(fp,"%f %f %f", &pt.x, &pt.y, &pt.z);
pts.push_back(pt);
num++;
}
fclose(fp);
float* t = new float[num]; //用来保存每两点之间的弦长
float* t1 = new float[num];
t[0] = 0;
t1[0] = 0;
for (int i = 1; i < num; i++) {
p = sqrt(pow((pts[i].x - pts[i - 1].x), 2) + pow((pts[i].y - pts[i - 1].y), 2) + pow((pts[i].z - pts[i - 1].z), 2));
t[i] = t[i - 1] + p;
Tn += t[i];
}
for (int i = 1; i < num; i++) {
t1[i] = t1[i - 1] + t[i]/Tn;
}
//输出读取的数据点
for (size_t j = 0; j < num; j++) {
cout << pts[j].x << " \t" << pts[j].y << " \t" << pts[j].z << endl;
}
cout << endl;
//拟合之后
for (int i = 0; i < num; i++) {
cout << t1[i] << endl;
}
return 0;
}
运行结果:
以上。