Пример #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);
        }
Пример #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);
            }
        }
Пример #3
0
        public static point intersectionPoint(edge e1, edge e2)
        {
            point p = null;

            double t;

            if (intersect(e1, e2, out t) == forIntersectionPoint.Skew_Cross)
            {
                p = BaseAlgs.pt(e1, t);
            }

            return(p);
        }
Пример #4
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();
            }
        }
Пример #5
0
        private void isPointInsideButton_Click(object sender, EventArgs e)
        {
            point p = pointsBox.SelectedItem as point;

            if (p == null)
            {
                MessageBox.Show("Выберите точку!");
            }
            else if (plgn == null)
            {
                MessageBox.Show("Создайте полигон!");
            }
            else
            {
                isPointInsideTextBox.Text = BaseAlgs.isPointInsidePolygon(p, plgn).ToString();
            }
        }
Пример #6
0
        private void edgeIntersectButton_Click(object sender, EventArgs e)
        {
            edge e1 = comboBoxEdgeIntsct1.SelectedItem as edge;
            edge e2 = comboBoxEdgeIntsct2.SelectedItem as edge;

            if (e1 == null || e2 == null)
            {
                MessageBox.Show("Выберите ребра!");
            }
            else if (e1 == e2)
            {
                MessageBox.Show("Выберите разные ребра!");
            }
            else
            {
                point p = BaseAlgs.intersectionPoint(e1, e2);
                if (p != null)
                {
                    drawPoint(p, Color.Blue);
                }
            }
        }
Пример #7
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);
        }