91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 464KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-05-16
  • 語言: C/C++
  • 標(biāo)簽: VC++??

資源簡介

判斷點是否在多邊形內(nèi) #include #include #include #define max(a,b) ((a>b)?a:b) #define min(a,b) ((a<b)?a:b) using namespace std; const double INFINITY = 1e10; const double ESP = 1e-5; const int MAX_N = 1000; //定義點 struct Point { double x, y; }; //定義邊 struct LineSegment { Point pt1, pt2; }; typedef vector Polygon;

資源截圖

代碼片段和文件信息

#include
#include
#include?
#define?max(ab)?((a>b)?a:b)
#define?min(ab)?((ausing?namespace?std;

const?double?INFINITY?=?1e10;?
const?double?ESP?=?1e-5;?
const?int?MAX_N?=?1000;?
//定義點
?struct?Point?
{?
double?x?y;?
};?
//定義邊

struct?LineSegment?
{?
Point?pt1?pt2;?
};?

typedef?vector?Polygon;?
?

//?計算叉乘?|P0P1|?×?|P0P2|?
double?Multiply(Point?p1?Point?p2?Point?p0)?
{?
return?(?(p1.x?-?p0.x)?*?(p2.y?-?p0.y)?-?(p2.x?-?p0.x)?*?(p1.y?-?p0.y)?);?
}?

//?判斷線段是否包含點point?
bool?IsOnline(Point?point?LineSegment?line)?
{?
return(?(?fabs(Multiply(line.pt1?line.pt2?point))? (?(?point.x?-?line.pt1.x?)?*?(?point.x?-?line.pt2.x?)?<=?0?)?&&?
(?(?point.y?-?line.pt1.y?)?*?(?point.y?-?line.pt2.y?)?<=?0?)?);?
}?

//?判斷線段相交?
bool?Intersect(LineSegment?L1?LineSegment?L2)?
{?
return(?(max(L1.pt1.x?L1.pt2.x)?>=?min(L2.pt1.x?L2.pt2.x))?&&?
(max(L2.pt1.x?L2.pt2.x)?>=?min(L1.pt1.x?L1.pt2.x))?&&?
(max(L1.pt1.y?L1.pt2.y)?>=?min(L2.pt1.y?L2.pt2.y))?&&?
(max(L2.pt1.y?L2.pt2.y)?>=?min(L1.pt1.y?L1.pt2.y))?&&?
(Multiply(L2.pt1?L1.pt2?L1.pt1)?*?Multiply(L1.pt2?L2.pt2?L1.pt1)?>=?0)?&&?
(Multiply(L1.pt1?L2.pt2?L2.pt1)?*?Multiply(L2.pt2?L1.pt2?L2.pt1)?>=?0)?
);?
}?

//?判斷點在多邊形內(nèi)?
bool?InPolygon(Polygon?&?polygon?Point?point)?
{?
int?n?=?polygon.size();?
int?count?=?0;?
LineSegment?line;?
line.pt1?=?point;?
line.pt2.x?=?point.x;?
line.pt2.y?=?-?INFINITY;?
?
for(?int?i?=?0;?i? //?得到多邊形的一條邊?
LineSegment?side;?
side.pt1?=?polygon[i];?
side.pt2?=?polygon[(i?+?1)?%?n];?
?//判斷已知點是否在邊上
if(?IsOnline(point?side)?)?{?
return?1?;
}?
?
//?如果side平行y軸則不作考慮?
if(?fabs(side.pt1.x?-?side.pt2.x)? continue;?
}?
?
if(?IsOnline(side.pt1?line)?)?
{?
if(?side.pt1.x?>?side.pt2.x?)?count++;?
}?
else?if(?IsOnline(side.pt2?line)?)?
{?
if(?side.pt2.x>?side.pt1.x?)?count++;?
}?
else?if(?Intersect(line?side)?)
{?
count++;?
}?
}?
?
?if?(?count?%?2?==?1?)?{return?0;}
else?{?return?1;}
}



//****************************************************************
void?main()
{
int?n;
double?xy;

Point?pt1;
cout<<“請輸入一點:“< cin>>x>>y;
pt1.x=x;
pt1.y=y;
cout<<“點坐標(biāo)為:(“<
Polygon?poly;
cout<<“請輸入多邊形的邊數(shù):“< cin>>n;
for(int?i=0;i {
double?mj;
cout<<“請輸入第“< cin>>m>>j;
Point?pt;
pt.x=m;
pt.y=j;
poly.push_back(pt);
}

//cout<<“多邊形的邊數(shù)“< bool?retur;
retur=InPolygon(poly?pt1);?
if(retur==1)
cout<<“點在多邊形外!“< else?
cout<<“點在多邊形內(nèi)!“<
}


?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????31521??2011-03-24?21:53??點在多邊形內(nèi)Y軸C++\Debug\PInP.obj

?????文件?????241724??2011-03-24?21:53??點在多邊形內(nèi)Y軸C++\Debug\PInPVC.exe

?????文件?????296968??2011-03-24?21:53??點在多邊形內(nèi)Y軸C++\Debug\PInPVC.ilk

?????文件????1281284??2011-03-11?18:52??點在多邊形內(nèi)Y軸C++\Debug\PInPVC.pch

?????文件?????582656??2011-03-24?21:52??點在多邊形內(nèi)Y軸C++\Debug\PInPVC.pdb

?????文件??????74752??2011-03-24?21:57??點在多邊形內(nèi)Y軸C++\Debug\vc60.idb

?????文件??????94208??2011-03-24?21:52??點在多邊形內(nèi)Y軸C++\Debug\vc60.pdb

?????文件???????2820??2011-03-24?21:52??點在多邊形內(nèi)Y軸C++\PInP.cpp

?????文件???????4282??2011-03-11?19:13??點在多邊形內(nèi)Y軸C++\PInPVC.dsp

?????文件????????520??2011-03-11?18:50??點在多邊形內(nèi)Y軸C++\PInPVC.dsw

?????文件??????41984??2011-03-24?21:57??點在多邊形內(nèi)Y軸C++\PInPVC.ncb

?????文件??????53760??2011-03-24?21:57??點在多邊形內(nèi)Y軸C++\PInPVC.opt

?????文件????????246??2011-03-24?21:54??點在多邊形內(nèi)Y軸C++\PInPVC.plg

?????目錄??????????0??2011-03-24?21:52??點在多邊形內(nèi)Y軸C++\Debug

?????目錄??????????0??2011-03-24?21:57??點在多邊形內(nèi)Y軸C++

-----------?---------??----------?-----??----

??????????????2706725????????????????????15


評論

共有 條評論