GIS拓扑生成

图中第二个“左”是“右”,sorry……

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;

namespace GIS拓扑生成

{

    class Program

    {

        static void Main(string[] args)

        {

            const int Nhu = 6;

            const int Npoint = 4;

            string[] Start=new string[Nhu];

            string[] End = new string[Nhu];

            int[][] hu = new int[Npoint][];

            int[][] hu_left = new int[Nhu][];

            int[][] hu_right = new int[Nhu][];

            Hashtable ht = new Hashtable(Npoint);

            Start = new string[Nhu] { "A", "C", "D", "B", "C", "B" };

            End = new string[Nhu] { "B", "A", "A", "C", "D", "D" };

            hu[0] = new int[3] { 2, 1, 0 };

            hu[1] = new int[3] { 3, 5, 0 };

            hu[2] = new int[3] { 1, 4, 3 };

            hu[3] = new int[3] { 2, 5, 4 }; 

            ht.Add("A", 0);

            ht.Add("B", 1);

            ht.Add("C", 2);

            ht.Add("D", 3);            

            

            string No, Nc;

            for (int s = 0; s < Nhu; s++)

            {

                int Sc = s;

                List<int> Pi = new List<int>();

                if (hu_left[Sc] != null && hu_right[Sc] != null)

                    continue;

                if (hu_left[Sc] == null)

                {

                    Pi.Add(Sc);

                    hu_left[Sc] = Pi.ToArray();

                    No = Start[Sc];

                    Nc = End[Sc];

                step1:

                    if ( Nc == No)

                        continue;

                    else

                    {

                        int j = (int)ht[Nc];

                        for (int so = 0; so < 3; so++)

                        {

                            int temp = Sc;

                            if (Sc == hu[j][so])

                                continue;

                            Sc = hu[j][so];

                            if (Nc == Start[Sc] && hu_left[Sc] == null)

                                break;

                            if (Nc == End[Sc] && hu_right[Sc] == null)

                                break;

                            Sc = temp;

                        }

                        Pi.Add(Sc);

                        if (Nc == Start[Sc])

                        {

                            hu_left[Sc] = Pi.ToArray();

                            Nc = End[Sc];

                        }

                        else if (Nc == End[Sc])

                        {

                            hu_right[Sc] = Pi.ToArray();

                            Nc = Start[Sc];

                        }

                        goto step1;

                    }                    

                }

                else

                {

                    Pi = new List<int>();

                    if (hu_right[Sc] == null)

                    {

                        Pi.Add(Sc);

                        hu_right[Sc] = Pi.ToArray();

                        No = End[Sc];

                        Nc = Start[Sc];

                    step2:

                        if (No == Nc)

                            continue;

                        else

                        {

                            int j = (int)ht[Nc];

                            for (int so = 0; so < 3; so++)

                            {

                                int temp = Sc;

                                if (Sc == hu[j][so])

                                    continue;

                                Sc = hu[j][so];

                                if (Nc == Start[Sc] && hu_left[Sc] == null)

                                    break;

                                if (Nc == End[Sc] && hu_right[Sc] == null)

                                    break;

                                Sc = temp;

                            }

                                

                            Pi.Add(Sc);

                            if (Nc == Start[Sc])

                            {

                                hu_left[Sc] = Pi.ToArray();

                                Nc = End[Sc];

                            }

                            else if (Nc == End[Sc])

                            {

                                hu_right[Sc] = Pi.ToArray();

                                Nc = Start[Sc];

                            }

                            goto step2;

                        }                        

                    }

                }

            }

            Console.WriteLine("弧段编号\t弧段左多边形\t弧段右多边形");

            string l = "";

            string r = "";

            for (int n = 0; n < Nhu; n++)

            {

                for (int ko=0;ko <hu_left[n].Length ;ko++)

                    l += hu_left [n][ko ].ToString ();

                for (int ko = 0; ko < hu_right[n].Length; ko++)

                    r += hu_right[n][ko].ToString();

                Console.WriteLine((n).ToString() + "\t\t" + l + "\t\t" + r);

                l = ""; r = "";

            }                

            Console.ReadLine();

        }

    }

}


原文地址:https://www.cnblogs.com/lcxu2/p/2004026.html