[Delaunay Triangle] [图形学] C# 实现代码

本文介绍了C#实现Delaunay三角剖分的图形学代码,展示了随机30个点的效果,并提供修复判断双边逻辑错误的方案。核心代码可移植。
摘要由CSDN通过智能技术生成

原理

效果

这是一个随机三十个点的最终构成效果。

实现代码

以下是以C#为基础的实现代码,用到了UnityEngine.Vector2类型和v2相关的函数,核心逻辑与Unity不关联,不妨碍移植。

using System.Collections.Generic;
using UnityEngine;

public class UDelaunayResult
{
    /// <summary>
    /// 三角形列表
    /// </summary>
    public List<Vector2[]> Triangles;
    /// <summary>
    /// 边列表
    /// </summary>
    public List<Vector2[]> Edges;
    /// <summary>
    /// 顶点列表
    /// </summary>
    public List<Vector2> Vertexes;
}

public class UDelaunay
{
    public static UDelaunayResult GetTriangles2D(List<Vector2> _vertexes) 
    {
        UDelaunayResult result = new UDelaunayResult();
        List<Vector2[]> triangles = new List<Vector2[]>();
        List<Vector2[]> edges = new List<Vector2[]>();
        List<Vector2[]> super = new List<Vector2[]>();
        //> 找到最小和最大的点
        float minX=0, minY=0, maxX=0, maxY=0; 
        foreach (var v in _vertexes) 
        {
            if (v.x < minX) minX = v.x;
            if (v.y < minY) minY = v.y;
            if (v.x > maxX) maxX = v.x;
            if (v.y > maxY) maxY = v.y;
        } 
        minX -= 10;
        mi
  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值