当前位置: 首页>>代码示例>>C#>>正文


C# LineSegment.MediumBissector方法代码示例

本文整理汇总了C#中LineSegment.MediumBissector方法的典型用法代码示例。如果您正苦于以下问题:C# LineSegment.MediumBissector方法的具体用法?C# LineSegment.MediumBissector怎么用?C# LineSegment.MediumBissector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LineSegment的用法示例。


在下文中一共展示了LineSegment.MediumBissector方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddPoint

        public bool AddPoint(Point P)
        {
            Line cut = null;

            //----------------------------------------first part-------------------------
            if (Cells.Count == 0)
            {
                _cells.Add(new VoronoiCell(P));
                return true;
            }
            _cells.Add(new VoronoiCell(P));

            //Get the medium bissector
            LineSegment aux = new LineSegment(_cells[0].Center, _cells[1].Center);
            //Agora a gambiarra fica seria
            cut = aux.MediumBissector();
            if (Cells.Count == 1)
            {
                _cells[0].Sides.Add(new VoronoiLine(cut,_cells[1],1));
                _cells[1].Sides.Add(new VoronoiLine(cut,_cells[0],0));
                return true;
            }

            //--------------------------------------second part-----------------------

            Queue<int> indexToCut = new Queue<int>(); //Queue with the index of the voroni cells to cut

            //Finds which cell contains P
            int initialIndex;
            bool worked = false;
            for (initialIndex = 0; initialIndex < Cells.Count; initialIndex++)
            {
                if(Cells[initialIndex].IsInsideSpecial(P))
                {
                    worked = true;
                    break;
                }
            }
            if(!worked) return false;

            //Start the algorithm
            bool [] visited = new bool [Cells.Count];
            for (int i = 0;  i < Cells.Count; i++)
            {
                visited[i] = false;
            }
            visited[initialIndex] = true;
            visited[Cells.Count-1] = true;
            indexToCut.Enqueue(initialIndex);
            List<int> nextIndexes; //aux
            while(indexToCut.Count>0)
            {

                int currentIndex = indexToCut.Dequeue();//gets the next index
                bool haveCut = true; //POG
                nextIndexes = Cells[currentIndex].CutPoligon(cut, ref haveCut);
                if(haveCut)
                {
                    Cells[currentIndex].Sides[Cells[currentIndex].Sides.Count - 1].IndexNeigbor = Cells.Count-1;
                    Cells[currentIndex].Sides[Cells[currentIndex].Sides.Count - 1].Neigbor = Cells[Cells.Count - 1];

                    VoronoiLine support = Cells[currentIndex].Sides[Cells[currentIndex].Sides.Count-1];

                    Cells[Cells.Count-1].Sides.Add(new VoronoiLine(support._line));
                    Cells[Cells.Count - 1].Sides[Cells[Cells.Count - 1].Sides.Count - 1].IndexNeigbor = currentIndex;
                    Cells[Cells.Count - 1].Sides[Cells[Cells.Count - 1].Sides.Count - 1].Neigbor = Cells[currentIndex];
                }
                for (int i = 0; i < nextIndexes.Count; i++)
                {
                    if(!visited[nextIndexes[i]])
                    {
                        visited[nextIndexes[i]] = true;
                        indexToCut.Enqueue(nextIndexes[i]);
                    }
                }
            }
            return true;
        }
开发者ID:Supitto,项目名称:Metria,代码行数:78,代码来源:VoronoiDiagram.cs


注:本文中的LineSegment.MediumBissector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。