Exemplo n.º 1
0
        //�����������
        /// <summary>
        ///�����������
        /// </summary>
        /// <param name="starti">��ʼ�����ڵ���</param>
        /// <param name="store">����˳��</param>
        /// <param name="Sosflag">�����������������</param>
        /// <param name="insectflag">�ཻ������� �ཻΪ1</param>
        ///  <param name="insectpoint">�ཻ�������¼����</param>
        ///  <param name="polyon">�������������</param>
        ///  <param name="vectcollect">�����ཻ��̩ɭ�����</param>
        public void Sospoloy(int starti, bool store, int[] Sosflag,int[] taisflag, int[,] insectflag, PointF[,] insectpoint, Polyon multrect, voronoiboundary tais)
        {
            int m = multrect.Vertices.Count; int n = tais.voronicollect.Count;
            if(store)
            {
                for(int j=starti;j<m;j++)
                {
                    if (Sosflag[j]==1)
                    {
                        return;
                    }
                    else
                    {
                        Sosflag[j] = 1;
                        if (PtInPolygon(multrect.Vertices[j], tais.voronicollect))
                        {
                            if (tais.Vimultptcompare(multrect.Vertices[j]))
                            {
                                tais.vimultcollect.Add(multrect.Vertices[j]);
                            }

                        }
                        for (int i = 0; i < n;i++ )
                        {
                            if (insectflag[i,j] == 1)
                            {
                                insectflag[i,j] = 0;
                                //�ж��ཻ�ĵ��Ƿ���Ƕ˵�
                                if (tais.Vimultptcompare(insectpoint[i, j]))
                                {
                                    tais.vimultcollect.Add(insectpoint[i, j]);
                                }

                                if (PtInPolygon(tais.voronicollect[i], multrect.Vertices))
                                {
                                    if (tais.Vimultptcompare(tais.voronicollect[i]))
                                    {
                                        tais.vimultcollect.Add(tais.voronicollect[i]);
                                    }

                                    //������һѭ���ĺ��� ����Ҫ�жϴ˶���ε�˳�������ʱ�����С�����������С�����˳�� ���������������ǴӴ�С��˳��
                                    if (i < (i + 1) % n)
                                   {
                                       if (!IsCCW(tais.voronicollect))
                                       {
                                           Sospoloy(i, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                       }
                                       else
                                           Sospoloy(i, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                   }
                                    else
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy(i, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy(i, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }

                                }
                                if (PtInPolygon(tais.voronicollect[(i + 1) % n], multrect.Vertices))
                                {
                                    if (tais.Vimultptcompare(tais.voronicollect[(i + 1) % n]))
                                    {
                                        tais.vimultcollect.Add(tais.voronicollect[(i + 1) % n]);
                                    }

                                    //������һѭ���ĺ���
                                    if (i < (i + 1) % n)
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy((i + 1) % n, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy((i + 1) % n, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }
                                    else
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy((i + 1) % n, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy((i + 1) % n,true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }

                                }
                            }
                        }
                    }

                }
            }
            else
            {
                for (int j = starti+m; j >0 ; j--)
                {
                    if (Sosflag[j%m] == 1)
                    {
                        return;
                    }
                    else
                    {
                        Sosflag[j % m] = 1;
                        if (PtInPolygon(multrect.Vertices[j % m], tais.voronicollect))
                        {
                            if (tais.Vimultptcompare(multrect.Vertices[j % m]))
                            {
                                tais.vimultcollect.Add(multrect.Vertices[j % m]);
                            }

                        }
                        for (int i = 0; i < n; i++)
                        {
                            if (insectflag[i,j % m] == 1)
                            {
                                insectflag[i,j % m] = 0;
                                if (tais.Vimultptcompare(insectpoint[i, j % m]))
                                {
                                    tais.vimultcollect.Add(insectpoint[i, j % m]);
                                }

                                if (PtInPolygon(tais.voronicollect[i], multrect.Vertices))
                                {
                                    if (tais.Vimultptcompare(tais.voronicollect[i]))
                                    {
                                        tais.vimultcollect.Add(tais.voronicollect[i]);
                                    }

                                    //������һѭ���ĺ���
                                    if (i < (i + 1) % n)
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy(i, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy(i, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }
                                   else
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy(i, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy(i, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }

                                }
                                if (PtInPolygon(tais.voronicollect[(i + 1) % n], multrect.Vertices))
                                {
                                    if (tais.Vimultptcompare(tais.voronicollect[(i + 1) % n]))
                                    {
                                        tais.vimultcollect.Add(tais.voronicollect[(i + 1) % n]);
                                    }

                                    //������һѭ���ĺ���
                                    if (i < (i + 1) % n)
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy((i + 1) % n, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy((i + 1) % n, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }
                                    else
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy((i + 1) % n, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy((i + 1) % n, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }

                                }
                            }
                        }
                    }

                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// ��ö���κ�͹��̩ɭ����εĽ���
        /// </summary>
        /// <param name="multrect">��������</param>
        /// <param name="tais">͹�ǵ�̩ɭ�����</param>
        public void insectpoloy(Polyon multrect,voronoiboundary tais)
        {
            int m = multrect.Vertices.Count; int n = tais.voronicollect.Count;
               //Ϊ��������εĽ�����һ������һ������εı�� ��ʼΪ�� ������������ڲ���Ϊ1
               int[] rectpointflag=new int[m];
               int[] taispointflag=new int[n];
               for (int i=0;i<m;i++)
               {
               rectpointflag[i]=0;
               }
               for (int j=0;j<n;j++)
               {
               taispointflag[j]=0;
               }
               //����ཻ�����ཻ����·��ŵ�λ��Ϊ1 ������·�ĵ�һ���ڵ�ı��˳��
               int[,] insectflag=new int[n,m];
               PointF[,] insectpoint=new PointF[n,m];
               for (int i=0;i<n;i++)
               {
               for (int j=0;j<m;j++)
               {
                   insectflag[i,j]=0;
                   insectpoint[i,j] = new PointF();
               }

               }
               //�����ཻ���߶��ñ�Ǽ�¼
               for (int i = 0; i < n;i++ )
               {
               PointF p1 = tais.voronicollect[i];
               PointF p2 = tais.voronicollect[(i + 1) % n];
               for (int j = 0; j < m;j++ )
               {
                   PointF p=new PointF();
                   PointF p3 = multrect.Vertices[j];
                   PointF p4 = multrect.Vertices[(j + 1) % multrect.Vertices.Count];
                   if (GetIntersection(p1, p2, p3, p4, ref p) == 1)
                   {
                       insectflag[i,j] = 1;
                       insectpoint[i,j] = p;
                   }
               }
               }
               //���н����յ������
               int starti = 0;
              sosocontinue:
               Sospoloy(starti, true, rectpointflag, taispointflag, insectflag, insectpoint, tais, multrect);
               //�����ཻ�Ľڵ��Ƿ���ȫ����
               int resault = 0;
               for (int i = 0; i < n;i++ )
               {
               for (int j = 0; j < m;j++ )
               {
                   if (insectflag[i, j]==1)
                   {
                       starti=i;
                       goto sosocontinue;
                   }

               }
               }
              //������õĽ������� ̩ɭ����μ�����
               tais.voronicollect.Clear();
               for (int i = 0; i < tais.vimultcollect.Count;i++ )
               {
               tais.voronicollect.Add(tais.vimultcollect[i]);
               }

               //for (int i = 0; i < n;i++ )
               //{
               //    taispointflag[i] = 1;    //˵�������ڲ�
               //    if (PtInPolygon(tais.voronicollect[i],multrect.Vertices))
               //    {
               //         tais.insertboundarycollect.Add(tais.voronicollect[i]);

               //    }
               //    for (int j=0;j<m;j++)
               //    {
               //        if (insectflag[i,j]==1)
               //        {
               //            insectflag[i,j] = 0;
               //            tais.insertboundarycollect.Add(insectpoint[i,j]);
               //            if (PtInPolygon(multrect.Vertices[j],tais.voronicollect))
               //            {
               //                tais.insertboundarycollect.Add(multrect.Vertices[j]);

               //            }
               //            if (PtInPolygon(multrect.Vertices[(j + 1) % multrect.Vertices.Count], tais.voronicollect))
               //            {
               //                tais.insertboundarycollect.Add(multrect.Vertices[(j + 1) % multrect.Vertices.Count]);
               //            }
               //        }

               //    }

               //}
        }
Exemplo n.º 3
0
 //�жϿ�Խ������߶������εĽ��� �������ȫ�����򷵻�a ��b
 /// <summary>
 /// �жϿ�Խ������߶������εĽ��� �������ȫ�����򷵻�a ��b
 /// </summary>
 /// <param name="a">�߶��׽ڵ�</param>
 /// <param name="b">�߶�ĩ�ڵ�</param>
 /// <param name="rec">�������</param>
 public List<PointF> Lineinsectpolygon(PointF a, PointF b, Polyon rect)
 {
     List<PointF> pcol = new List<PointF>();
     PointF p=new PointF();
     for (int i = 0; i < rect.Vertices.Count; i++)
     {
         PointF p1 = rect.Vertices[i];
         PointF p2 = rect.Vertices[(i + 1) % rect.Vertices.Count];
         if (GetIntersection(a,b,p1,p2,ref p)==1)
         {
             pcol.Add(p);
             break;
         }
         else if(GetIntersection(a,b,p1,p2,ref p)==2)
         {
             pcol.Add(a);
             pcol.Add(b);
             break;
         }
     }
     return pcol;
 }
Exemplo n.º 4
0
        //����̩ɭ�����
        /// <summary>
        ///����̩ɭ�����
        /// </summary>
        /// <param name="starti">��ʼ�����ڵ���</param>
        /// <param name="store">����˳��</param>
        /// <param name="Sosflag">�����������������</param>
        /// <param name="insectflag">�ཻ������� �ཻΪ1</param>
        ///  <param name="insectpoint">�ཻ�������¼����</param>
        ///  <param name="polyon">�������������</param>
        ///  <param name="vectcollect">�����ཻ��̩ɭ�����</param>
        public void Sospoloy(int starti, bool store, int[] Sosflag, int[] taisflag,int[,] insectflag, PointF[,] insectpoint, voronoiboundary tais,Polyon multrect )
        {
            int m = multrect.Vertices.Count; int n = tais.voronicollect.Count;
            if (store)
            {
                for (int i = starti; i< n; i++)
                {
                    if (taisflag[i] == 1)
                    {
                        return;
                    }
                    else
                    {
                        taisflag[i] = 1;
                        if (PtInPolygon(tais.voronicollect[i], multrect.Vertices))
                        {
                            if (tais.Vimultptcompare(tais.voronicollect[i]))
                            {
                                tais.vimultcollect.Add(tais.voronicollect[i]);
                            }

                        }
                        for (int j = 0; j < m; j++)
                        {
                            if (insectflag[i,j] == 1)
                            {
                                insectflag[i,j] = 0;
                                if (tais.Vimultptcompare(insectpoint[i, j]))
                                {
                                    tais.vimultcollect.Add(insectpoint[i, j]);
                                }

                                if (PtInPolygon(multrect.Vertices[j], tais.voronicollect))
                                {
                                    if (tais.Vimultptcompare(multrect.Vertices[j]))
                                    {
                                        tais.vimultcollect.Add(multrect.Vertices[j]);
                                    }

                                    //������һ����ε�ѭ�� ����Ҫ�жϴ˶������ʲô˳��
                                    if (j < (j + 1) % m)
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy(j, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy(j, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }
                                    else
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy(j, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy(j, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }

                                }
                                if (PtInPolygon(multrect.Vertices[(j + 1) % m], tais.voronicollect))
                                {
                                    if (tais.Vimultptcompare(multrect.Vertices[(j + 1) % m]))
                                    {
                                        tais.vimultcollect.Add(multrect.Vertices[(j + 1) % m]);
                                    }

                                    //������һ����ε�ѭ��
                                    if (j < (j + 1) % m)
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy((j + 1) % m, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy((j + 1) % m, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }
                                    else
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy((j + 1) % m, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy((j + 1) % m, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }

                                }
                            }
                        }
                    }

                }
            }
            else
            {
                for (int i= starti + n; i > 0; i--)
                {
                    if (taisflag[i % n] == 1)
                    {
                        return;
                    }
                    else
                    {
                       taisflag[i% n] = 1;
                        if (PtInPolygon(tais.voronicollect[i % n], multrect.Vertices))
                        {
                            if (tais.Vimultptcompare(tais.voronicollect[i % n]))
                            {
                                tais.vimultcollect.Add(tais.voronicollect[i % n]);
                            }

                        }
                        for (int j = 0; j < m; j++)
                        {
                            if (insectflag[i%n,j] == 1)
                            {
                                insectflag[i % n,j] = 0;
                                if (tais.Vimultptcompare(insectpoint[i % n, j]))
                                {
                                    tais.vimultcollect.Add(insectpoint[i % n, j]);
                                }

                                if (PtInPolygon(multrect.Vertices[j], tais.voronicollect))
                                {
                                    if (tais.Vimultptcompare(multrect.Vertices[j]))
                                    {
                                        tais.vimultcollect.Add(multrect.Vertices[j]);
                                    }

                                    //������һ���ѭ��
                                    if (j < (j + 1) % m)
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy(j, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy(j, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }

                                    else
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy(j, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy(j,false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }
                                }
                                if (PtInPolygon(multrect.Vertices[(j + 1) % m], tais.voronicollect))
                                {
                                    if (tais.Vimultptcompare(multrect.Vertices[(j + 1) % m]))
                                    {
                                        tais.vimultcollect.Add(multrect.Vertices[(j + 1) % m]);
                                    }

                                    //����Ҫѭ��������
                                    if (j < (j + 1) % m)
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy((j + 1) % m, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy((j + 1) % m, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }
                                   else
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy((j + 1) % m, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy((j + 1) % m, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }
                                }
                            }
                        }
                    }

                }
            }
        }