System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); Point top = new Point(200, 100); Point bottom = new Point(200, 400); Point left = new Point(0, 300); Point right = new Point(300, 300); path.AddLine(top, left); path.AddLine(left, bottom); path.AddLine(bottom, right); path.AddLine(right, top); Point test = new Point(200, 200); bool result = path.IsVisible(test); 我这样好象可以,不过不知效率高低.....
Point[] points = new Point[4]; RectangleF rectF = GetRectangleF(1.0f); points[0] = new Point(Convert.ToInt32(rectF.Left), Convert.ToInt32(rectF.Top)); points[1] = new Point(Convert.ToInt32(rectF.Left), Convert.ToInt32(rectF.Bottom)); points[2] = new Point(Convert.ToInt32(rectF.Right), Convert.ToInt32(rectF.Bottom)); points[3] = new Point(Convert.ToInt32(rectF.Right), Convert.ToInt32(rectF.Top)); IntPtr hrgn = CreatePolygonRgn(points, 4, 2);//Win32API参见MSDN帮助 return PtInRegion(hrgn, pX, pY);//Win32API参见MSDN帮助
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace 区域的单击检测 { public partial class Form1 : Form { SolidBrush brush = new SolidBrush(Color.Black); Region region1 = new Region(new Rectangle(50, 0, 50, 150)); Region region2 = new Region(new Rectangle(0, 50, 150, 50)); Graphics g;
Point top = new Point(200, 100);
Point bottom = new Point(200, 400);
Point left = new Point(0, 300);
Point right = new Point(300, 300);
path.AddLine(top, left);
path.AddLine(left, bottom);
path.AddLine(bottom, right);
path.AddLine(right, top); Point test = new Point(200, 200);
bool result = path.IsVisible(test);
我这样好象可以,不过不知效率高低.....
Point[] points = new Point[4]; RectangleF rectF = GetRectangleF(1.0f); points[0] = new Point(Convert.ToInt32(rectF.Left), Convert.ToInt32(rectF.Top));
points[1] = new Point(Convert.ToInt32(rectF.Left), Convert.ToInt32(rectF.Bottom));
points[2] = new Point(Convert.ToInt32(rectF.Right), Convert.ToInt32(rectF.Bottom));
points[3] = new Point(Convert.ToInt32(rectF.Right), Convert.ToInt32(rectF.Top)); IntPtr hrgn = CreatePolygonRgn(points, 4, 2);//Win32API参见MSDN帮助 return PtInRegion(hrgn, pX, pY);//Win32API参见MSDN帮助
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 区域的单击检测
{
public partial class Form1 : Form
{
SolidBrush brush = new SolidBrush(Color.Black);
Region region1 = new Region(new Rectangle(50, 0, 50, 150));
Region region2 = new Region(new Rectangle(0, 50, 150, 50));
Graphics g;
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
g = this.CreateGraphics();
region1.Union(region2);
} private void Form1_MouseUp(object sender, MouseEventArgs e)
{
this.Refresh();
if (region1.IsVisible(new Point(e.X, e.Y), g))
{
brush.Color = Color.Red;
}
else
{
brush.Color = Color.FromArgb(64, 255, 0, 0);
}
g.FillRegion(brush, region1);
}
}
}懒得改,这是我以前写的一段代码,就看你能不能看明白了.
对于这种内点检测,我曾问过一个从事计算导弹弹道的数学专家,可能他不太明白我的意图,或我没表示清楚是要干什么,他的回答是可以用相交来判断,并让我去看《Math Library》,不过我估计计算机图形可能是用三角形分割或点在闭合曲线的行进方向上的右右位来判断的,当然这是建立在我的猜想上的,我也没试验过这种东西.
我想到办法了,从理论上将
建设两点(Xa,Ya),(Xb,Yb) 组成直线为a1X +b1Y+c1 =0
与两点(Xc,Yc),(Xd,Yd).组成直线为a2X +b2Y+c2 =0
这两条直线平行
则激活点(X0,Y0)代到直线上面去
a1X0 +b1Y0+c1
a2X0 +b2Y+c2
这样得出的结果只有一个>0,一个<0 ,这个点才在这个这两个平行线之间.
另一对平行线也可如此判断.