Exemplo n.º 1
0
 public bool PointTopLeft(SystemCoordinates x)
 {
     if (vertical)
     {
         if (x.X < b)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         if (k == 0 && x.Y > b)
         {
             return(true);
         }
         if (k == 0)
         {
             return(false);
         }
         SystemCoordinates sss = BuildSecondCoordinate(x.X);
         if (sss.Y > x.Y)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 2
0
        public DoubleExtention DistanceToPoint(SystemCoordinates alpha)
        {
            List <DoubleExtention> dist = new List <DoubleExtention>();

            if (ULimitSet && LLimitSet)
            {
                dist.Add(alpha.Distance(ULimitPoint));
                dist.Add(alpha.Distance(LLimitPoint));
            }
            Line a = new Line(alpha, center);

            a.FirstEnd = center;
            List <SystemCoordinates> p = IntersectionWithInfLine(a);

            //if(IntersectionWithLine(a).Count!=0)
            foreach (var x in p)
            {
                dist.Add(x.Distance(alpha));
            }
            //dist.Add(this.IntersectionWithLine(a)[0].Distance(alpha));
            DoubleExtention min = dist[0];

            foreach (var z in dist)
            {
                if (z < min)
                {
                    min = z;
                }
            }
            return(min);
        }
Exemplo n.º 3
0
 public Line(SystemCoordinates p, Angle alpha)
 {
     if ((DoubleExtention)alpha == 90 || (DoubleExtention)alpha == 270)
     {
         vertical = true;
         b        = p.X;
         k        = 2000000000;
     }
     else
     if ((DoubleExtention)alpha == 0 || (DoubleExtention)alpha == 180)
     {
         b        = p.Y;
         k        = 0;
         vertical = false;
     }
     else
     {
         k = alpha.tg();
         DoubleExtention ty = k * p.X;
         DoubleExtention tb = p.Y - ty;
         b        = tb;
         vertical = false;
     }
     FirstEnd = p;
     AngleForOnePointLines = alpha;
 }
Exemplo n.º 4
0
        public Circle(SystemCoordinates p1, SystemCoordinates p2, SystemCoordinates p3)
        {
            DoubleExtention x1    = p1.X;
            DoubleExtention x2    = p2.X;
            DoubleExtention x3    = p3.X;
            DoubleExtention y1    = p1.Y;
            DoubleExtention y2    = p2.Y;
            DoubleExtention y3    = p3.Y;
            DoubleExtention alpha = (x1 * x1 + y1 * y1 - x3 * x3 - y3 * y3) / 2;
            DoubleExtention betaa = (x2 * x2 + y2 * y2 - x3 * x3 - y3 * y3) / 2;
            DoubleExtention b;
            DoubleExtention a;

            if (x1 == x3)
            {
                b = alpha / (y1 - y3);
                a = (betaa - b * (y2 - y3)) / (x2 - x3);
            }
            else
            if (x2 == x3)
            {
                b = betaa / (y2 - y3);
                a = (alpha - b * (y1 - y3)) / (x1 - x3);
            }
            else
            {
                DoubleExtention gamma  = alpha / (x1 - x3) - betaa / (x2 - x3);
                DoubleExtention lambda = (y1 - y3) / (x1 - x3) - (y2 - y3) / (x2 - x3);
                b = gamma / lambda;
                a = (alpha - b * (y1 - y3)) / (x1 - x3);
            }
            center = new SystemCoordinates(a, b);
            radius = center.Distance(p1);
            Line Z = new Line(center, p1, false);

            Z.BuildAngle();
            UpperLimitAngle = Z.AngleForOnePointLines;
            Z = new Line(center, p3, false);
            Z.BuildAngle();
            LowerLimitAngle = Z.AngleForOnePointLines;
            while (lowerLimitAngle > upperLimitAngle)
            {
                lowerLimitAngle -= (Math.PI * 2);
            }
            if (!PointIsBetweenEdges(p2))
            {
                DoubleExtention t = lowerLimitAngle;
                lowerLimitAngle = upperLimitAngle;
                upperLimitAngle = t;
                while (lowerLimitAngle > upperLimitAngle)
                {
                    lowerLimitAngle -= (Math.PI * 2);
                }
                while (upperLimitAngle < 0)
                {
                    lowerLimitAngle += (Math.PI * 2);
                    upperLimitAngle += (Math.PI * 2);
                }
            }
        }
Exemplo n.º 5
0
        public DoubleExtention Distance(SystemCoordinates point)
        {
            DoubleExtention a = (this.x - point.X) * (this.x - point.X) + (this.y - point.Y) * (this.y - point.Y);

            a.sqrt_set();
            return(a);
        }
Exemplo n.º 6
0
        public Line BuildKasatelnaya(SystemCoordinates p)
        {
            Line Radius = new Line(p, center, false);

            Radius.BuildAngle();
            Line ret = Radius.BuildOrthogonalLine(p);

            ret.BuildAngle();
            return(ret);
        }
Exemplo n.º 7
0
        public SystemCoordinates BuildPointReflection(SystemCoordinates point)
        {
            DoubleExtention a = point.X;

            a       -= this.x;
            point.X -= (2 * a);
            a        = point.Y;
            a       -= this.y;
            point.Y -= (2 * a);
            return(point);
        }
Exemplo n.º 8
0
 public void MoveTo(SystemCoordinates from, SystemCoordinates to)
 {
     center.X += to.X - from.X;
     center.Y += to.Y - from.Y;
     for (int aa = 0; aa < ringCol.Length; aa++)
     {
         ringCol[aa].X += to.X - from.X;
         ringCol[aa].Y += to.Y - from.Y;
     }
     lineCol = new Line[ringCol.Length];
     for (int aa = 0; aa < ringCol.Length - 1; aa++)
     {
         lineCol[aa] = new Line(ringCol[aa].Clone(), ringCol[aa + 1].Clone(), false);
     }
     lineCol[ringCol.Length - 1] = new Line(ringCol[ringCol.Length - 1].Clone(), ringCol[0].Clone(), false);
 }
Exemplo n.º 9
0
 public Line(SystemCoordinates p1, SystemCoordinates p2, bool Infinite = true)
 {
     if (p1.X == p2.X)
     {
         vertical = true;
         k        = 2000000000;
         b        = p1.X;
     }
     else
     {
         k        = (p2.Y - p1.Y) / (p2.X - p1.X);
         b        = -((p2.Y - p1.Y) / (p2.X - p1.X)) * p1.X + p1.Y;
         vertical = false;
     }
     if (Infinite == false)
     {
         FirstEnd  = p1;
         SecondEnd = p2;
     }
 }
Exemplo n.º 10
0
        public static bool InOneLine(SystemCoordinates p1, SystemCoordinates p2, SystemCoordinates p3)
        {
            Line l = p1 + p2;

            if (l.Vertical && p3.X == p1.X && p2.X == p1.X)
            {
                return(true);
            }
            if (l.Vertical)
            {
                return(false);
            }
            if (l.BuildSecondCoordinate(p3.X).Y == p3.Y)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 11
0
 public bool PointIsBetweenEdges(SystemCoordinates point)
 {
     if (LLimitSet && ULimitSet)
     {
         Line a = new Line(center, point, false);
         a.BuildAngle();
         DoubleExtention b = a.AngleForOnePointLines.GetInRadians();
         if ((b >= lowerLimitAngle && b <= upperLimitAngle) || ((b - Math.PI * 2) >= lowerLimitAngle && (b - Math.PI * 2) <= upperLimitAngle) || ((b + Math.PI * 2) >= lowerLimitAngle && (b + Math.PI * 2) <= upperLimitAngle))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 12
0
        public Line IntersectWithLine(Line toIntersect, out bool intersects, out SystemCoordinates point)
        {
            DoubleExtention   dst;
            SystemCoordinates s;
            bool isIsecting = false;
            Line isector    = Line.Zero;

            point = SystemCoordinates.Zero;
            DoubleExtention distane = 10000;

            foreach (var x in lineCol)
            {
                bool isect;
                bool equal;
                s = x.IntersectWithLine(toIntersect, out isect, out equal);
                if (isect)
                {
                    if (isIsecting == false)
                    {
                        isIsecting = true;
                        isector    = x;
                        distane    = s.Distance(toIntersect.FirstEnd);
                        point      = s;
                    }
                    else
                    {
                        dst = s.Distance(toIntersect.FirstEnd);
                        if (dst < distane)
                        {
                            isector = x;
                            distane = dst;
                            point   = s;
                        }
                    }
                }
            }
            intersects = isIsecting;
            return(isector);
        }
Exemplo n.º 13
0
 public SystemCoordinates IntersectWithLine(Line line, out bool intersect, out bool equal)
 {
     if (line.Vertical == true)
     #region This line is vertical
     {
         if (this.Vertical == true)
         {
             if (this.B == line.B)
             {
                 intersect = true;
                 equal     = true;
                 return(SystemCoordinates.Zero);
             }
             else
             {
                 intersect = false;
                 equal     = false;
                 return(SystemCoordinates.Zero);
             }
         }
     }
     #endregion
     #region This line is not vertical
     else
     {
         intersect = true;
         equal     = false;
         SystemCoordinates toReturn = new SystemCoordinates(line.B, this.K * line.B + this.B);
         if (IsBetweenEnds(toReturn) && line.IsBetweenEnds(toReturn))
         {
             return(toReturn);
         }
         else
         {
             intersect = false;
             return(SystemCoordinates.Zero);
         }
     }
Exemplo n.º 14
0
 public Line BuildOrthogonalLine(SystemCoordinates a)
 {
     if (vertical == true)
     {
         if (a.X != b)
         {
             return(new Line(a, new SystemCoordinates(b, a.Y)));
         }
         else
         {
             return(new Line(new SystemCoordinates(a.X - 1, a.Y), new SystemCoordinates(b, a.Y)));
         }
     }
     else
     if (k != 0)
     {
         return(new Line(-1 / K, a.Y - (-1 / K) * a.X));
     }
     else
     {
         return(new Line(a.X));
     }
 }
Exemplo n.º 15
0
        public DoubleExtention DistanceToPoint(SystemCoordinates x)
        {
            Line X = BuildOrthogonalLine(x);
            bool Intersect, Equal;
            SystemCoordinates alpha = X.IntersectWithLine(this, out Intersect, out Equal);

            if (Intersect == true)
            {
                return(alpha.Distance(x));
            }
            else
            {
                if (firstEndSet && secondEndSet)
                {
                    return(Math.Min(x.Distance(firstEnd), x.Distance(secondEnd)));
                }
                if (firstEndSet)
                {
                    return(x.Distance(firstEnd));
                }
                return(x.Distance(secondEnd));
            }
        }
Exemplo n.º 16
0
        public Line BuildKasatelnaya(Line Intersect, out bool PointFound, out SystemCoordinates IntersectPoint)
        {
            try
            {
                var points_i   = this.IntersectionWithLine(Intersect);
                var points_inf = this.IntersectionWithInfLine(Intersect);
                if (points_i.Count == 0)
                {
                    PointFound     = false;
                    IntersectPoint = SystemCoordinates.Zero;
                    return(Line.Zero);
                }
                if (points_i.Count == 1 && points_inf.Count == 1 && ULimitSet == false)
                {
                    PointFound     = false;
                    IntersectPoint = SystemCoordinates.Zero;
                    return(Line.Zero);
                }
                SystemCoordinates point;
                if (points_i.Count == 1)
                {
                    point = points_i[0];
                }
                else if (points_i.Count == 2)
                {
                    if (Intersect.FirstEndSet)
                    {
                        DoubleExtention d = Intersect.FirstEnd.Distance(points_i[0]);
                        if (d > Intersect.FirstEnd.Distance(points_i[1]))
                        {
                            point = points_i[1];
                        }
                        else
                        {
                            point = points_i[0];
                        }
                    }
                    else
                    {
                        DoubleExtention d = Intersect.SecondEnd.Distance(points_i[0]);
                        if (d > Intersect.SecondEnd.Distance(points_i[1]))
                        {
                            point = points_i[1];
                        }
                        else
                        {
                            point = points_i[0];
                        }
                    }
                }
                else
                {
                    point = points_i[0];
                }
                IntersectPoint = point;
                Line prlLine = this.BuildKasatelnaya(point);
                PointFound = true;
                return(prlLine);
            }

            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 17
0
        public List <SystemCoordinates> IntersectionWithLine(Line line)
        {
            List <SystemCoordinates> ToReturn = new List <SystemCoordinates>();

            if (line.Vertical == true)
            {
                //Якщо пряма вертикальна, то line.B == X;
                if ((line.B < (center.X - radius)) || (line.B > (center.X + radius)))
                {
                    //Якщо вертикальня лінія не торкається кола - нічого не робимо
                }
                else
                if ((line.B == (center.X - radius)) || (line.B == (center.X + radius)))
                {
                    //Якщо вертикальня лінія дотикаєтся до кола - додаємо координати дотику
                    SystemCoordinates Coords = new SystemCoordinates(line.B, center.Y);
                    ToReturn.Add(Coords);
                }
                else
                if (line.B == center.X)
                {
                    //Якщо вертикальня лінія перетинає коло по діаметру - додаємо координати перетину
                    ToReturn.Add(new SystemCoordinates(line.B, center.Y + radius));
                    ToReturn.Add(new SystemCoordinates(line.B, center.Y - radius));
                }
                else
                {
                    //Якщо вертикальня лінія перетинає коло не по діаметру - додаємо координати перетину
                    ToReturn.Add(new SystemCoordinates(line.B, center.Y + Math.Sqrt(radius * radius - (line.B - center.X) * (line.B - center.X))));
                    ToReturn.Add(new SystemCoordinates(line.B, center.Y - Math.Sqrt(radius * radius - (line.B - center.X) * (line.B - center.X))));
                }
            }
            else
            {
                //Якщо пряма не вертикальна, то використовуємо формули, виведені з таких двох рівнянь:
                //y = k*x + b
                //(x-a)^2 + (y-b)^2 = R^2
                DoubleExtention C = -(radius * radius - center.X * center.X - center.Y * center.Y - line.B * line.B +
                                      2 * line.B * center.Y);
                DoubleExtention B = 2 * (line.K * line.B - center.X - line.K * center.Y);
                DoubleExtention A = 1 + line.K * line.K;
                DoubleExtention D = B * B - 4 * A * C;
                if (D == 0) //Якщо пряма дотикається до кола
                {
                    DoubleExtention X = -B / (2 * A);
                    DoubleExtention Y = line.K * X + line.B;
                    ToReturn.Add(new SystemCoordinates(X, Y));
                }
                else if (D > 0) //Якщо пряма пернетинає коло
                {
                    DoubleExtention X1 = (-B + D.sqrt()) / (2 * A);
                    DoubleExtention X2 = (-B - D.sqrt()) / (2 * A);
                    ToReturn.Add(new SystemCoordinates(X1, line.K * X1 + line.B));
                    ToReturn.Add(new SystemCoordinates(X2, line.K * X2 + line.B));
                }
            }
            List <SystemCoordinates> Toreturn = new List <SystemCoordinates>();

            foreach (var e in ToReturn)
            {
                if (line.IsBetweenEnds(e))
                {
                    Toreturn.Add(e);
                }
            } //Перевірка на належність отриманих координат прямій (бо пряма може бути променєм або відрізком)
            if (ULimitSet && LLimitSet)
            {
                List <SystemCoordinates> a = new List <SystemCoordinates>();
                foreach (var z in Toreturn)
                {
                    if (PointIsBetweenEdges(z))
                    {
                        a.Add(z);
                    }
                }
                Toreturn = a;
            } //Перевірка на належність отриманих координат колу (бо коло може бути лише частиною кола, а не повним колом)
            return(Toreturn);
        }
Exemplo n.º 18
0
        public void MoveTo(SystemCoordinates from, SystemCoordinates to)
        {
            SystemCoordinates diff = to - from;

            center = new SystemCoordinates(center.X + diff.X, center.Y + diff.Y);
        }
Exemplo n.º 19
0
 public Circle(SystemCoordinates Center, DoubleExtention Radius)
 {
     center = Center;
     radius = Radius;
 }
Exemplo n.º 20
0
 public SystemCoordinates(SystemCoordinates Coords)
 {
     x = Coords.X;
     y = Coords.Y;
 }
Exemplo n.º 21
0
        public List <SystemCoordinates> IntersectionWithInfLine(Line line)
        {
            List <SystemCoordinates> ToReturn = new List <SystemCoordinates>();

            if (line.Vertical == true)
            {
                if ((line.B < (center.X - radius)) || (line.B > (center.X + radius)))
                {
                    //return ToReturn;
                }
                else
                if ((line.B == (center.X - radius)) || (line.B == (center.X + radius)))
                {
                    //List<SystemCoordinates> ToReturn = new List<SystemCoordinates>();
                    SystemCoordinates Coords = new SystemCoordinates(line.B, center.Y);
                    ToReturn.Add(Coords);
                    //return ToReturn;
                }
                else
                if (line.B == center.X)
                {
                    //List<SystemCoordinates> ToReturn = new List<SystemCoordinates>();
                    ToReturn.Add(new SystemCoordinates(line.B, center.Y + radius));
                    ToReturn.Add(new SystemCoordinates(line.B, center.Y - radius));
                    //return ToReturn;
                }
                else
                {
                    //List<SystemCoordinates> ToReturn = new List<SystemCoordinates>();
                    ToReturn.Add(new SystemCoordinates(line.B, center.Y + Math.Sqrt(radius * radius - (line.B - center.X) * (line.B - center.X))));
                    ToReturn.Add(new SystemCoordinates(line.B, center.Y - Math.Sqrt(radius * radius - (line.B - center.X) * (line.B - center.X))));
                    //return ToReturn;
                }
            }
            else
            {
                /*DoubleExtention a = line.K * line.K + 1;
                 * DoubleExtention b = center.X - line.K * line.B + line.K * center.Y;
                 * DoubleExtention c = center.X * center.X + (center.Y - line.B) * (center.Y - line.B) - radius * radius;
                 * DoubleExtention x1 = (-b + Math.Sqrt(b * b - a * c)) / a;
                 * DoubleExtention x2 = (-b - Math.Sqrt(b * b - a * c)) / a;
                 * DoubleExtention y1 = line.K * x1 + line.B;
                 * DoubleExtention y2 = line.K * x2 + line.B;*/
                DoubleExtention C = -(radius * radius - center.X * center.X - center.Y * center.Y - line.B * line.B +
                                      2 * line.B * center.Y);
                DoubleExtention B = 2 * (line.K * line.B - center.X - line.K * center.Y);
                DoubleExtention A = 1 + line.K * line.K;
                DoubleExtention D = B * B - 4 * A * C;
                if (D == 0)
                {
                    DoubleExtention X = -B / (2 * A);
                    DoubleExtention Y = line.K * X + line.B;
                    ToReturn.Add(new SystemCoordinates(X, Y));
                }
                else if (D > 0)
                {
                    DoubleExtention X1 = (-B + D.sqrt()) / (2 * A);
                    DoubleExtention X2 = (-B - D.sqrt()) / (2 * A);
                    ToReturn.Add(new SystemCoordinates(X1, line.K * X1 + line.B));
                    ToReturn.Add(new SystemCoordinates(X2, line.K * X2 + line.B));
                }
                //List<SystemCoordinates> ToReturn = new List<SystemCoordinates>();

                /*ToReturn.Add(new SystemCoordinates(x1, y1));
                *  ToReturn.Add(new SystemCoordinates(x2, y2));*/
                //return ToReturn;
            }
            if (ULimitSet && LLimitSet)
            {
                List <SystemCoordinates> a = new List <SystemCoordinates>();
                foreach (var z in ToReturn)
                {
                    if (PointIsBetweenEdges(z))
                    {
                        a.Add(z);
                    }
                }
                ToReturn = a;
            }
            return(ToReturn);
        }
Exemplo n.º 22
0
 /// <summary>
 /// Конвертация координат из системных в экранные и наоборот
 /// </summary>
 /// <param name="Point">Точка в системе</param>
 /// <returns></returns>
 public Point Converter(SystemCoordinates Point)
 {
     return(Converter(Point.X, Point.Y));
 }