privatevoid根据边界生成三角网考虑凹边界button1_Click(objectsender,EventArgse){float[]result=null;objectreturnObj,pickPoint;stringpickPrompt=选取(多段线对象)!;AcadDoc.Utility.GetEntity(outreturnObj,outpickPoint,pickPrompt);AcadObjectreturnCADObj=(AcadObject)returnObj;if(returnCADObj.ObjectName==AcDb2dPolyline){AcadPolylinetempLine=(AcadPolyline)returnCADObj;double[]result2=(double[])tempLine.Coordinates;intcount=result2.Length/3;inttempI,tempJ;result=newfloat[2*count];for(inti=0;icount;i++){tempI=2*i;tempJ=tempI+i;result[tempI]=(float)result2[tempJ];result[tempI+1]=(float)result2[tempJ+1];}}elseif(returnCADObj.ObjectName==AcDbPolyline){AcadLWPolylinetempLine=(AcadLWPolyline)returnCADObj;double[]result2=(double[])tempLine.Coordinates;intcount=result2.Length;result=newfloat[count];for(inti=0;icount;i++){result[i]=(float)result2[i];}}if(result!=null){inttag01=1,num01=0,num02=0,tempTag;float[]point1,point2,point3;intcount=result.Length/2;inti,tempI;for(i=0;icount-2;i++){tempI=2*i;point1=newfloat[2];point2=newfloat[2];point3=newfloat[2];point1[0]=result[tempI];point1[1]=result[tempI+1];point2[0]=result[tempI+2];point2[1]=result[tempI+3];point3[0]=result[tempI+4];point3[1]=result[tempI+5];tempTag=JudgeTwoVector(point1,point2,point3);if(tempTag==1)num01++;elseif(tempTag==-1)num02++;}if(num01num02)tag01=-1;Tri[]tris=BuildTIN(result);inttotalIndex=count;intcount2=tris.Length;System.Collections.ArrayListdelTriArray=newSystem.Collections.ArrayList();for(i=0;icount2;i++){point1=newfloat[2];point2=newfloat[2];point3=newfloat[2];tempI=2*tris[i].NodeA;point1[0]=result[tempI];point1[1]=result[tempI+1];tempI=2*tris[i].NodeB;point2[0]=result[tempI];point2[1]=result[tempI+1];tempI=2*tris[i].NodeC;point3[0]=result[tempI];point3[1]=result[tempI+1];if(JudgeDelTri2(point1,point2,point3,result,tag01)){delTriArray.Add(i);}}for(i=0;icount2;i++){if(delTriArray.Contains(i))continue;double[]p1=newdouble[3],p2=newdouble[3],p3=newdouble[3];p1[0]=(double)result[2*tris[i].NodeA];p1[1]=(double)result[2*tris[i].NodeA+1];p1[2]=0;p2[0]=(double)result[2*tris[i].NodeB];p2[1]=(double)result[2*tris[i].NodeB+1];p2[2]=0;p3[0]=(double)result[2*tris[i].NodeC];p3[1]=(double)result[2*tris[i].NodeC+1];p3[2]=0;AcadDoc.ModelSpace.Add3DFace(p1,p2,p3,p1);AcadDoc.Application.Update();}}///summary///判断两个向量的叉乘方向,向量point1-point2与向量point3-point2////summary///paramname=point1/param///paramname=point2/param///paramname=point3/param///returns/returnsprivateintJudgeTwoVector(float[]point1,float[]point2,float[]point3){intresult=1;float[]vector01=newfloat[2],vector02=newfloat[2];vector01[0]=point1[0]-point2[0];vector01[1]=point1[1]-point2[1];vector02[0]=point3[0]-point2[0];vector02[1]=point3[1]-point2[1];floattempValue=vector02[1]*vector01[0]-vector01[1]*vector02[0];if(tempValue0)result=-1;elseif(tempValue==0)result=0;returnresult;}publicclassEdge{publicintStart;//边的起点publicintEnd;//边的终点publicintLeftTri=-1;//左边三角形索引publicintRightTri=-1;//右边三角形索引}publicclassTri{publicintNodeA;//第一个节点的索引publicintNodeB;//第二个节点的索引publicintNodeC;//第三个节点的索引publicintAdjTriA=-1;//第一个邻接三角形索引publicintAdjTriB=-1;//第二个邻接三角形索引publicintAdjTriC=-1;//第三个邻接三角形索引}privateTri[]BuildTIN(float[]pointsCoord){System.Collections.ArrayListarrayEdges=newSystem.Collections.ArrayList();System.Collections.ArrayListarrayTris=newSystem.Collections.ArrayList();//获取点集外围边界inti,startIndex=0,tempIndex,lastIndex;intpointCount=pointsCoord.Length/2;for(i=1;ipointCount;i++)//寻找X值最小的点号{if(pointsCoord[2*i]pointsCoord[2*startIndex]){startIndex=i;}}Edgeedge=newEdge();edge.Start=startIndex;lastIndex=startIndex-1;tempIndex=startIndex;float[]vector1=newfloat[2],vector2=newfloat[2];vector1[0]=0;vector1[1]=100;floatvector1Length,vector2Length,angleTemp,angleMax,lengthMin;angleMax=0;while(lastIndex!=startIndex){vector1Length=(float)Math.Sqrt(vector1[0]*vector1[0]+vector1[1]*vector1[1]);lengthMin=300;for(i=0;ipointCount;i++)//找边界{if(i!=edge.Start){vector2[0]=pointsCoord[2*i]-pointsCoord[2*tempIndex];vector2[1]=pointsCoord[2*i+1]-pointsCoord[2*tempIndex+1];vector2Length=(float)Math.Sqrt(vector2[0]*vector2[0]+vector2[1]*vector2[1]);angleTemp=(float)Math.Acos((vector1[0]*vector2[0]+vector1[1]*vector2[1])/(vector1Length*vector2Length));if(angleTempangleMax){angleMax=angleTemp;edge.End=i;lengthMin=vector2Length;}elseif(angleTemp==angleMax&&vector2LengthlengthMin){edge.End=i;lengthMin=vector2Length;}}}arrayEdges.Add(edge);lastIndex=edge.End;edge=newEdge();edge.Start=lastIndex;angleMax=0;vector1[0]=pointsCoord[2*tempIndex]-pointsCoord[2*lastIndex];vector1[1]=pointsCoord[2*tempIndex+1]-pointsCoord[2*lastIndex+1];tempIndex=lastIndex;}//生成TINintnewIndex,edgeCount=arrayEdges.Count;floatangleV1V2Temp,angleV2V3Temp,angleV1V2Max,angleV2V3Max,vector3Length;float[]vector3=newfloat[2];boolisTriExist;for(i=0;iarrayEdges.Count;i++){edge=newEdge();edge=(Edge)arrayEdges[i];//取出一条边//判断三角形是否存在(若本边的左三角已存在,则计算右三角)?if(edge.LeftTri==-1){newIndex=-1;//新选取点的索引angleV1V2Max=0;angleV2V3Max=0;vector1[0]=pointsCoord[2*edge.End]-pointsCoord[2*edge.Start];vecto