三角网的生成算法#ifndef TIN_H #define TIN_H #include #include #include #include #include"WGraphics.h" using namespace std; typedef struct mo intmark; }mo; typedef struct }Point;typedef struct sample//文件读入的采样点结构 Pointpoint; int Mark; int Number;//采样点编号 }Sample; class TIN public:void GetData(); void Display(int scale); inlinedouble Distance(Point p1,Point p2)//计算两点之间的距离 inlinedouble ComputeAngle(Point p1,Point p2,Point p3)//计算角C doublea=Distance(p2,p3); double b=Distance(p3,p1); double c=Distance(p1,p2); return inlineint F(Point p1,Point p2,Point p3)//计算点在直线的区间 return-1; else return intSearch(int p1,int p2,int p3); //检查三角形是否重复或交* intExtend(int p1,int p2,int p3);//以p1,p2 位基边扩展三角形 voidTerminal(int key); protected:vector t1; vector t2; vector t3; int dot;int #endifint TIN::Search(int p1,int p2,int p3) //检查三角形是否重复或交* moField[7]; Field[1].m=p1; Field[1].n=p2; Field[1].mark=0; Field[2].m=p2; Field[2].n=p1; Field[2].mark=0; Field[3].m=p1; Field[3].n=p3; Field[3].mark=0; Field[4].m=p3; Field[4].n=p1; Field[4].mark=0; Field[5].m=p2; Field[5].n=p3; Field[5].mark=0; Field[6].m=p3; Field[6].n=p2; Field[6].mark=0; for(int if(Field[i].mark==2)return true; return false;//三角形没有重复 intTIN::Extend(int p1,int p2,int p3)//以p1,p2 为基线生成三角形 intm=F(dot[p1].point,dot[p2].point,dot[p3].point); double Angle1=0; double Angle2=0; int sign=0; for(int dot[i].Mark=F(dot[p1].point,dot[p2].point,dot[i].point);if(dot[i].Mark+m==0 Angle2=ComputeAngle(dot[p1].point,dot[p2].point,dot[i].point);if(Angle2>Angle1) Angle1=Angle2;sign=i; t1.push_back(p1);t2.push_back(p2); t3.push_back(sign); return sign;//新生成三角形找到了 elsereturn voidTIN::Terminal(int key) t1.push_back(0);t2.push_back(0); t3.push_back(0); int doubledis1=999999999; double dis2; double angle1=0; double angle2=0; int if(key!=i){dis2=Distance(dot[key].point,dot[i].point); if(dis2angle1) t3.push_back(m);//********************************第一个种子三角形生成 while(K!=L) a=Extend(t1[K],t2[K],t3[K]);b=Extend(t2[K],t3[K],t1[K]); c=Extend(t3[K],t1[K],t2[K]); voidTIN::GetData() ifstreamin_stream; in_stream.open("data2.txt"); if(in_stream==NULL) exit(0); in_stream>>N; dot=new Sample[N+1]; for(int in_stream>>dot[i].Number>>dot[i].point.x>>dot[i].point.y;in_stream.close(); voidTIN::Display(int scale) //cout