【问题标题】:Plot rectangle with multiple points. Is it possible?绘制具有多个点的矩形。是否可以?
【发布时间】:2020-11-03 02:12:06
【问题描述】:

this is precisely what I want multiple markers and covering them is a rectangle polygon我有多个纬度和经度点。我需要在我的 Windows 窗体应用程序中绘制一个覆盖所有指定的多边形。像这样。

它由一个多边形和一个矩形组成。避免多边形我只想要矩形。

【问题讨论】:

  • 你想给一些像素上色吗?使用 graphics.FillRectangle(semitranparentBrush, x, y, w, h) 和/或 graphics.DrawRectangle(Pens.Black, x, y, w, h) 例如在 Paint 事件或 Bitmap 上..
  • 我编辑了这个问题。请再次检查。
  • 标记和矩形之间的关系是什么?你想找到并画出最小的矩形吗?将标记放在一个列表中,并使用 linq 查找最小和最大 x 和 y 值..:List<PointF> markers = new List<PointF>() { p1,p2,p3,p4....}; float xLeft = markers.Min(x => x.X); float yTop = markers.Min(x => x.Y);..

标签: c# google-maps geometry polygon


【解决方案1】:

正如@Taw 所暗示的,您可以使用以下坐标绘制矩形:

List<PointF> ptlist = new List<PointF>();

// Add points to the list here

ptlist.Sort((p1, p2) => (p1.X.CompareTo(p2.X))); //Sort by X
float left = ptlist[0].X
float right = ptlist[ptlist.Count - 1].X

ptlist.Sort((p1, p2) => (p1.Y.CompareTo(p2.Y))); //Sort by Y
float top = ptlist[0].Y
float bottom = ptlist[ptlist.Count - 1].Y

// Use left, top and right, bottom to draw your rectangle.

除了排序,您还可以编写一个简单的代码来查找列表的最小值和最大值以提高效率。

【讨论】:

  • 请注意,根据元素的数量,排序的效率远低于调用 Min 和 Max。
猜你喜欢
  • 1970-01-01
  • 2018-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-17
  • 1970-01-01
  • 1970-01-01
  • 2018-09-03
相关资源
最近更新 更多