gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:11:55 25 4
gpt4 key购买 nike

你好,我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com