예제 #1
0
 private CoordinateSystem()
 {
     differenceX = 0;
     differenceY = 0;
     sizesSet    = false;
     Configuration.Config.NewConfig += new EventHandler <EventArguments.ConfigurationChangeArgs>(Config_NewConfig);
 }
예제 #2
0
        public Polygon(SystemCoordinates[] ring)
        {
            DoubleExtention minX = ring[0].X, maxX = ring[0].X, minY = ring[0].Y, maxY = ring[0].Y;

            lineCol = new Line[ring.Length];
            for (int i = 0; i < ring.Length - 1; i++)
            {
                lineCol[i] = new Line(ring[i].Clone(), ring[i + 1].Clone(), false);
                minX       = DoubleExtention.MinimumOf(minX, ring[i].Clone().X);
                maxX       = DoubleExtention.MaximumOf(maxX, ring[i].Clone().X);
                minY       = DoubleExtention.MinimumOf(minY, ring[i].Clone().Y);
                maxY       = DoubleExtention.MaximumOf(maxY, ring[i].Clone().Y);
            }
            lineCol[ring.Length - 1] = new Line(ring[ring.Length - 1].Clone(), ring[0].Clone(), false);
            minX     = DoubleExtention.MinimumOf(minX, ring[ring.Length - 1].X);
            maxX     = DoubleExtention.MaximumOf(maxX, ring[ring.Length - 1].X);
            minY     = DoubleExtention.MinimumOf(minY, ring[ring.Length - 1].Y);
            maxY     = DoubleExtention.MaximumOf(maxY, ring[ring.Length - 1].Y);
            center.X = (maxX + minX) / 2;
            center.Y = (maxY + minY) / 2;
            ringCol  = new SystemCoordinates[ring.Length];
            for (int i = 0; i < ring.Length; i++)
            {
                ringCol[i] = ring[i].Clone();
            }
        }
예제 #3
0
        public Mirror(string Name, SystemCoordinates Center, Angle Anglee, DoubleExtention Length)
        {
            angle       = Anglee;
            name        = Name;
            coordinates = Center;
            length      = Length;

            if (((DoubleExtention)angle != (DoubleExtention)90) && ((DoubleExtention)angle != (DoubleExtention)270))
            {
                DoubleExtention y = Center.X * angle.tg();
                DoubleExtention b = Center.Y - y;
                ToDraw           = new Line(angle.tg(), b); ToDraw.AngleForOnePointLines = angle;
                ToDraw.FirstEnd  = new SystemCoordinates((length / 2) * angle.cos() + Center.X, (length / 2) * angle.sin() + Center.Y);
                ToDraw.SecondEnd = Center.BuildPointReflection(ToDraw.FirstEnd);
            }
            else
            {
                ToDraw = new Line(Center.X);
                if ((DoubleExtention)angle == (DoubleExtention)90)
                {
                    ToDraw.FirstEnd  = new SystemCoordinates(Center.X, Center.Y + length / 2); ToDraw.AngleForOnePointLines = angle;
                    ToDraw.SecondEnd = Center.BuildPointReflection(ToDraw.FirstEnd);
                }
                if ((DoubleExtention)angle == (DoubleExtention)270)
                {
                    ToDraw.FirstEnd  = new SystemCoordinates(Center.X, Center.Y - length / 2); ToDraw.AngleForOnePointLines = angle;
                    ToDraw.SecondEnd = Center.BuildPointReflection(ToDraw.FirstEnd);
                }
            }
        }
예제 #4
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);
        }
예제 #5
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);
                }
            }
        }
예제 #6
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);
        }
예제 #7
0
        public static void Draw(Angle angle, SystemCoordinates SecondEnd, SystemCoordinates FirstEnd, bool Selected = false)
        {
            Point p1 = CoordinateSystem.Instance.Converter(SecondEnd);

            p1.Y += (int)(3 * angle.cos());
            p1.X += (int)(3 * angle.sin());
            Point pp1 = new Point(p1.X + (int)(Math.Ceiling(2 * angle.sin() * (-1))), p1.Y - (int)(Math.Ceiling(2 * angle.cos())));

            if (angle.GetInDegrees() >= 69 && angle.GetInDegrees() <= 90)
            {
                pp1.Y += 1;
            }
            DoubleExtention d = FirstEnd.Distance(SecondEnd);

            d *= CoordinateSystem.Instance.Scale;
            int   length = (int)d;
            Point p2     = new Point((int)(length * angle.cos()) + p1.X, (int)(length * angle.sin() * (-1)) + p1.Y);
            Point pp2    = new Point((int)(length * angle.cos()) + pp1.X, (int)(length * angle.sin() * (-1)) + pp1.Y);

            LineDrawer.DrawLine(p1, p2, Color.Red, 5);
            if (Selected)
            {
                LineDrawer.DrawLine(pp1, pp2, Color.Blue, 3);
            }
            else
            {
                LineDrawer.DrawLine(pp1, pp2, Color.Black, 3);
            }
        }
