Beispiel #1
0
 public MyTriangle(MyPoint a, MyPoint b, MyPoint c)
 {
     A = a;
     B = b;
     C = c;
     halfPeriment = (A.getDistance(B) + A.getDistance(C) + B.getDistance(C)) / 2;
     square = Math.Pow((halfPeriment * (halfPeriment - A.getDistance(B)) * (halfPeriment - A.getDistance(C)) * (halfPeriment - B.getDistance(C))), 0.5);
 }
Beispiel #2
0
 public bool is_between(MyPoint one, MyPoint two)
 {
     double exp1 = getDistance(one) + getDistance(two);
     double exp2 = one.getDistance(two);
     double exp3 = exp1 - exp2;
     if (exp3 < 0)
         exp3 *= -1;
     return exp3 < coefficient_error;
 }
Beispiel #3
0
        public void TestMethod1()
        {
            MyPoint a = new MyPoint(0, 0);
            MyPoint b = new MyPoint(4, 6);
            MyPoint c = new MyPoint(4, 0);

            MyPoint in_point = new MyPoint(3, 2);
            MyPoint ex_point = new MyPoint(8, 8);

            MyTriangle triangle = new MyTriangle(a,b,c);

            Assert.AreEqual(true, triangle.MyPointBelong(in_point), "internal point checking");
            Assert.AreEqual(false, triangle.MyPointBelong(ex_point), "external point checking");
        }
Beispiel #4
0
        public bool MyPointBelong(MyPoint D)
        {
            bool result = false;
            // Найдем 3 треугольника, который получатся при добавлении точки.
            MyTriangle first = new MyTriangle(A, B, D);
            MyTriangle second = new MyTriangle(B, C, D);
            MyTriangle third = new MyTriangle(A, C, D);

            // А теперь немного заморочек со случаем, когда 3 точки лежат на 1 линии, и это уже фиговый треугольник.
            if (!first.is_correct() || !second.is_correct() || !third.is_correct())
            {
                if (!first.is_correct() && !D.is_between(A, B))
                    return false;
                if (!first.is_correct() && D.is_between(A, B))
                    return true;
                if (!second.is_correct() && !D.is_between(D, C))
                    return false;
                if (!second.is_correct() && D.is_between(D, C))
                    return true;
                if (!third.is_correct() && !D.is_between(A, C))
                    return false;
                if (!third.is_correct() && D.is_between(A, C))
                    return true;
            }

            double s1 = square;
            double s2 = first.square + second.square + third.square;
            double dif = s1 - s2;
            if (dif < 0)
                dif *= -1;
            // Ну если сумма площадей равна, то все хорошо
            if (dif < coefficient_error)
            {
                result = true;
            }

            return result;
        }
Beispiel #5
0
 public double getDistance(MyPoint o)
 {
     return Math.Pow((Math.Pow(X - o.X, 2) + Math.Pow(Y - o.Y, 2)), 0.5);
 }
Beispiel #6
0
        private void button_belong_Click(object sender, EventArgs e)
        {
            List<MyPoint> points = new List<MyPoint>();
            string query = textBox_addtr.Text;
            foreach (string xy in query.Split(';'))
            {
                int x = Convert.ToInt32(xy.Split(',')[0]);
                int y = Convert.ToInt32(xy.Split(',')[1]);
                points.Add(new MyPoint(x, y));
            }
            MyTriangle triangle = new MyTriangle(points[0], points[1], points[2]);

            int point_x = Convert.ToInt32(textBox_addp_x.Text);
            int point_y = Convert.ToInt32(textBox_addp_y.Text);
            MyPoint suspect = new MyPoint(point_x, point_y);
            if (triangle.MyPointBelong(suspect))
            {
                MessageBox.Show("Belongs!!!");
            }
            else
            {
                MessageBox.Show("Not Belongs!!!");
            }
        }