資源簡(jiǎn)介
使用C#實(shí)現(xiàn)的delaunay三角網(wǎng)生成算法。使用說明:運(yùn)行后在窗口中單擊鼠標(biāo)添加樣采樣點(diǎn),當(dāng)采樣點(diǎn)大于等于3時(shí)自動(dòng)生成delaunay三角網(wǎng);點(diǎn)擊工具欄上的按鈕可以顯示每個(gè)三角形的外心。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
namespace?delaunay2
{
????public?partial?class?Form1?:?Form
????{
????????public?int?tPoints?=?0;
????????int?HowMany?=?0;
????????Point?point?=?new?Point();
????????Point?point1?=?new?Point();
????????Point?point2?=?new?Point();
????????Point?point3?=?new?Point();
????????Pen?p?=?new?Pen(Color.Red?2);
????????Pen?p3?=?new?Pen(Color.Yellow?2);
????????Graphics?g;
????????datatype?dt?=?new?datatype();
????????//?PainOutLine?POL?=?new?PainOutLine();
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?Form1_MouseDown(object?sender?MouseEventArgs?e)
????????{
????????????//Set?Vertex?coordinates?where?you?clicked?the?form?
????????????dt.Vertex[tPoints].x?=?e.X;
????????????dt.Vertex[tPoints].y?=?e.Y;
????????????//Perform?Triangulation?Function?if?there?are?more?than?2?points
????????????if?(tPoints?>?2)
????????????{
????????????????//?set?form‘s?color?as?white
????????????????g.Clear(Color.White);
????????????????function?fu?=?new?function();
????????????????HowMany?=?fu.Triangulate(tPoints?dt);
????????????}
????????????else
????????????{
????????????????point?=?new?Point(e.X?e.Y);
????????????????g?=?this.CreateGraphics();
????????????????g.DrawEllipse(p?e.X?e.Y?3?3);
????????????????Update();
????????????}
????????????tPoints++;
????????????Label1.Text?=?“點(diǎn)個(gè)數(shù)是?“?+?tPoints;
????????????Label2.Text?=?“三角形個(gè)數(shù)是“?+?HowMany;
????????????for?(int?i?=?1;?i?<=?HowMany;?i++)
????????????{
????????????????point1?=?new?Point(Convert.ToInt32(dt.Vertex[dt.Triangle[i].vv0].x)?Convert.ToInt32(dt.Vertex[dt.Triangle[i].vv0].y));
????????????????point2?=?new?Point(Convert.ToInt32(dt.Vertex[dt.Triangle[i].vv1].x)?Convert.ToInt32(dt.Vertex[dt.Triangle[i].vv1].y));
????????????????point3?=?new?Point(Convert.ToInt32(dt.Vertex[dt.Triangle[i].vv2].x)?Convert.ToInt32(dt.Vertex[dt.Triangle[i].vv2].y));
????????????????g.DrawLine(p?point1?point2);
????????????????g.DrawLine(p?point2?point3);
????????????????g.DrawLine(p?point1?point3);
????????????}
????????}
????????private?void?eXIT_Click(object?sender?EventArgs?e)
????????{
????????????this.Close();
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????tPoints?=?1;
????????}
????????private?void?circumcircle_Click(object?sender?EventArgs?e)
????????{
????????????barycenter?bc?=?new?barycenter();
????????????bc.CalculateBC(HowMany?dt);
????????????for?(int?i?=?1;?i?<=?HowMany;?i++)
????????????{
????????????????SolidBrush?brush1?=?new?SolidBrush(Color.Black);
????????????????g.FillEllipse(brush1?Convert.ToInt64(dt.OutHert[i].a)?Convert.ToInt64(dt.OutHert[i].b)?4?4);
????????????}
????????}
????????private?void?connect_Click(object?sender?EventArgs?e)
?
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-02-19?20:55??delaunay2\
?????目錄???????????0??2013-02-19?20:56??delaunay2\delaunay2\
?????文件?????????869??2013-02-19?20:55??delaunay2\delaunay2.sln
?????文件???????19456??2013-02-20?14:52??delaunay2\delaunay2.suo
?????目錄???????????0??2013-02-19?20:55??delaunay2\delaunay2\bin\
?????目錄???????????0??2013-02-19?22:53??delaunay2\delaunay2\bin\Debug\
?????文件???????21504??2013-02-20?19:07??delaunay2\delaunay2\bin\Debug\delaunay2.exe
?????文件???????34304??2013-02-20?19:07??delaunay2\delaunay2\bin\Debug\delaunay2.pdb
?????文件???????11600??2013-02-20?19:09??delaunay2\delaunay2\bin\Debug\delaunay2.vshost.exe
?????文件?????????490??2010-03-17?22:39??delaunay2\delaunay2\bin\Debug\delaunay2.vshost.exe.manifest
?????文件????????3677??2013-02-19?21:32??delaunay2\delaunay2\delaunay2.csproj
?????文件???????20911??2013-02-20?19:07??delaunay2\delaunay2\Form1.cs
?????文件????????6158??2013-02-20?14:42??delaunay2\delaunay2\Form1.Designer.cs
?????文件????????9876??2013-02-20?14:42??delaunay2\delaunay2\Form1.resx
?????目錄???????????0??2013-02-19?20:55??delaunay2\delaunay2\obj\
?????目錄???????????0??2013-02-19?20:55??delaunay2\delaunay2\obj\x86\
?????目錄???????????0??2013-02-20?19:07??delaunay2\delaunay2\obj\x86\Debug\
?????文件?????????637??2013-02-20?19:09??delaunay2\delaunay2\obj\x86\Debug\delaunay2.csproj.FileListAbsolute.txt
?????文件???????21504??2013-02-20?19:07??delaunay2\delaunay2\obj\x86\Debug\delaunay2.exe
?????文件????????2775??2013-02-20?14:42??delaunay2\delaunay2\obj\x86\Debug\delaunay2.Form1.resources
?????文件???????34304??2013-02-20?19:07??delaunay2\delaunay2\obj\x86\Debug\delaunay2.pdb
?????文件?????????180??2013-02-19?22:52??delaunay2\delaunay2\obj\x86\Debug\delaunay2.Properties.Resources.resources
?????文件????????4440??2013-02-20?14:15??delaunay2\delaunay2\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????6196??2013-02-20?19:07??delaunay2\delaunay2\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件?????????286??2013-02-20?14:42??delaunay2\delaunay2\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件?????????538??2013-02-20?14:42??delaunay2\delaunay2\obj\x86\Debug\GenerateResource.write.1.tlog
?????文件????????7897??2013-02-20?14:24??delaunay2\delaunay2\obj\x86\Debug\ResolveAssemblyReference.cache
?????目錄???????????0??2013-02-19?20:55??delaunay2\delaunay2\obj\x86\Debug\TempPE\
?????文件?????????490??2013-02-19?22:53??delaunay2\delaunay2\Program.cs
?????目錄???????????0??2013-02-19?20:55??delaunay2\delaunay2\Properties\
?????文件????????1350??2013-02-19?20:55??delaunay2\delaunay2\Properties\AssemblyInfo.cs
............此處省略4個(gè)文件信息
評(píng)論
共有 條評(píng)論