예제 #8
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;
 }
예제 #9
0
 public OPolygon(Polygon pl, DoubleExtention density, string name)
 {
     poly         = pl;
     this.density = density;
     this.name    = name;
     coordinates  = poly.Center.Clone();
 }
예제 #10
0
        public Mirror(string SaveStr)
        {
            string[] splitted = SaveStr.Split('^');
            if (splitted.Length != 7)
            {
                throw new OpticalBuilderLib.Exceptions.ErrorWhileReading();
            }
            try
            {
                string            Name   = splitted[1];
                SystemCoordinates Center = new SystemCoordinates(Convert.ToDouble(splitted[2]), Convert.ToDouble(splitted[3]));
                Angle             Anglee = Convert.ToDouble(splitted[4]);
                DoubleExtention   Length = Convert.ToDouble(splitted[5]);
                id          = Convert.ToInt32(splitted[6]);
                angle       = Anglee;
                name        = Name;
                coordinates = Center;
                length      = Length;
                if (((DoubleExtention)angle != (DoubleExtention)90) && ((DoubleExtention)angle != (DoubleExtention)270))
                {
                    DoubleExtention y = Center.X * angle.tg();
                    DoubleExtention b = Center.Y - y;
                    ToDraw = new Line(angle.tg(), b);
                }
                else
                {
                    ToDraw = new Line(Center.X);
                }
                if (((DoubleExtention)angle != (DoubleExtention)90) && ((DoubleExtention)angle != (DoubleExtention)270))
                {
                    DoubleExtention y = Center.X * angle.tg();
                    DoubleExtention b = Center.Y - y;
                    ToDraw           = new Line(angle.tg(), b);
                    ToDraw.FirstEnd  = new SystemCoordinates((length / 2) * angle.cos() + Center.X, (length / 2) * angle.sin() + Center.Y);
                    ToDraw.SecondEnd = Center.BuildPointReflection(ToDraw.FirstEnd);
                }
                else
                {
                    ToDraw = new Line(Center.X);
                    if ((DoubleExtention)angle == (DoubleExtention)90)
                    {
                        ToDraw.FirstEnd  = new SystemCoordinates(Center.X, Center.Y + length / 2);
                        ToDraw.SecondEnd = Center.BuildPointReflection(ToDraw.FirstEnd);
                    }
                    if ((DoubleExtention)angle == (DoubleExtention)270)
                    {
                        ToDraw.FirstEnd  = new SystemCoordinates(Center.X, Center.Y - length / 2);
                        ToDraw.SecondEnd = Center.BuildPointReflection(ToDraw.FirstEnd);
                    }
                }

                ToDraw.AngleForOnePointLines = angle;
            }
            catch
            {
                throw new OpticalBuilderLib.Exceptions.ErrorWhileReading();
            }
        }
예제 #11
0
 public SphereMirror(string name, SystemCoordinates coords, DoubleExtention R, SystemCoordinates p1, SystemCoordinates p2, SystemCoordinates p3, bool Vognutoye)
 {
     this.name   = name;
     coordinates = coords;
     r           = R;
     a           = new Circle(p1, p2, p3);
     this.p2     = p2;
     vognutoye   = Vognutoye;
 }
예제 #12
0
 public Sphere(string name, SystemCoordinates coords, DoubleExtention R, DoubleExtention od)
 {
     this.name   = name;
     coordinates = coords;
     r           = R;
     //this.id = id;
     a = new Circle(coords, R);
     opticaldensity = od;
 }
예제 #13
0
 public static void DrawFilledCircle(Pen pen, Point center, DoubleExtention r)
 {
     Gl.glColor4f((float)(pen.Color.R) / 255, (float)(pen.Color.G) / 255, (float)(pen.Color.B) / 255,
                  (float)1);
     Gl.glPointSize(pen.Width > (float)r ? pen.Width:(float)r);
     Gl.glBegin(Gl.GL_POINTS);
     Gl.glVertex2i(center.X, center.Y);
     Gl.glEnd();
 }
예제 #14
0
        public static Angle operator -(Angle a1, Angle a2)
        {
            double angle = a1.GetInDegrees() - a2.GetInDegrees();

            if (angle < 0)
            {
                angle += 360;
            }
            return(new Angle(angle, false));
        }
