下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Douglas-Peucker 算法 曲線離散化 在數(shù)字化過(guò)程中, 需要對(duì)曲線進(jìn)行采樣簡(jiǎn)化, 即在曲線上取有限個(gè)點(diǎn), 將其變?yōu)?折線,并且能夠在一定程度上保持原有的形狀。 經(jīng)典的 Douglas-Peucker 算法描 述如下:(1) 在曲線首尾兩點(diǎn)A, B之間連接一條直線AB該直線為曲線的弦;(2) 得到曲線上離該直線段距離最大的點(diǎn)C,計(jì)算其與AB的距離d;( 3)比較該距離與預(yù)先給定的閾值 threshold 的大小,如果小于 threshold , 則該直線段作為曲線的近似,該段曲線處理完畢。(4)如果距離大于閾值,則用 C將曲線分為兩段AC和 BC并分別對(duì)兩段取信 進(jìn)行 13 的處理。
2、( 5)當(dāng)所有曲線都處理完畢時(shí),依次連接各個(gè)分割點(diǎn)形成的折線,即可以作為 曲線的近似。/*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 /點(diǎn)的結(jié)構(gòu)public:double X;double Y;double Z;MyPointStruct()this-X = 0;this-Y = 0;this-Z = 0;MyPointStruct(double x, double y, double z) /點(diǎn)的構(gòu)造函數(shù)this-X = x;this-Y = y;this-Z = z;MyPointStruct();class DouglasPeuckerpublic: vector PointStruct;vector myTag; / 標(biāo)記
6、特征點(diǎn)的一個(gè) bool 數(shù)組 vector PointNum;/ 離散化得到的點(diǎn)號(hào) 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)/ 點(diǎn)到直線的距離公式法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; /記錄最大值時(shí)點(diǎn)元素在數(shù)組中的下標(biāo)for (int index = firstPoint; index maxDistance)maxDistance = distance;indexFarthest = index;if (maxDistance tolerance & indexFarthest != 0)myTagindexFarthest = true; /記錄特征點(diǎn)的索引信息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);/ /僅供個(gè)人用于學(xué)習(xí)、研究;不得用于商業(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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度醫(yī)院醫(yī)技人員技能提升合同4篇
- 打雜工合同范本(2篇)
- 二零二五年度農(nóng)村土地整治項(xiàng)目承包合同書4篇
- 二零二五年度充電樁充電服務(wù)補(bǔ)貼資金管理合同3篇
- 二零二五版高端鎳氫電池產(chǎn)品定制研發(fā)合同范本4篇
- 二零二五年度農(nóng)場(chǎng)租賃合同農(nóng)業(yè)生態(tài)修復(fù)與保護(hù)協(xié)議4篇
- 2025年度房地產(chǎn)租賃合同房屋質(zhì)量及維修責(zé)任約定4篇
- 2025年互聯(lián)網(wǎng)+內(nèi)資股東股權(quán)投資合同
- 二零二五版智能門禁系統(tǒng)與電梯聯(lián)動(dòng)工程合同3篇
- 2025年度互聯(lián)網(wǎng)企業(yè)程序員聘用合同模板
- 2024年中考語(yǔ)文滿分作文6篇(含題目)
- 第一節(jié)-貨幣資金資料講解
- 如何提高售后服務(wù)的快速響應(yīng)能力
- 北師大版 2024-2025學(xué)年四年級(jí)數(shù)學(xué)上冊(cè)典型例題系列第三單元:行程問(wèn)題“拓展型”專項(xiàng)練習(xí)(原卷版+解析)
- 2023年譯林版英語(yǔ)五年級(jí)下冊(cè)Units-1-2單元測(cè)試卷-含答案
- Unit-3-Reading-and-thinking課文詳解課件-高中英語(yǔ)人教版必修第二冊(cè)
- 施工管理中的文檔管理方法與要求
- DL∕T 547-2020 電力系統(tǒng)光纖通信運(yùn)行管理規(guī)程
- 種子輪投資協(xié)議
- 執(zhí)行依據(jù)主文范文(通用4篇)
- 浙教版七年級(jí)數(shù)學(xué)下冊(cè)全冊(cè)課件
評(píng)論
0/150
提交評(píng)論