问题描述
要求输出坐标表、边表、节点表、邻接表(相邻的三角形)。现在只完成了输出坐标表,想请教各位大神,如何表示和输出后面三种表格?给点建议也可以的。(右边是四个listbox)代码如下:Form1.csusingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Collections;namespacecs3{publicpartialclassForm1:Form{privateGraphicsg=null;privatePenpen=newPen(Color.Red,1);privateBrushbrush=Brushes.Red;//设置笔刷为红色privateArrayListlist=newArrayList();//点列表privateArrayListlinelist=newArrayList();//边列表publicForm1(){InitializeComponent();}privatevoidForm1_MouseDown(objectsender,MouseEventArgse)//单击生成点{g=this.CreateGraphics();g.FillEllipse(brush,e.X,e.Y,5,5);list.Add(e.Location);listBox1.Items.Add(e.Location.X+","+e.Location.Y);//输出点坐标//listBox2.Items.Add();}publicfloatAngle(Pointcen,Pointfirst,Pointsecond)//求出三角形的顶角,cen为顶点{floatdx1,dx2,dy1,dy2;floatangle;dx1=first.X-cen.X;dy1=first.Y-cen.Y;dx2=second.X-cen.X;dy2=second.Y-cen.Y;floatc=(float)Math.Sqrt(dx1*dx1+dy1*dy1)*(float)Math.Sqrt(dx2*dx2+dy2*dy2);//判断能否组成三角形if(c==0)return-1;angle=(float)Math.Acos((dx1*dx2+dy1*dy2)/c);//求出顶点夹角returnangle;}publicdoubleDistance(Pointfirst,Pointsecond)//求两点距离{doubledis;dis=Math.Sqrt((second.Y-first.Y)*(second.Y-first.Y)+(second.X-first.X)*(second.X-first.X));returndis;}privatevoidbutton1_Click(objectsender,EventArgse)//生成三角网{doubleang;//定义角ArrayListtinline=newArrayList();//与第一点最近的点doublemindis=1000000000000;//定义最短距离doubledis;intcount=0;Linetl=newLine();for(inti=1;i<list.Count;i++)//循环所有点{dis=Distance((Point)list[0],(Point)list[i]);if(dis<mindis){mindis=dis;count=i;}}tl.Begin=(Point)list[0];tl.End=(Point)list[count];tl.ID = 1; tinline.Add(tl);for(intj=0;j<tinline.Count;j++){doubleminang=-1;//最小角boolOK;OK=false;Linetling1=newLine();Linetling2=newLine();for(inti=0;i<list.Count;i++){intyoubian;youbian=ZuoYou((Point)list[i],((Line)tinline[j]).Begin,((Line)tinline[j]).End);if(youbian==1){ang=Angle((Point)list[i],((Line)tinline[j]).Begin,((Line)tinline[j]).End);if(ang>minang){minang=ang;count=i;}OK=true;}}if(OK==true){tling1.Begin=((Line)tinline[j]).Begin;tling1.End=(Point)list[count];tinline.Add(tling1);tling2.Begin=(Point)list[count];tling2.End=((Line)tinline[j]).End;tinline.Add(tling2);for(inti=0;i<tinline.Count-1;i++){if(tling2.Begin==((Line)tinline[i]).Begin&&tling2.End==((Line)tinline[i]).End){tinline.Remove(tinline[tinline.Count-1]);}}}}for(inti=0;i<=tinline.Count-1;i++){g.DrawLine(pen,((Line)tinline[i]).Begin,((Line)tinline[i]).End);}}publicintZuoYou(Pointcen,Pointfirst,Pointsecond)//异则判断:判断点在直线左侧还是右侧{doubles;s=(first.X-cen.X)*(second.Y-cen.Y)-(first.Y-cen.Y)*(second.X-cen.X);if(s>0){return1;}elsereturn2;}}}Line.csusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Drawing;namespacecs3{classLine{publicPointBegin;publicPointEnd;publicintID;}}
解决方案
解决方案二:
如果你会delaunay算法就会很好弄,因为后三种表都是实现算法必须用到的结构或中间结果
解决方案三:
http://download.csdn.net/detail/fengdjhy/3112649引用1楼mwp的回复:
如果你会delaunay算法就会很好弄,因为后三种表都是实现算法必须用到的结构或中间结果