资源简介
在数字化过程中,需要对曲线进行采样简化,即在曲线上取有限个点,将其变为折线,并且能够在一定程度上保持原有的形状。
代码片段和文件信息
#include “DouglasPeucker.h“
double DouglasPeucker::PerpendicularDistance(MyPointStruct &point1 MyPointStruct &point2 MyPointStruct &point3)
{
// 点到直线的距离公式法
double A B C maxDist = 0;
A = point2.Y - point1.Y;
B = point1.X - point2.X;
C = point2.X * point1.Y - point1.X * point2.Y;
maxDist = fabs((A * point3.X + B * point3.Y + C) / sqrt(A * A + B * B));
return maxDist;
}
MyPointStruct DouglasPeucker::myConvert(int index)
{
return PointStruct[index];
}
void DouglasPeucker::DouglasPeuckerReduction(int firstPoint int lastPoint double tolerance)
{
double maxDistance = 0;
int indexFarthest = 0; // 记录最大值时点元素在数组中的下标
for (int index = firstPoint; index < lastPoint; index++)
{
double distance = PerpendicularDistance(myConvert(firstPoint) myConvert(lastPoint) myConvert(index));
if (distance > maxDistance)
{
maxDistance = distance;
indexFarthest = index;
}
}
if (maxDistance > tolerance && indexFarthest != 0)
{
myTag[indexFarthest] = true; // 记录特征点的索引信息
DouglasPeuckerReduction(firstPoint indexFarthest tolerance);
DouglasPeuckerReduction(indexFarthest lastPoint tolerance);
}
}
DouglasPeucker::DouglasPeucker(vector &Pointsint tolerance)
{
PointStruct = Points;
int totalPointNum =Points.size();
myTag.resize(totalPointNum0);
DouglasPeuckerReduction(0 totalPointNum-1 tolerance);
for (int index = 0; index {
if(myTag[index])PointNum.push_back(index);
}
}
void DouglasPeucker::WriteData(const char *filename)
{
FILE *fp = fopen(filename“w“);
int pSize = PointNum.size();
for(int index=0;index {
fprintf(fp“%lf\t%lf\n“PointStruct[PointNum[index]].XPointStruct[PointNum[index]].Y);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 126976 2009-03-01 16:08 Douglas_Peucker\debug\Douglas_Peucker.exe
文件 520012 2009-03-01 16:08 Douglas_Peucker\debug\Douglas_Peucker.ilk
文件 715776 2009-03-01 16:08 Douglas_Peucker\debug\Douglas_Peucker.pdb
文件 9028 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\Debug\BuildLog.htm
文件 415120 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\Debug\DouglasPeucker.obj
文件 403 2009-03-01 14:33 Douglas_Peucker\Douglas_Peucker\Debug\Douglas_Peucker.exe.em
文件 468 2009-03-01 14:33 Douglas_Peucker\Douglas_Peucker\Debug\Douglas_Peucker.exe.em
文件 385 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\Debug\Douglas_Peucker.exe.intermediate.manifest
文件 67 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\Debug\mt.dep
文件 169606 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\Debug\sample.obj
文件 216064 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\Debug\vc80.idb
文件 249856 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\Debug\vc80.pdb
文件 1819 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\DouglasPeucker.cpp
文件 982 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\DouglasPeucker.h
文件 4124 2009-03-01 15:11 Douglas_Peucker\Douglas_Peucker\Douglas_Peucker.vcproj
文件 1427 2009-03-01 16:13 Douglas_Peucker\Douglas_Peucker\Douglas_Peucker.vcproj.3C785FDEE0B54AD.luliang.user
文件 1016 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\sample.cpp
文件 1960960 2009-03-01 16:13 Douglas_Peucker\Douglas_Peucker.ncb
文件 910 2009-03-01 13:41 Douglas_Peucker\Douglas_Peucker.sln
..A..H. 10752 2009-03-01 16:13 Douglas_Peucker\Douglas_Peucker.suo
目录 0 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker\Debug
目录 0 2009-03-01 16:08 Douglas_Peucker\debug
目录 0 2009-03-01 16:08 Douglas_Peucker\Douglas_Peucker
目录 0 2009-03-01 14:09 Douglas_Peucker
----------- --------- ---------- ----- ----
4405751 24
- 上一篇:操作系统课程设计实现可变分区存储管理
- 下一篇:十六进制与字符串互转
相关资源
- M5-branes的Argyres-Douglas理论的顶点算子
- 柯布-道格拉斯Cobb-Douglas生产函数模型
- Internetworking With TCP/IP Volume 1, 6th Ed
- Numerical Analysis (7th Edition) by Richar
- PCB电流与信号完整性设计美道格拉斯
- 实验设计与分析(第6版) Douglas C.M
- 华章数学译丛图论导引(中文版.原书
- 《音频功率放大器设计手册》(第四
- 点集压缩算法douglas-peucker等
- 图论导引第二版 Douglas B. West 著,骆吉
- PCB电流与信号完整性设计美道格拉斯
- 道格拉斯曲线矢量数据压缩算法
评论
共有 条评论