已知一任意多边形的各点坐标
现在需要根据参数返回多边形内点的坐标
也就是说
如果传入3,就要返回3个坐标点的坐标
求高手解答
现在需要根据参数返回多边形内点的坐标
也就是说
如果传入3,就要返回3个坐标点的坐标
求高手解答
解决方案 »
- double类型转为hex(十六进制)字符串问题
- c#web加载ActiveX控件空闲在工具栏中是灰的不可选。是什么问题
- 求教个问题:如何判断泛型T对象是否为default(T)
- 一直觉得正则表式功能是挺麻烦的,规则又难理解,请问那位可以提供点学习的方法,谢谢
- datagridview 更改为Detail的时候用BindingNavigator出错,很棘手
- 这种叫重载吗?
- C#中的AtiveX怎样实现IObjectSafety接口?
- oledbconnection问题!
- tcp服务器中转,服务器端转发如何实现
- 萌新求问,父窗体关闭跳到子窗体,为啥子窗体也关了,有什么让子窗体不关闭的方法吗
- [200分]求高效并集算法
- 请问,DirectX 2D绘图函数有哪些,谢谢
{
Point[] pParam = new Point[] { new Point(12, 34), new Point(3, 5), new Point(45, 56), new Point(126, 6) };
Point[] pIn = GetPointInPolygon(2, pParam); } /// <summary>
/// 获取多边形内随机坐标点
/// </summary>
/// <param name="count">获取左边点数量</param>
/// <param name="point">多边形的各个点</param>
/// <returns></returns>
public Point[] GetPointInPolygon(int count, Point[] point)
{
if (point.Length < 3)
return null; //不是多边形 int x1 = int.MaxValue;
int x2 = int.MinValue;
int y1 = int.MaxValue;
int y2 = int.MinValue; foreach (Point p in point)
{
if (p.X < x1)
x1 = p.X;
if (p.X > x2)
x2 = p.X;
if (p.Y < y1)
y1 = p.Y;
if (p.Y > y2)
y2 = p.Y;
} Random rnd = new Random((int)DateTime.Now.Ticks);
Point[] pointRet = new Point[count];
for (int i = 0; i < count; i++)
{
pointRet[i] = new Point(rnd.Next(x1, x2), rnd.Next(y1, y2));
}
return pointRet;
}
/// <summary>
/// 获取多边形内随机坐标点
/// </summary>
/// <param name="count">获取左边点数量</param>
/// <param name="point">多边形的各个点</param>
/// <returns></returns>
public Point[] GetPointInPolygon(int count, Point[] point)
{
if (point.Length < 3)
return null; //不是多边形 int x1 = int.MaxValue;
int x2 = int.MinValue;
int y1 = int.MaxValue;
int y2 = int.MinValue; foreach (Point p in point)
{
if (p.X < x1)
x1 = p.X;
if (p.X > x2)
x2 = p.X;
if (p.Y < y1)
y1 = p.Y;
if (p.Y > y2)
y2 = p.Y;
}
GraphicsPath myGraphicsPath = new GraphicsPath();
Region myRegion = new Region();
myGraphicsPath.Reset();
myGraphicsPath.AddPolygon(pParam);
myRegion.MakeEmpty();
myRegion.Union(myGraphicsPath); Random rnd = new Random((int)DateTime.Now.Ticks);
Point[] pointRet = new Point[count];
int n=0;
while(n<count)
{
Point p = new Point(rnd.Next(x1, x2), rnd.Next(y1, y2));
if (myRegion.IsVisible(p)) //在多边形内
{
pointRet[n] = p;
n++;
} }
return pointRet;
}
改成
myGraphicsPath.AddPolygon(point);
X [rect.Left,rect.Right]
Y [rect.Top,rect.Bottom]
要加个条件 x,y要在圆内具体算法
http://wenku.baidu.com/view/a6179d6527d3240c8447ef66.html