예제 #15
0
        public static Angle operator +(Angle a1, Angle a2)
        {
            double angle = a1.GetInDegrees() + a2.GetInDegrees();

            if (angle > 360)
            {
                angle -= 360;
            }
            return(new Angle(angle, false));
        }
예제 #16
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);
        }
예제 #17
0
 public Line BuildOrthogonalLine_save(DoubleExtention X, DoubleExtention Y)
 {
     if (vertical == false)
     {
         return(BuildOrthogonalLineX(X));
     }
     else
     {
         return(BuildOrthogonalLineY(Y));
     }
 }
예제 #18
0
 public static void DrawCircle(Pen pen, Point center, DoubleExtention r)
 {
     Gl.glColor4f((float)(pen.Color.R) / 255, (float)(pen.Color.G) / 255, (float)(pen.Color.B) / 255,
                  (float)1);
     Gl.glLineWidth(pen.Width);
     Gl.glBegin(Gl.GL_LINE_STRIP);
     for (float i = 0; i <= Math.PI * 2; i += 0.01f)
     {
         Gl.glVertex2d(center.X + r * Math.Cos(i), center.Y + r * Math.Sin(i));
     }
     Gl.glEnd();
 }
예제 #19
0
        /// <summary>
        /// Конвертация координат из системных в экранные и наоборот
        /// </summary>
        /// <param name="X">Точка на экране (координата X)</param>
        /// <param name="Y">Точка на экране (координата Y)</param>
        /// <returns></returns>
        public SystemCoordinates Converter(int X, int Y)
        {
            DoubleExtention x = X, y = Y;

            x -= centerX;
            x /= scale;
            y  = screenHeight - y;
            y -= centerY;
            y /= scale;
            x += differenceX;
            y += differenceY;
            return(new SystemCoordinates(x, y));
        }
예제 #20
0
        /// <summary>
        /// Конвертация координат из системных в экранные и наоборот
        /// </summary>
        /// <param name="SystemX">Системный Х</param>
        /// <param name="SystemY">Системный Y</param>
        /// <returns>Точка на элементе рисования</returns>
        public Point Converter(DoubleExtention SystemX, DoubleExtention SystemY)
        {
            if (sizesSet == false)
            {
                Exception e = new Exception("Система не инициализирована. Выполните команду ObjectCollection.GetSystem().ResetSizes()");
                throw e;
            }
            SystemX -= differenceX;
            SystemY -= differenceY;
            int ScreenX = (int)(SystemX * scale) + centerX;
            int ScreenY = (screenHeight - (int)(SystemY * scale)) - centerY;

            return(new Point(ScreenX, ScreenY));
        }
예제 #21
0
        public override int DistanceToPointS(Point X)
        {
            Line alpha = CoordinateSystem.Instance.Converter(X) + coordinates;
            List <SystemCoordinates> t = a.IntersectionWithInfLine(alpha);
            DoubleExtention          d = t[0].Distance(CoordinateSystem.Instance.Converter(X));

            foreach (var systemCoordinatese in t)
            {
                if (d > systemCoordinatese.Distance(CoordinateSystem.Instance.Converter(X)))
                {
                    d = systemCoordinatese.Distance(CoordinateSystem.Instance.Converter(X));
                }
            }
            return((int)(d * CoordinateSystem.Instance.Scale));
        }
예제 #22
0
        public override void Rotate(SystemCoordinates to, SystemCoordinates from)
        {
            Angle           fromm, too;
            DoubleExtention dst =
                ((from.X - poly.Center.X) * (from.X - poly.Center.X) + (from.Y - poly.Center.Y) * (from.Y - poly.Center.Y)).
                sqrt();

            fromm = new Angle((from.Y - poly.Center.Y) / dst, (from.X - poly.Center.X) / dst);
            dst   =
                ((to.X - poly.Center.X) * (to.X - poly.Center.X) + (to.Y - poly.Center.Y) * (to.Y - poly.Center.Y)).
                sqrt();
            too = new Angle((to.Y - poly.Center.Y) / dst, (to.X - poly.Center.X) / dst);
            poly.Rotate(new Angle(too.GetInDegrees() - fromm.GetInDegrees(), false));
            coordinates = poly.Center.Clone();
        }
예제 #23
0
파일: Ray.cs 프로젝트: hotab/OpticalBuilder
 public int DistanceToPointS(SystemCoordinates X)
 {
     if (LineArray.Count > 0)
     {
         DoubleExtention a = LineArray[0].DistanceToPoint(X);
         foreach (var line in LineArray)
         {
             a = Math.Min(a, line.DistanceToPoint(X));
         }
         return((int)Math.Ceiling(a * CoordinateSystem.Instance.Scale));
     }
     else
     {
         return(-1);
     }
 }
