Delaunay三角网算法

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Biblioteka Baidu
public int Triangulate(int nvert) { bool[] Complete = new bool[MaxTriangles]; long[,] Edges = new long[3, MaxTriangles * 3+1]; long Nedge; long xmin; long xmax; long ymin; long ymax; long xmid; long ymid; double dx; double dy; double dmax; int i; int j; int k; int ntri; double xc = 0.0; double yc = 0.0; double r = 0.0; bool inc; xmin = Vertex[1].x; ymin = Vertex[1].y; xmax = xmin; ymax = ymin; for (i = 2; i <= nvert; i++) { if (Vertex[i].x < xmin) { xmin = Vertex[i].x; } if (Vertex[i].x > xmax) { xmax = Vertex[i].x; } if (Vertex[i].y < ymin) { ymin = Vertex[i].y; } if (Vertex[i].y > ymax) { ymax = Vertex[i].y; }
double dx; double dy; double rsqr; double drsqr; eps = 0.000000001; if (Math.Abs(y1 - y2) < eps && Math.Abs(y2 - y3) < eps) { MessageBox.Show("INCIRCUM - F - Points are coincident !!"); return false; } if (Math.Abs(y2 - y1) < eps) { m2 = (-(Convert.ToDouble(x3) Convert.ToDouble(x2)) / (Convert.ToDouble(y3) - Convert.ToDouble(y2))); mx2 =Convert.ToDouble( (x2 + x3) / 2.0); my2 =Convert.ToDouble( (y2 + y3) / 2.0); xc = Convert.ToDouble((x2 + x1) / 2.0); yc =Convert.ToDouble( m2 * (xc - mx2) + my2); } else if (Math.Abs(y3 - y2) < eps) { m1 = (-(Convert.ToDouble(x2) Convert.ToDouble(x1)) / (Convert.ToDouble(y2) - Convert.ToDouble(y1))); mx1 =Convert.ToDouble( (x1 + x2) / 2.0); my1 =Convert.ToDouble( (y1 + y2) / 2.0); xc = Convert.ToDouble((x3 + x2) / 2.0); yc =Convert.ToDouble( m1 * (xc - mx1) + my1); } else { m1 = (-(Convert.ToDouble(x2) Convert.ToDouble(x1)) / (Convert.ToDouble(y2) - Convert.ToDouble(y1))); m2 = (-(Convert.ToDouble(x3) Convert.ToDouble(x2)) / (Convert.ToDouble(y3) - Convert.ToDouble(y2))); mx1 = Convert.ToDouble((x1 + x2) / 2.0); mx2 = Convert.ToDouble((x2 + x3) / 2.0); my1 = Convert.ToDouble((y1 + y2) / 2.0); my2 = Convert.ToDouble((y2 + y3) / 2.0); xc = Convert.ToDouble((m1 * mx1 - m2 *
= dx;
= dy; + xmin) / 2; + ymin) / 2; + 1].x = Convert.ToInt64(xmid - 2
Vertex[Triangle[j].vv2].y, xc, yc, r); if (inc) { Edges[1, Nedge + 1] = Triangle[j].vv0; Edges[2, Nedge + 1] = Triangle[j].vv1; Edges[1, Nedge + 2] = Triangle[j].vv1; Edges[2, Nedge + 2] = Triangle[j].vv2; Edges[1, Nedge + 3] = Triangle[j].vv2; Edges[2, Nedge + 3] = Triangle[j].vv0; Nedge = Nedge + 3; Triangle[j]. vv0 = Triangle[ntri].vv0; Triangle[j]. vv1 = Triangle[ntri].vv1; Triangle[j]. vv2 = Triangle[ntri].vv2; Complete[j] = Complete[ntri]; j = j - 1; ntri = ntri 1; }}} while (j < ntri); for (j = 1; j <= Nedge - 1; j++) { if (Edges[1, j] != 0 && Edges[2, j] != 0) { for (k = j + 1; k <= Nedge; k++) { if (Edges[1, k] != 0 && Edges[2, k] != 0) { if (Edges[1, j] == Edges[2, k]) {
Delaunay 三角网算法(用 C#语言实现)
这是我翻译的一个 VB6.0 的 delaunay(简称 D 三角网)三角网的算法,里面的 变量设置还需要修改一下, 由于 C#的强类型检查,所以比 VB6.0 要麻烦一些 虑程式的布局样式了 using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; namespace Delaunay { public struct dVertex { public long x; public long y; public long z; } public struct dTriangle { public long vv0; public long vv1; public long vv2; } public class Delaunay { public const int MaxVertices = 500; public const int MaxTriangles = 1000; public dVertex[] Vertex = new dVertex[MaxVertices]; public dTriangle[] Triangle = new dTriangle[MaxTriangles]; private bool InCircle(long xp, long yp, long x1, long y1, long x2, long y2, long x3, long y3, double xc, double yc, double r) { double eps; double m1; double m2; double mx1; double mx2; double my1; double my2; ,由于篇幅受限所以就不考
} dx = Convert.ToDouble(xmax) Convert.ToDouble(xmin); dy = Convert.ToDouble(ymax) Convert.ToDouble(ymin); if (dx > dy) { dmax } else { dmax } xmid = (xmax ymid = (ymax Vertex[nvert * dmax); Vertex[nvert + 1].y = Convert.ToInt64(ymid dmax); Vertex[nvert + 2].x = xmid; Vertex[nvert + 2].y = Convert.ToInt64(ymid + 2 * dmax); Vertex[nvert + 3].x = Convert.ToInt64(xmid + 2 * dmax); Vertex[nvert + 3].y = Convert.ToInt64(ymid dmax); Triangle[1].vv0 = nvert + 1; Triangle[1].vv1 = nvert + 2; Triangle[1].vv2 = nvert + 3; Complete[1] = false; ntri = 1; for (i = 1; i <= nvert; i++) { Nedge = 0; j = 0; do { j = j + 1; if (Complete[j] != true) { inc = InCircle(Vertex[i].x, Vertex[i].y, Vertex[Triangle[j].vv0].x, Vertex[Triangle[j].vv0].y, Vertex[Triangle[j].vv1].x, Vertex[Triangle[j].vv1].y, Vertex[Triangle[j].vv2].x,
mx2 + my2 - my1) / (m1 - m2)); yc = Convert.ToDouble(m1 * (xc - mx1) + my1); } dx = (Convert.ToDouble(x2) Convert.ToDouble(xc)); dy = (Convert.ToDouble(y2) Convert.ToDouble(yc)); rsqr = Convert.ToDouble(dx * dx + dy * dy); r = Convert.ToDouble(Math.Sqrt(rsqr)); dx = Convert.ToDouble(xp - xc); dy = Convert.ToDouble(yp - yc); drsqr = Convert.ToDouble(dx * dx + dy * dy); if (drsqr <= rsqr) { return true; } return false; } private int WhichSide(long xp, long yp, long x1, long y1, long x2, long y2) { double equation; equation = ((Convert.ToDouble(yp) Convert.ToDouble(y1)) * (Convert.ToDouble(x2) - Convert.ToDouble(x1))) - ((Convert.ToDouble(y2) - Convert.ToDouble(y1)) * (Convert.ToDouble(xp) - Convert.ToDouble(x1))); if (equation > 0) { return -1; //WhichSide = -1; } else if (equation == 0) { return 0; } else { return 1; } }
相关文档
最新文档