Ejemplo n.º 1
0
        public bool Intersects(LineSeg B)
        {
            var A = this;

            var ADelta = A.I1 - A.I0;
            var BDelta = B.I1 - B.I0;

            var denom = (-BDelta.X * ADelta.Y + ADelta.X * BDelta.Y);

            var s = (-ADelta.Y * (A.I0.X - B.I0.X) + ADelta.X * (A.I0.Y - B.I0.Y)) / denom;
            var t = (BDelta.X * (A.I0.Y - B.I0.Y) - ADelta.Y * (A.I0.X - B.I0.X)) / denom;

            if (s >= 0.0 && s <= 1.0 && t >= 0.0 && t <= 1.0)
            {
                var intX = A.I0.X + (t * ADelta.X);
                var intY = A.I0.Y + (t * ADelta.Y);

                var intPoint = new Point(intX, intY);

                //Console.WriteLine("Intersection: " + intPoint.ToString());

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
 public DataPoint(int nInd, LineSeg ls)
 {
     _Ls  = ls;
     _Ind = nInd;
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            string path = args[0];

            Dictionary <int, DataPoint> dicData = new Dictionary <int, DataPoint>();

            Dictionary <int, Set> dicIndToNeighs = new Dictionary <int, Set>(); //Adjacency

            using (StreamReader sr = new StreamReader(path))
            {
                while (sr.Peek() >= 0)
                {
                    string strline = sr.ReadLine();
                    //Console.WriteLine(sr.ReadLine());
                    var firstsplit = strline.Split(':').ToList();
                    int nVal       = Convert.ToInt32(firstsplit[0]);

                    var secondsplit = firstsplit[1].Split(',');

                    List <double> dVals = new List <double>();
                    foreach (var val in secondsplit)
                    {
                        var trimmed = val.Trim(new Char[] { ' ', '[', ']', '(', ')' });
                        dVals.Add(Convert.ToDouble(trimmed));
                        //Console.WriteLine("trimmed: " + trimmed);
                    }

                    LineSeg ls = new LineSeg(dVals);
                    dicData[nVal] = (new DataPoint(nVal, ls));
                }
            }

            foreach (var i in dicData) //Could make this symmetric, but will be lazy for now
            {
                Set neighsForInd = new Set();
                Console.WriteLine(i.Value.ToString());
                foreach (var j in dicData)
                {
                    if (i.Key == j.Key)
                    {
                        continue;
                    }

                    if (i.Value._Ls.Intersects(j.Value._Ls))
                    {
                        //Console.WriteLine(i + " " + j + " intersect");
                    }
                    else
                    {
                        neighsForInd.Add(j.Key);
                    }
                }

                dicIndToNeighs[i.Key] = neighsForInd;
            }

            BronKerbosch bk = new BronKerbosch();

            bk._adjacency = dicIndToNeighs;

            Set R = new Set();
            Set X = new Set();
            Set P = new Set();

            foreach (var v in dicData)
            {
                X.Add(v.Key);
            }

            bk.BK(R, X, P);

            var vMaxSorted = from data in bk._maximumClique orderby data ascending select data;

            foreach (var v in vMaxSorted)
            {
                Console.WriteLine(v);
            }

            //Console.WriteLine("Calls: " + bk._Calls);
        }