public MainForm() { InitializeComponent(); region = new Polygon2d(); region.Add(new Point2d()); region.Add(new Point2d { X = ClientRectangle.Width }); region.Add(new Point2d { X = ClientRectangle.Width, Y = ClientRectangle.Height }); region.Add(new Point2d { Y = ClientRectangle.Height }); #region Шаг 1. Создаём начальную модель, состоящую из сторон прямоугольника. // TODO: Переделать на многольник. List<Plane2d> borders = new List<Plane2d>(); for (int i = 0; i < region.Count; i++) borders.Add(new Plane2d { Pole = region[i].Copy, Normal = (region[i + 1] - region[i])._I_(false) }); vertex = Vertex<Geometric>.CreateClosenessModel(borders[0], borders[1], borders[2]); vertex.BreakCrosBy(borders[3]); #endregion #region Шаг 2. Устанавливаем для полученных троек круги Делоне. !!Нужно ли автоматизировать?!! vertex.SetCircleDelone(new Circle { Pole = new Point2d { X = ClientRectangle.Width - ClientRectangle.Height / 2, Y = ClientRectangle.Height / 2 }, Scalar = ClientRectangle.Height / 2 }); vertex.Cros.SetCircleDelone(new Circle { Pole = new Point2d { X = ClientRectangle.Height / 2, Y = ClientRectangle.Height / 2 }, Scalar = ClientRectangle.Height / 2 }); //vertex.SetCircleDelone(Assistant.КРУГ_ДЕЛОНЕ(borders[0], borders[1], borders[2])); //vertex.Cros.SetCircleDelone(Assistant.КРУГ_ДЕЛОНЕ(borders[2], borders[3], borders[0])); vertex.Prev.Cros.SetCircleDelone(new Circle()); vertex.Cros.Prev.Cros.SetCircleDelone(new Circle()); #endregion rand = new Random(); triples = ClosenessModelExt<Geometric, Circle>.GetTriples(this.vertex); }
public FormMain() { InitializeComponent(); polygon_list = new List<Polygon2d>(); polygon = null; is_edit = false; #region Тестовый вариант. pole = new Point2d { X = 0, Y = 30 }; Polygon2d polygon_temp = new Polygon2d { Pole = new Point2d { X = 30, Y = 10 } }; polygon_temp.Add(new Point2d { X = 0, Y = 0 }); polygon_temp.Add(new Point2d { X = 100, Y = 0 }); polygon_temp.Add(new Point2d { X = 100, Y = 100 }); polygon_list.Add(polygon_temp); polygon_temp = new Polygon2d { Pole = new Point2d { X = 150, Y = 90 } }; polygon_temp.Add(new Point2d { X = 50, Y = 0 }); polygon_temp.Add(new Point2d { X = 100, Y = 50 }); polygon_temp.Add(new Point2d { X = 50, Y = 150 }); polygon_temp.Add(new Point2d { X = 0, Y = 50 }); polygon_list.Add(polygon_temp); #endregion }
/// <summary> /// Преобразование прямоугольника в многоугольник. /// </summary> /// <param name="rectangle"></param> /// <returns></returns> public static Polygon2d ToPolygon(this Geometric2dWithPointVector rectangle) { Polygon2d polygon = new Polygon2d { Pole = rectangle.Pole.Copy }; polygon.Add(new Point2d()); polygon.Add(new Point2d { X = rectangle.Vector.X }); polygon.Add(new Point2d { X = rectangle.Vector.X, Y = rectangle.Vector.Y }); polygon.Add(new Point2d { Y = rectangle.Vector.Y }); return polygon; }
private void FormMain_Paint(object sender, PaintEventArgs e) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; //e.Graphics.ScaleTransform(1, -1); //e.Graphics.TranslateTransform(0, -ClientSize.Height); if (is_edit) { e.Graphics.Clear(System.Drawing.Color.FromArgb(200, 200, 200)); Point2d pole_temp = polygon.Pole; polygon.Pole += pole.Vector; DrawGrid(e.Graphics, polygon.Pole); e.Graphics.FillAndDraw(System.Drawing.Brushes.Green, System.Drawing.Pens.Black, polygon); polygon.Pole = pole_temp; } else { e.Graphics.Clear(System.Drawing.Color.White); DrawGrid(e.Graphics, pole); for (int i = 0; i < polygon_list.Count; i++) { Point2d pole_temp = polygon_list[i].Pole; polygon_list[i].Pole += pole.Vector; if (polygon_list[i] == polygon) e.Graphics.FillAndDraw(System.Drawing.Brushes.Blue, System.Drawing.Pens.Black, polygon_list[i]); else e.Graphics.FillAndDraw(System.Drawing.Brushes.Yellow, System.Drawing.Pens.Black, polygon_list[i]); polygon_list[i].Pole = pole_temp; } } Polygon2d region = new Polygon2d { Pole = new Point2d() }; region.Add(new Point2d()); region.Add(new Point2d { X = ClientSize.Width }); region.Add(new Point2d { X = ClientSize.Width, Y = ClientSize.Height }); region.Add(new Point2d { Y = ClientSize.Height }); System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(100, 100, 100, 100)); if (plane_dividing_list.Count > 0) { for (int i = 0; i < plane_dividing_list.Count; i++) { Plane2d plane = plane_dividing_list[i].IteratorPlane.Plane(0); Point2d pole_temp = plane.Pole; plane.Pole += pole.Vector; e.Graphics.FillAndDraw(region, brush, System.Drawing.Pens.Black, plane); plane.Pole = pole_temp; } } }
public static Polygon2d Отрезок(Circle circle_this, Plane2d plane) { Polygon2d polygon = new Polygon2d(); polygon.Add(circle_this.Pole - plane.Normal * circle_this.Scalar); polygon.Add(circle_this.Pole - plane.Normal * (circle_this.Scalar + Plane2dExt.Расширенное_расстояние(plane, circle_this))); return polygon; }
public static Polygon2d Отрезок(Circle circle_this, Circle circle) { Polygon2d polygon = new Polygon2d(); Vector2d vector = circle.Pole - circle_this.Pole; double length = Math.Sqrt(vector * vector); vector /= length; polygon.Add(circle_this.Pole + vector * circle_this.Scalar); polygon.Add(circle.Pole - vector * circle.Scalar); return polygon; }
public static void FillAndDraw(this Graphics graphics, Polygon2d region, Brush brush, Pen pen, Plane2d plane) { Polygon2d polygon = new Polygon2d(); for (int i = 0; i < region.Count; i++) { double ed = ((region[i] + region.Pole.Vector) - plane.Pole) * plane.Normal; if (ed < 0) polygon.Add(region[i] + region.Pole.Vector); double ed_temp = (region[i + 1] - region[i]) * plane.Normal; if (ed_temp != 0) { double t = -(((region[i] + region.Pole.Vector) - plane.Pole) * plane.Normal) / ed_temp; if (0 < t && t <= 1) polygon.Add(region[i] + region.Pole.Vector + (region[i + 1] - region[i]) * t); } } graphics.FillAndDraw(brush, pen, polygon); } // !!!Переделать!!!