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 }
} // Π₯Π°ΡΠΈΠ½, ΠΡΠ΄Π»ΠΎ private bool Step(Polygon2d polygon, StripRegion strip_region, List<Polygon2d> polygon_placed_list) { #region Π¨Π°Π³-1. Π£ΡΡΠ°Π½ΠΎΠ²ΠΊΠ° Π½Π°ΡΠ°Π»ΡΠ½ΠΎΠ³ΠΎ Π·Π½Π°ΡΠ΅Π½ΠΈΡ (Π±Π΅ΡΠΊΠΎΠ½Π΅ΡΠ½ΠΎΡΡΡ) ΡΠΎΡΠΊΠΈ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ ΡΠ΅ΠΊΡΡΠ΅Π³ΠΎ Polygon. polygon.Pole = new Point2d(); for (int j = 1; j <= polygon.Pole.Dim; j++) polygon.Pole[j] = double.PositiveInfinity; #endregion #region Π¨Π°Π³-2. ΠΠΎΡΡΡΠΎΠ΅Π½ΠΈΠ΅ Π²ΡΠ΅Ρ Π³ΠΎΠ΄ΠΎΡΠΎΠ² ΡΡΠ½ΠΊΡΠΈΠΈ ΠΏΠ»ΠΎΡΠ½ΠΎΠ³ΠΎ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ. List<Polygon2d> polygon_godograph_list = new List<Polygon2d>(); // Π£ΡΡΠ°Π½ΠΎΠ²ΠΈΡΡ Capacity. #region Π¨Π°Π³-2.1. ΠΠΎΠ΄ΠΎΡΠ°Ρ ΡΡΠ½ΠΊΡΠΈΠΈ ΠΏΠ»ΠΎΡΠ½ΠΎΠ³ΠΎ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ ΠΏΠΎ ΠΏΠΎΠ»ΠΎΡΠ΅. polygon_godograph_list.Add(ΠΠΎΠ΄ΠΎΡΠ°Ρ_ΡΡΠ½ΠΊΡΠΈΠΈ_ΠΏΠ»ΠΎΡΠ½ΠΎΠ³ΠΎ_ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ(polygon, strip_region)); #endregion #region Π¨Π°Π³-2.2. ΠΠΎΠ΄ΠΎΡΠ°ΡΡ ΡΡΠ½ΠΊΡΠΈΠΈ ΠΏΠ»ΠΎΡΠ½ΠΎΠ³ΠΎ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ ΠΏΠΎ ΠΌΠ½ΠΎΠ³ΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΠ°ΠΌ. for (int i = 0; i < polygon_placed_list.Count; i++) polygon_godograph_list.Add(ΠΠΎΠ΄ΠΎΡΠ°Ρ_ΡΡΠ½ΠΊΡΠΈΠΈ_ΠΏΠ»ΠΎΡΠ½ΠΎΠ³ΠΎ_ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ(polygon, polygon_placed_list[i])); #endregion #endregion #region Π¨Π°Π³-3. Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΡΠΏΠΈΡΠΊΠ° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΡΡ ΡΠΎΡΠ΅ΠΊ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ. poles = new List<Point2d>(); #endregion #region Π¨Π°Π³-4. ΠΠΎΠ±Π°Π²Π»ΡΠ΅ΠΌ ΡΠΎΡΠΊΠΈ ΠΏΠ΅ΡΠ΅ΡΠ΅ΡΠ΅Π½ΠΈΡ ΡΡΠΎΡΠΎΠ½ ΠΏΠΎΠ»ΠΎΡΡ. // ΠΠ΅ΡΡΠΈΠ½Ρ polygon_godograph_list[0]; #endregion #region Π¨Π°Π³-5. ΠΠ»Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ ΠΏΠ°ΡΡ Π³ΠΎΠ΄ΠΎΡΠ°ΡΠΎΠ² ΡΡΠ½ΠΊΡΠΈΠΈ ΠΏΠ»ΠΎΡΠ½ΠΎΠ³ΠΎ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ Π½Π°Ρ ΠΎΠ΄ΠΈΠΌ ΠΈΡ ΡΠΎΡΠΊΠΈ ΠΏΠ΅ΡΠ΅ΡΠ΅ΡΠ΅Π½ΠΈΡ. for (int i = 0; i < polygon_godograph_list.Count - 1; i++) for (int j = i + 1; j < polygon_godograph_list.Count; j++) poles.AddRange(Π’ΠΎΡΠΊΠΈ_ΠΏΠ΅ΡΠ΅ΡΠ΅ΡΠ΅Π½ΠΈΡ_ΠΌΠ½ΠΎΠ³ΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΠΎΠ²(polygon_godograph_list[i], polygon_godograph_list[j])); #endregion #region Π¨Π°Π³-6. ΠΠ»Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΠΉ ΡΠΎΡΠΊΠΈ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ... bool is_placed = false; for (int i = 0; i < poles.Count; i++) { #region Π¨Π°Π³-6.1. ΠΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ ΡΡΠ»ΠΎΠ²ΠΈΠ΅ ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠ½ΠΎΡΡΠΈ ΠΎΠ±Π»Π°ΡΡΠΈ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ. bool is_point_right = Π’ΠΎΡΠΊΠ°_ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠΈΡ_ΠΌΠ½ΠΎΠ³ΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΡ(poles[i], polygon_godograph_list[0]); #endregion #region Π¨Π°Π³-6.2. ΠΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ ΡΡΠ»ΠΎΠ²ΠΈΠ΅ Π½Π΅ΠΏΠ΅ΡΠ΅ΡΠ΅ΡΠ΅Π½ΠΈΡ Ρ ΡΠ°Π·ΠΌΠ΅ΡΡΠ½Π½ΡΠΌΠΈ ΠΎΠ±ΡΠ΅ΠΊΡΠ°ΠΌΠΈ. for (int j = 1; j < polygon_godograph_list.Count && is_point_right; j++) is_point_right = !Π’ΠΎΡΠΊΠ°_ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠΈΡ_ΠΌΠ½ΠΎΠ³ΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΡ(poles[i], polygon_godograph_list[j]); #endregion #region Π¨Π°Π³-6.3. ΠΡΠ»ΠΈ Π²ΡΠΏΠΎΠ»Π½ΡΡΡΡΡ Π²ΡΠ΅ ΡΡΠ»ΠΎΠ²ΠΈΡ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ, ΡΠΎ... if (is_point_right) { #region Π£ΡΡΠ°Π½Π°Π²Π»ΠΈΠ²Π°Π΅ΠΌ ΠΎΠ±ΡΠ΅ΠΊΡ Π² ΡΠΎΡΠΊΡ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ (ΠΈΠ· Π΄Π²ΡΡ ΡΠΎΡΠ΅ΠΊ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ Π²ΡΠ±ΠΈΡΠ°Π΅ΡΡΡΡ Π±ΠΎΠ»Π΅Π΅ ΠΎΠΏΡΠΈΠΌΠ°Π»ΡΠ½Π°Ρ). // ΠΠΎΠ΄ΠΎΠΉΠ΄ΡΡ Π»ΠΈ ΡΠ°ΠΊΠΎΠΉ Π²Π°ΡΠΈΠ°Π½Ρ? polygon.Pole.Copy = strip_region.OptPole(polygon.Pole, poles[i]); #endregion is_placed = true; } #endregion } #endregion return is_placed; }
public static void Fill(this Graphics graphics, Brush brush, Polygon2d polygon) { if (polygon.Count > 2) { PointF[] points = polygon.ToArrayOfPointF(); if (points.Length > 1) graphics.FillPolygon(brush, points); } }
/// <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; }
public static void Draw(this Graphics graphics, Pen pen, Polygon2d polygon) { if (polygon.Count == 2) { graphics.DrawLine(pen, polygon[0].ToPointF(), polygon[1].ToPointF()); } if (polygon.Count > 2) { PointF[] points = polygon.ToArrayOfPointF(); if (points.Length > 1) graphics.DrawPolygon(pen, points); } }
private void FormMain_MouseDown(object sender, MouseEventArgs e) { point_curr.X = e.X; point_curr.Y = e.Y; is_mouse_down = true; if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Clicks == 2) { is_edit = !is_edit; if (is_edit && polygon == null) { polygon = new Polygon2d { Pole = new Point2d { Vector = point_curr - pole } }; polygon_list.Add(polygon); } if (!is_edit && !polygon.IsRightPolygon()) polygon_list.Remove(polygon); } if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Clicks == 1) { Point2d point = new Point2d { Vector = point_curr - pole }; if (is_edit) { point.Vector -= polygon.Pole.Vector; polygon.Add(point); } else { polygon = null; for (int i = 0; i < polygon_list.Count && polygon == null; i++) if (polygon_list[i].IsContain(point)) polygon = polygon_list[i]; } } Invalidate(); }
public static void FillAndDraw(this Graphics graphics, Brush brush, Pen pen, Polygon2d polygon) { if (polygon.Count == 2) { graphics.DrawLine(pen, polygon[0].ToPointF(), polygon[1].ToPointF()); } if (polygon.Count > 2) { PointF[] points = polygon.ToArrayOfPointF(); graphics.FillPolygon(brush, points); graphics.DrawPolygon(pen, points); } }
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); } // !!!ΠΠ΅ΡΠ΅Π΄Π΅Π»Π°ΡΡ!!!
// ΠΠ΅ΡΠΎΠ΄ ΠΏΠΎΠΈΡΠΊΠ° ΡΠ°Π·Π΄Π΅Π»ΡΡΡΠΈΡ . // TODO: ΠΠ΅ΡΠ΅Π΄Π΅Π»Π°ΡΡ. private double Find(Polygon2d.Iterator iti, Polygon2d.Iterator itj) { int gi = -1; int gj = -1; double ged = double.NegativeInfinity; for (int i = 0; i < iti.Count; i++) { int lj = -1; double led = double.PositiveInfinity; for (int j = 0; j < itj.Count; j++) { double ed = Plane2dExt.Π Π°ΡΡΠΈΡΠ΅Π½Π½ΠΎΠ΅_ΡΠ°ΡΡΡΠΎΡΠ½ΠΈΠ΅(iti.Plane(i), itj.Point(j)); if (led > ed) { led = ed; lj = j; } if (ed < 0) { led = double.PositiveInfinity; break; } } if (!double.IsPositiveInfinity(led)) { if (ged < led) { ged = led; gi = i; gj = lj; } } } if (!double.IsNegativeInfinity(ged)) { iti.Move(gi); itj.Move(gj); } return ged; }
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, 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 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 PlaneDividing(Polygon2d.Iterator iterator_plane, Polygon2d.Iterator iterator_point) { this.iterator_plane = iterator_plane; this.iterator_point = iterator_point; }
} // ΠΡΠΎΠ»Π΅ΡΠΊΠΎΠ²ΡΠΊΠΈΠΉ. private Polygon2d ΠΠΎΠ΄ΠΎΡΠ°Ρ_ΡΡΠ½ΠΊΡΠΈΠΈ_ΠΏΠ»ΠΎΡΠ½ΠΎΠ³ΠΎ_ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΡ(Polygon2d polygon_i, Polygon2d polygon_j) { throw new NotImplementedException(); } // ΠΡΠΎΠ»Π΅ΡΠΊΠΎΠ²ΡΠΊΠΈΠΉ.
} // !!!ΠΠ΅ΡΠ΅Π΄Π΅Π»Π°ΡΡ!!! public static void FillAndDraw_(this Graphics graphics, Polygon2d region, Brush brush, Pen pen, Geometric2d geometric) { if (geometric is Point2d) graphics.FillAndDraw(brush, pen, geometric as Point2d); if (geometric is Geometric2dWithPointScalar) graphics.FillAndDraw(brush, pen, geometric as Geometric2dWithPointScalar); if (geometric is Geometric2dWithPointVector) graphics.FillAndDraw(brush, pen, geometric as Geometric2dWithPointVector); if (geometric is Polygon2d) graphics.FillAndDraw(brush, pen, geometric as Polygon2d); if (geometric is Plane2d) graphics.FillAndDraw(region, brush, pen, geometric as Plane2d); }
} // ΠΡΠ·ΠΎΠ²Π»Π΅Π². private bool Π’ΠΎΡΠΊΠ°_ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠΈΡ_ΠΌΠ½ΠΎΠ³ΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΡ(Point2d point, Polygon2d polygon) { throw new NotImplementedException(); } // Π₯Π°ΡΠΈΠ½, ΠΡΠ΄Π»ΠΎ
} // ΠΡΠΎΠ»Π΅ΡΠΊΠΎΠ²ΡΠΊΠΈΠΉ. private List<Point2d> Π’ΠΎΡΠΊΠΈ_ΠΏΠ΅ΡΠ΅ΡΠ΅ΡΠ΅Π½ΠΈΡ_ΠΌΠ½ΠΎΠ³ΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΠΎΠ²(Polygon2d polygon_i, Polygon2d polygon_j) { throw new NotImplementedException(); } // ΠΡΠ·ΠΎΠ²Π»Π΅Π².