Ejemplo n.º 1
0
        //расчет угла между отрезками
        public double VectorAng(segments seg1, segments seg2)
        {
            double x1    = Math.Abs(seg1.x1 - seg1.x2);
            double x2    = Math.Abs(seg2.x1 - seg2.x2);
            double y1    = Math.Abs(seg1.y1 - seg1.y2);
            double y2    = Math.Abs(seg2.y1 - seg2.y2);
            double CosA  = (x1 * x2 + y1 * y2) / (Math.Sqrt(Math.Pow(x1, 2) + Math.Pow(y1, 2)) * Math.Sqrt(Math.Pow(x2, 2) + Math.Pow(y2, 2)));
            double ACosA = Math.Acos(CosA);

            return(ACosA);
        }
Ejemplo n.º 2
0
        //Добавление вектора
        public void AddVector(int x1, int x2, int y1, int y2)
        {
            segments NewSeg = new segments()
            {
                x1   = Convert.ToInt32(x1),
                x2   = Convert.ToInt32(x2),
                y1   = Convert.ToInt32(y1),
                y2   = Convert.ToInt32(y2),
                Name = ("(" + x1 + ";" + y1 + ")(" + x2 + ";" + y2 + ")")
            };

            db.segments.Add(NewSeg);
            db.SaveChanges();
        }
Ejemplo n.º 3
0
        //пересчет координат вектора, в зависимоти от угла и точки поворота
        public void Rotate(double angle, segments seg1, double X, double Y)
        {
            /*
             * X = x * cos(alpha) — y * sin(alpha);
             * Y = x * sin(alpha) + y * cos(alpha);
             */

            double angleRadian = angle * Math.PI / 180;
            double OX1 = seg1.x1, OY1 = seg1.y1, OX2 = seg1.x2, OY2 = seg1.y2;

            seg1.x1 = (OX1 - X) * Math.Cos(angleRadian) - (OY1 - Y) * Math.Sin(angleRadian) + X;
            seg1.y1 = (OX1 - X) * Math.Sin(angleRadian) + (OY1 - Y) * Math.Cos(angleRadian) + Y;
            seg1.x2 = (OX2 - X) * Math.Cos(angleRadian) - (OY2 - Y) * Math.Sin(angleRadian) + X;
            seg1.y2 = (OX2 - X) * Math.Sin(angleRadian) + (OY2 - Y) * Math.Cos(angleRadian) + Y;
        }
Ejemplo n.º 4
0
        //определяет наличие или отсутствие пересечений
        public bool Intersection(segments seg1, segments seg2)
        {
            double x1, x2, x3, x4, y1, y2, y3, y4;
            double Ua, Ub, numerator_a, numerator_b, denominator;

            if (seg1.x2 <= seg1.x1)
            {
                x1 = seg1.x2;
                x2 = seg1.x1;
                y1 = seg1.y2;
                y2 = seg1.y1;
            }
            else
            {
                x1 = seg1.x1;
                x2 = seg1.x2;
                y1 = seg1.y1;
                y2 = seg1.y2;
            }
            if (seg2.x2 <= seg2.x1)
            {
                x3 = seg2.x2;
                x4 = seg2.x1;
                y3 = seg2.y2;
                y4 = seg2.y1;
            }
            else
            {
                x3 = seg2.x1;
                x4 = seg2.x2;
                y3 = seg2.y1;
                y4 = seg2.y2;
            }
            denominator = (y4 - y3) * (x1 - x2) - (x4 - x3) * (y1 - y2);
            if (denominator == 0)
            {
                if ((x1 * y2 - x2 * y1) * (x4 - x3) - (x3 * y4 - x4 * y3) * (x2 - x1) == 0 && (x1 * y2 - x2 * y1) * (y4 - y3) - (x3 * y4 - x4 * y3) * (y2 - y1) == 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                numerator_a = (x4 - x2) * (y4 - y3) - (x4 - x3) * (y4 - y2);
                numerator_b = (x1 - x2) * (y4 - y2) - (x4 - x2) * (y1 - y2);
                Ua          = numerator_a / denominator;
                Ub          = numerator_b / denominator;
                if (Ua >= 0 && Ua <= 1 && Ub >= 0 && Ub <= 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }