• 大小: 131KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: Matlab
  • 标签: voronoi  computationa  

资源简介

使用matlab生成了Voronoi图,使用Delaunay三角形生成Voronoi图。

资源截图

代码片段和文件信息

%本函数实现将相邻三角形外接圆圆心相连
%对于没有外接圆的边,标记其中垂线射线(端点为接圆圆心)
function triangles = buildLine(triangles Xmax Xmin Ymax Ymin)

Xmid = Xmin + (Xmax-Xmin)/2;
Ymid = Ymin + (Ymax-Ymin)/2;
[~ n] = size(triangles);
for i = 1:n
    triangles(i).neighborCircleCenters = [];
    if size(triangles(i).neighbors 2) ~= 3
        if size(triangles(i).neighbors 2) == 1
            center = triangleCircumCircle(triangles(triangles(i).neighbors(1)));
            center = center(1).center;
            triangles(i).neighborCircleCenters = [triangles(i).neighborCircleCenters; center];
            %下面为中垂线射线
            tbl = tabulate(triangles(i).linindex(:));
            temp = find(tbl(: 2) == 0);
            bian = [tbl(temp(1)) tbl(2 1); tbl(temp(1)) tbl(3 1)];
            for k = 1:2
                x11 = triangles(i).list(bian(k 1) 1);
                x21 = triangles(i).list(bian(k 2) 1);
                y11 = triangles(i).list(bian(k 1) 2);
                y21 = triangles(i).list(bian(k 2) 2);
                if x11 < x21
                    x1 = x11 + (x21-x11)/2;
                    if y11 < y22
                        y1 = y11 + (y21-y11)/2;
                    else
                        y1 = y21 + (y11-y21)/2;
                    end
                else
                    x1 = x21 + (x11-x21)/2;
                    if y11 < y21
                        y1 = y11 + (y21-y11)/2;
                    else
                        y1= y21 + (y11-y21)/2;
                    end
                end
                
                x2 = triangles(i).center(1);
                y2 = triangles(i).center(2);
                
                     if abs(x1 - x2) < 0.0000001
                    x = x1;
                    if y1 > Ymid
                        y = y1 + 1;
                    else
                        y = y1 - 1;
                    end
                else
                    if x1 > Xmid
                        x = x1 + 1;
                        y = (x-x1) / (x1-x2) * (y1-y2) + y1;
                    else
                        x = x1 - 1;
                        y = (x-x1) / (x1-x2) * (y1-y2) + y1;
                    end
                end
                
                triangles(i).neighborCircleCenters = [triangles(i).neighborCircleCenters; [x y]];
            end
        elseif size(triangles(i).neighbors 2) == 2
            for j = 1:2
                center = triangleCircumCircle(triangles(triangles(i).neighbors(j)));
                center = center(1).center;
                triangles(i).neighborCircleCenters = [triangles(i).neighborCircleCenters; center];
            end
                %下面为中垂线射线
                tbl = tabulate(triangles(i).linindex(:));
                temp = find(tbl(: 2) == 1);
                bian = [tbl(temp(1) 1) tbl(temp(2) 1)];
                x11 = triangles(i).list(bian(1) 1);
                x21 = triangles(i).list(bian(2) 1)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        5146  2018-12-10 20:48  buildLine.m
     文件         550  2018-12-06 18:13  circumcircleBuilding.m
     文件        6367  2019-01-01 13:43  DT2.m
     文件         993  2018-12-10 17:22  findNeighborTriangles.m
     文件         198  2018-12-07 12:06  isInCircle.m
     文件         453  2018-12-10 10:50  isInCircleRight.m
     文件         936  2018-12-10 13:57  triangleCircumCircle.m
     文件         291  2019-01-01 13:02  VD1.m
     文件       70549  2018-12-10 21:00  VD1结果图.png
     文件        1306  2019-01-01 13:43  VD2.m
     文件       69816  2018-12-10 20:58  VD2结果图.png

评论

共有 条评论