예제 #24
0
파일: Ray.cs 프로젝트: hotab/OpticalBuilder
 public DoubleExtention DistanceToPoint(SystemCoordinates X)
 {
     if (LineArray.Count > 0)
     {
         DoubleExtention a = LineArray[0].DistanceToPoint(X);
         foreach (var line in LineArray)
         {
             a = Math.Min(a, line.DistanceToPoint(X));
         }
         return(a);
     }
     else
     {
         return(-1);
     }
 }
예제 #25
0
        public override int DistanceToPointS(Point X)
        {
            Line[]          z   = poly.Lines;
            DoubleExtention dst = z[0].DistanceToPoint(X);
            DoubleExtention tmp;

            for (int i = 1; i < z.Length; i++)
            {
                tmp = z[i].DistanceToPoint(X);
                if (tmp < dst)
                {
                    dst = tmp;
                }
            }
            dst *= CoordinateSystem.Instance.Scale;
            return(dst.ToInt32());
        }
예제 #26
0
 public SphereMirror(string savestring)
 {
     string[] saves = savestring.Split('^');
     if (saves.Length != 13)
     {
         //TODO: Generate error
     }
     else
     {
         name        = saves[1];
         coordinates = new SystemCoordinates(Convert.ToDouble(saves[2]), Convert.ToDouble(saves[3]));
         r           = Convert.ToDouble(saves[4]);
         id          = Convert.ToInt32(saves[5]);
         a           = new Circle(new SystemCoordinates(Convert.ToDouble(saves[10]), Convert.ToDouble(saves[11])), new SystemCoordinates(Convert.ToDouble(saves[8]), Convert.ToDouble(saves[9])), new SystemCoordinates(Convert.ToDouble(saves[6]), Convert.ToDouble(saves[7])));
         p2          = new SystemCoordinates(Convert.ToDouble(saves[8]), Convert.ToDouble(saves[9]));
         vognutoye   = Convert.ToBoolean(saves[12]);
     }
 }
예제 #27
0
 public static void DrawCirclePart(Pen pen, Point center, DoubleExtention r, DoubleExtention l1, DoubleExtention l2)
 {
     Gl.glColor4f((float)(pen.Color.R) / 255, (float)(pen.Color.G) / 255, (float)(pen.Color.B) / 255,
                  (float)1);
     Gl.glLineWidth(pen.Width);
     Gl.glBegin(Gl.GL_LINE_STRIP);
     if (l1 > l2)
     {
         DoubleExtention tmp = l1;
         l1 = l2;
         l2 = tmp;
     }
     for (DoubleExtention i = l1; i <= l2; i += 0.005)
     {
         Gl.glVertex2d(center.X + r * Math.Cos(i), center.Y - r * Math.Sin(i));
     }
     Gl.glEnd();
 }
예제 #28
0
 public Sphere(string savestring)
 {
     //Name^X^Y^R^id;
     string[] saves = savestring.Split('^');
     if (saves.Length != 7)
     {
         //TODO: Generate error
     }
     else
     {
         name           = saves[1];
         coordinates    = new SystemCoordinates(Convert.ToDouble(saves[2]), Convert.ToDouble(saves[3]));
         r              = Convert.ToDouble(saves[4]);
         id             = Convert.ToInt32(saves[5]);
         a              = new Circle(coordinates, r);
         opticaldensity = Convert.ToDouble(saves[6]);
     }
 }
예제 #29
0
 public Line(Line a)
 {
     this.k   = a.k;
     this.b   = a.b;
     vertical = a.Vertical;
     if (a.FirstEndSet)
     {
         this.FirstEnd = a.FirstEnd;
     }
     if (a.SecondEndSet)
     {
         this.SecondEnd = a.SecondEnd;
     }
     if (a.AngleSet)
     {
         BuildAngle();
     }
 }
예제 #30
0
        public OPolygon(string savestr)
        {
            string[] splitted = savestr.Split('^');
            name = splitted[1];
            int count = Convert.ToInt32(splitted[3]);

            SystemCoordinates[] arr = new SystemCoordinates[count];
            density = Convert.ToDouble(splitted[2]);
            for (int i = 0; i < count; i++)
            {
                DoubleExtention x = Convert.ToDouble(splitted[2 * i + 4]);
                DoubleExtention y = Convert.ToDouble(splitted[2 * i + 5]);
                arr[i].X = x;
                arr[i].Y = y;
            }
            poly        = new Polygon(arr);
            coordinates = poly.Center.Clone();
        }