三维---三角网生成算法

这篇博客探讨了如何使用C#编程语言实现三维空间中的三角网生成算法,通过详细的数据类和方法描述,揭示了算法的具体步骤和实现细节。
摘要由CSDN通过智能技术生成

    class Delaunay
    {
        private static int INIT_VERTICES_COUNT = 6;
        private static int INIT_FACES_COUNT = 8;
        private static int VECTOR_LENGTH = 1;
        private static double DBL_EPSILON = 2.2204460492503131e-016;
        private static List<Vector3D> _AuxiliaryDots =new List<Vector3D>(INIT_VERTICES_COUNT);
        private static long[] _Statistics=new long[4];
        private static List< Vector3D> _ProjectedDots=new List<Vector3D>();
        static private List<Triangle> _Mesh = new List<Triangle>();
        private Delaunay()
        {
            for (int i = 0; i < INIT_VERTICES_COUNT; i++)
            {
                _AuxiliaryDots.Add( new Vector3D(
                    (i % 2 == 0 ? 1 : -1) * (i / 2 == 0 ? VECTOR_LENGTH : 0),
                    (i % 2 == 0 ? 1 : -1) * (i / 2 == 1 ? VECTOR_LENGTH : 0),
                    (i % 2 == 0 ? 1 : -1) * (i / 2 == 2 ? VECTOR_LENGTH : 0),
                    true, 0, 0, 0
                ));
            }
        }
        static double GetDistance(Vector3D v0, Vector3D v1)
        {
            return Math.Sqrt(Math.Pow((v0.X- v1.X), 2) +
        Math.Pow((v0.Y - v1.Y), 2) +  Math.Pow((v0.Z - v1.Z), 2));
        }
       static void RemoveExtraTriangles()
        {
            for (int i=0;i< _Mesh.Count;i++)
            {
                bool isExtraTriangle = false;
                for (int j = 0; j < 3; j++)
                {
                    if (_Mesh[i].Vertex[j].IsAuxiliaryDot)
                    {
                        isExtraTriangle = true;
                        break;
                    }
                }
                if (isExtraTriangle)
                {
                    _Mesh.RemoveAt(i);
                    i--;
                }
            
            }
        }
     public  static List<Tuple<int,int,int>> GetTriangulationResult(ref List<Vector3D> dots)
        {
            for (int i = 0; i < INIT_VERTICES_COUNT; i++)
            {
                _AuxiliaryDots.Add( new Vector3D(
                    (i % 2 == 0 ? 1 : -1) * (i / 2 == 0 ? VECTOR_LENGTH : 0),
                    (i % 2 == 0 ? 1 : -1) * (i / 2 == 1 ? VECTOR_LENGTH : 0),
                    (i % 2 == 0 ? 1 : -1) * (i / 2 == 2 ? VECTOR_LENGTH : 0),
                    true, 0, 0, 0
                ));
            }
            //_Statistics[2] = clock();
            for (int i=0;i<dots.Count;i++)
            {
                Vector3D projectedDot = new Vector3D(dots[i],VECTOR_LENGTH);
                _ProjectedDots.Add(projectedDot);
            }
            BuildInitialHull(ref _ProjectedDots);
            for (int i=0;i<_ProjectedDots.Count;i++)
            {
                Vector3D dot = _ProjectedDots[i];
                if (!dot.IsVisited)
                {
                    InsertDot(dot);
                }
            }

            // remove trianges connected with auxiliary dots
            RemoveExtraTriangles();

            // generate output
            List<Tuple<int, int, int>> mesh = new List<Tuple<int, int, int>>();
            for
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值