c# - 如何找到是否存在于任何多边形区域内的点?

标签 c# algorithm

你好,我正在使用 C#,我想知道是否有一个多边形(主要是三角形)给我,我必须找到给定的点是否存在于给定的多边形中,我想知道是否有任何函数在 c# 中可以为我做这件事或任何有效的算法吗??

多边形在 2D 平面中由 XY 点表示,给定点也由 XY 点表示

提前致谢

最佳答案

您需要使用 Graphics.IsVisible(Point p) . 指示由一对坐标指定的点是否包含在该 Graphics 对象的可见裁剪区域内。

来自 MSDN 的示例:

public void IsVisiblePoint(PaintEventArgs e)
{
   // Set clip region.
   Region clipRegion = new Region(new Rectangle(50, 50, 100, 100));
   e.Graphics.SetClip(clipRegion, CombineMode.Replace);
   // Set up coordinates of points.
   int x1 = 100;
   int y1 = 100;
   int x2 = 200;
   int y2 = 200;
   Point point1 = new Point(x1, y1);
   Point point2 = new Point(x2, y2);
   // If point is visible, fill ellipse that represents it.
   if (e.Graphics.IsVisible(point1))
   e.Graphics.FillEllipse(new SolidBrush(Color.Red), x1, y1, 10, 10);
   if (e.Graphics.IsVisible(point2))
   e.Graphics.FillEllipse(new SolidBrush(Color.Blue), x2, y2, 10, 10);
}

关于c# - 如何找到是否存在于任何多边形区域内的点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3140051/

相关文章:

algorithm - 给定二维点列表,找到最接近所有其他点的点

c# - ASP.NET/C# 中的服务器端麦克风捕获

c# - 用于数组和集合的自定义 Newtonsoft JsonConverter 以进行进一步操作

c# - 消失的代码?

ruby - 需要一个 Ruby 方法来确定矩阵 "touching"另一个元素的元素

c# - 根据大小对数字范围进行分区,然后找到该范围内给定数字的分区起点

c# - 如何在独立存储文件中存储和检索数据?

c# - MailKit 设置 Append 后可见的 MessageFlag

c++ - 排序时如何找出 "progress"?

algorithm - 非确定性 PDA 如何以及为何比确定性 PDA 更强大?