Ejemplo n.º 1
0
        public static bool mate(edge e, List <point> s, ref point p)
        {
            int    fl = 0;
            point  bestp = null;
            double t = double.MaxValue, bestt = double.MaxValue;
            edge   f = new edge(e);

            f = f.rot();

            for (int i = 0; i < s.Count; ++i)
            {
                if (BaseAlgs.classify(s[i], e) == BaseAlgs.orientation.Right)
                {
                    point tp = s[i];
                    edge  g  = new edge(ref e.dest, ref tp);
                    //edge g = new edge(e.dest, tp);
                    g.rot();
                    BaseAlgs.intersect(f, g, out t);
                    if (t < bestt)
                    {
                        fl    = 1;
                        bestp = s[i];
                        bestt = t;
                    }
                }
            }
            if (fl == 1)
            {
                p = bestp;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        private int pointsComparer(point ps, point pd, point p)
        {
            switch (BaseAlgs.classify(p, new edge(ref ps, ref pd)))
            {
            case BaseAlgs.orientation.Left: return(-1);

            case BaseAlgs.orientation.Right: return(1);

            default: return(0);
            }
        }
Ejemplo n.º 3
0
////////////////////////////////////////////////



        private void button1_Click(object sender, EventArgs e)
        {
            point p  = pointsBox.SelectedItem as point;
            edge  ed = edgesBox.SelectedItem as edge;

            if (p == null || ed == null)
            {
                MessageBox.Show("Выберите ребро и точку!");
            }
            else
            {
                textBox1.Text = BaseAlgs.classify(p, ed).ToString();
            }
        }
Ejemplo n.º 4
0
        public static edge hullEdge(List <point> s)
        {
            point p1, p2;
            int   m = 0;

            for (int i = 0; i < s.Count; ++i)
            {
                if (s[i] < s[m])
                {
                    m = i;
                }
            }
            point p = new point(s[0].x, s[0].y);

            s[0].x = s[m].x;
            s[0].y = s[m].y;
            s[m]   = p;

            m = 1;

            for (int j = 2; j < s.Count; ++j)
            {
                p1 = s[0];
                p2 = s[m];
                BaseAlgs.orientation c = BaseAlgs.classify(s[j], new edge(ref p1, ref p2));
                //BaseAlgs.orientation c = BaseAlgs.classify(s[j], new edge(p1, p2));
                if (c == BaseAlgs.orientation.Left || c == BaseAlgs.orientation.Between)
                {
                    m = j;
                }
            }

            p1 = s[0];
            p2 = s[m];

            return(new edge(ref p1, ref p2));
            //return new edge(p1, p2);
        }