付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Douglas-Peucker 算法 曲线离散化 在数字化过程中, 需要对曲线进行采样简化, 即在曲线上取有限个点, 将其变为 折线,并且能够在一定程度上保持原有的形状。 经典的 Douglas-Peucker 算法描 述如下:(1) 在曲线首尾两点A, B之间连接一条直线AB该直线为曲线的弦;(2) 得到曲线上离该直线段距离最大的点C,计算其与AB的距离d;( 3)比较该距离与预先给定的阈值 threshold 的大小,如果小于 threshold , 则该直线段作为曲线的近似,该段曲线处理完毕。(4)如果距离大于阈值,则用 C将曲线分为两段AC和 BC并分别对两段取信 进行 13 的处理。
2、( 5)当所有曲线都处理完毕时,依次连接各个分割点形成的折线,即可以作为 曲线的近似。/*sample.cpp*/#include #include #include DouglasPeucker.h using namespace std;void readin(vector &Points,const char * filename) MyPointStruct SinglePoint;FILE *fp = fopen(filename,r); while(fscanf(fp,%lf%lf,&SinglePoint.X,&SinglePoint.Y)!=EOF) Points.push_b
3、ack(SinglePoint);void DouglasPeuckerAlgorithm(vector &Points,int tolerance,const char*filename)DouglasPeucker Instance(Points,tolerance); Instance.WriteData(filename);void DumpOut1()printf(done!n);void DumpOut2()printf(need 3 command line parameter:n0executable file name;n1file name of the input dat
4、a;n2file name of the output data;n3threshold.n);int main(int argc, const char *argv)if(argc=4)vector Points; readin(Points,argv1);int threshold = atoi(argv3); DouglasPeuckerAlgorithm(Points,threshold,argv2); DumpOut1();elseDumpOut2();return 0;/ / /*DouglasPeucker.h*/#ifndef DOUGLAGPEUCKER#include #i
5、nclude using namespace std;struct MyPointStruct /点的结构public:double X;double Y;double Z;MyPointStruct()this-X = 0;this-Y = 0;this-Z = 0;MyPointStruct(double x, double y, double z) /点的构造函数this-X = x;this-Y = y;this-Z = z;MyPointStruct();class DouglasPeuckerpublic: vector PointStruct;vector myTag; / 标记
6、特征点的一个 bool 数组 vector PointNum;/ 离散化得到的点号 DouglasPeucker(void);DouglasPeucker(vector &Points,int tolerance); DouglasPeucker();void WriteData(const char *filename);private:void DouglasPeuckerReduction(int firstPoint, int lastPoint, double tolerance);double PerpendicularDistance(MyPointStruct &point1,
7、 MyPointStruct &point2, MyPointStruct &point3);MyPointStruct myConvert(int index);#define DOUGLAGPEUCKER#endif / / /*DouglasPeucker.cpp*/ #include DouglasPeucker.hdouble DouglasPeucker:PerpendicularDistance(MyPointStruct &point1,MyPointStruct &point2, MyPointStruct &point3)/ 点到直线的距离公式法double A, B, C
8、, 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 PointStructindex;void DouglasPeucker:DouglasPeucke
9、rReduction(int firstPoint, intlastPoint, double tolerance)double maxDistance = 0;int indexFarthest = 0; /记录最大值时点元素在数组中的下标for (int index = firstPoint; index maxDistance)maxDistance = distance;indexFarthest = index;if (maxDistance tolerance & indexFarthest != 0)myTagindexFarthest = true; /记录特征点的索引信息Do
10、uglasPeuckerReduction(firstPoint, indexFarthest, tolerance);DouglasPeuckerReduction(indexFarthest, lastPoint, tolerance);DouglasPeucker:DouglasPeucker(vector &Points,int tolerance)PointStruct = Points;int totalPointNum =Points.size();myTag.resize(totalPointNum,0);DouglasPeuckerReduction(0, totalPoin
11、tNum-1, tolerance);for (int index = 0; indextotalPointNum; index+) if(myTagindex)PointNum.push_back(index);void DouglasPeucker:WriteData(const char *filename)FILE *fp = fopen(filename,w);int pSize = PointNum.size();for(int index=0;indexpSize;index+) fprintf(fp,%lft%lfn,PointStructPointNumindex.X,PointStru ctPointNumindex.Y);/ /仅供个人用于学习、研究;不得用于商业用途。For personal use only in study and research; not for commercial use.Nur f u r den pers?nlichen f u r Studien, Forschung, zu kommerziellen Zwecken verwendet werden.Pour l e tude et la recherc
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年商丘工学院单招职业技能考试备考题库含详细答案解析
- 2026年黑龙江幼儿师范高等专科学校高职单招职业适应性测试备考题库及答案详细解析
- 2026年南宁学院高职单招职业适应性测试备考题库及答案详细解析
- 素人种草平台在美妆行业的价值与传声港服务模式白皮书
- 2026年北京北大方正软件职业技术学院高职单招职业适应性测试备考题库及答案详细解析
- 2026年郑州黄河护理职业学院单招综合素质考试模拟试题含详细答案解析
- 2026浙江绍兴市诸暨市人民医院招聘考试重点题库及答案解析
- 2026届河北省枣强中学高三上学期1月月考历史试题(含答案及解析)
- 2026年甘肃省庆阳市市本级新开发城镇公益性岗位50个参考考试题库及答案解析
- 2026年湖南民族职业学院单招职业技能考试参考题库含详细答案解析
- 医院消防安全宣传教育
- 新高考数学之圆锥曲线综合讲义第26讲外接圆问题(原卷版+解析)
- 亚马逊全球开店:2024亚马逊日本机会品类动向调查报告-床上用品
- 中药汤剂煎煮技术规范-公示稿
- 水岸·琉璃园-山东淄博留仙湖公园景观设计
- 新版出口报关单模板
- 微型课题研究的过程与方法课件
- 药学导论绪论-课件
- 14K118 空调通风管道的加固
- 加油站财务管理制度细则
- 真倚天屠龙记剧情任务详细攻略武功冲穴步骤
评论
0/150
提交评论