c語言同名標(biāo)靶點自動匹配算法實現(xiàn)實例代碼
更新時間:2018年02月03日 08:45:07 作者:微book
這篇文章主要介紹了c語言同名標(biāo)靶點自動匹配算法實現(xiàn)實例代碼,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
1.兩個標(biāo)靶數(shù)據(jù)
2.匹配結(jié)果
3.代碼
#include <iostream> #include <vector> #include <math.h> using namespace std; struct Point { int id; float x,y,z; Point(int _id,float _x,float _y,float _z):id(_id),x(_x),y(_y),z(_z){} }; struct Triangle { Point p1,p2,p3; }; class PointCloud { public: bool readFile(char *filename); //void PointMatch(const PointCloud& pc1,const PointCloud &pc2); vector<Point> pData; int r,g,b; }; bool PointCloud::readFile(char *filename) { if(filename==NULL)return false; FILE *fp=fopen(filename,"r"); if (!fp) { printf("Load file %s failed\n", filename); return false; } char buffer[100]; int count=0; while(!feof(fp)) { fgets(buffer, 300, fp); float x,y,z; sscanf_s(buffer,"%f%f%f",&x,&y,&z); Point p(count++,x,y,z); pData.push_back(p); } pData.pop_back(); } float calDis(const Point &p1,const Point &p2) { return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)+(p2.z-p1.z)*(p2.z-p1.z)); } void PointMatch(const PointCloud& pc1,const PointCloud &pc2) { for (int i=0;i<pc1.pData.size()-2;++i) for(int j=i+1;j<pc1.pData.size()-1;++j) for (int k=j+1;k<pc1.pData.size();++k) { Point p1=pc1.pData[i]; Point p2=pc1.pData[j]; Point p3=pc1.pData[k]; float s12=calDis(p1,p2); float s13=calDis(p1,p3); float s23=calDis(p2,p3); for (int m=0;m<pc2.pData.size();++m) for (int n=0;n<pc2.pData.size();++n) for (int l=0;l<pc2.pData.size();++l) { if (n!=m&&m!=l&&n!=l) { Point _p1=pc2.pData[m]; Point _p2=pc2.pData[n]; Point _p3=pc2.pData[l]; float _s12=calDis(_p1,_p2); float _s13=calDis(_p1,_p3); float _s23=calDis(_p2,_p3); if (fabs(s12-_s12)<0.45&&fabs(s13-_s13)<0.45&&fabs(s23-_s23)<0.45) { cout<<"pc1....."<<p1.id<<"pc2......"<<_p1.id<<endl; cout<<"pc1....."<<p2.id<<"pc2......"<<_p2.id<<endl; cout<<"pc1....."<<p3.id<<"pc2......"<<_p3.id<<endl; } } } } } int main() { char *file1="測試點云\\點云Mark0.txt"; char *file2="測試點云\\點云Mark1.txt"; PointCloud pc1,pc2; pc1.readFile(file1); pc2.readFile(file2); PointMatch(pc1,pc2); }
總結(jié)
以上就是本文關(guān)于c語言同名標(biāo)靶點自動匹配算法實現(xiàn)實例代碼的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關(guān)文章
淺析VSCode launch.json中的各種替換變量的意思 ${workspaceFolder} ${file} $
這篇文章主要介紹了VSCode launch.json中的各種替換變量的意思 ${workspaceFolder} ${file} ${fileBasename} ${fileDirname}等,非常不錯具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03c++之解決char轉(zhuǎn)string時出現(xiàn)的亂碼問題
這篇文章主要介紹了c++之解決char轉(zhuǎn)string時出現(xiàn)的亂碼問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08淺析C/C++ 中return *this和return this的區(qū)別
return *this返回的是當(dāng)前對象的克隆或者本身,return this返回當(dāng)前對象的地址,下面通過本文給大家介紹C/C++ 中return *this和return this的區(qū)別,感興趣的朋友一起看看吧2019-10-10C語言關(guān)鍵字之a(chǎn)uto register詳解
這篇文章主要為大家介紹了C語言關(guān)鍵字之a(chǎn)uto register,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-01-01C語言數(shù)據(jù)結(jié)構(gòu)之串插入操作
這篇文章主要介紹了C語言數(shù)據(jù)結(jié)構(gòu)之串插入操作的相關(guān)資料,希望通過本文能幫助到大家,讓大家實現(xiàn)這樣的功能,需要的朋友可以參考下2017-10-10