19,468
社区成员
发帖
与我相关
我的任务
分享
using System.Drawing;
private int IsLeft(Point P0, Point P1, Point P2)
{
int abc = 0;
try
{
abc = ((P1.X - P0.X) * (P2.Y - P0.Y) - (P2.X - P0.X) * (P1.Y - P0.Y));
}
catch (Exception ex)
{
Console.WriteLine("判断点是否在区域某顶点左边时出现异常:{0}", ex.ToString());
}
return abc;
}
private bool PointInFences(Point pnt1, Point[] fencePnts)
{
int wn = 0, j = 0; //wn 计数器 j第二个点指针
try
{
for (int i = 0; i < fencePnts.Length; i++)
{//开始循环
if (i == fencePnts.Length - 1)
j = 0;//如果 循环到最后一点 第二个指针指向第一点
else
j = j + 1; //如果不是 ,则找下一点
if (fencePnts[i].Y <= pnt1.Y)
{ // 如果多边形的点 小于等于 选定点的 Y 坐标
if (fencePnts[j].Y > pnt1.Y)
{ // 如果多边形的下一点 大于于 选定点的 Y 坐标
if (IsLeft(fencePnts[i], fencePnts[j], pnt1) > 0)
{
wn++;
}
}
}
else
{
if (fencePnts[j].Y <= pnt1.Y)
{
if (IsLeft(fencePnts[i], fencePnts[j], pnt1) < 0)
{
wn--;
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("判断点和区域时出现异常:{0}", ex.ToString());
}
if (wn == 0)
return false;
else
return true;
}
public class Point
{
public double X;
public double Y;
public Point(double x, double y)
{
this.X = x;
this.Y = y;
}
}
double a = 118.8918980,b = 31.965411;
CString astr;
astr.Format("%lf",a);
CString bstr;
bstr.Format("%lf",b);
int lena = astr.GetLength()-astr.Find(".");
int lenb = bstr.GetLength()-bstr.Find(".");
int len = max(lena,lenb);
int N = pow(10,len);
CPoint p(int(a*N),int(b*N));