幾何意義:
向量的點積(a·b):a·b= |a||b|cos∅
cos∅
,若cos∅
cos∅
為正,兩向量之間的夾角為銳角;為負,兩向量夾角為鈍角;為量,兩向量夾角為直角。(b在a方向上的投影)。
向量的叉積(a×b):a·b= |a||b|sin∅
sin∅
,數值上表示a和b構成的平行四邊形的面積。
#include
using namespace std;
typedef
long
long ll;
const
int max_n=
1e5+10;
const
double eps=
1e-10
;const
double pi=
acos(-
1.0)
;inline
intsign
(const
double
&x)struct point
point
(double _x=0,
double _y=0)
:x(_x),y
(_y)
//建構函式
point operator +
(const point &p)
const
point operator -
(const point &p)
const
double operator ^
(const point &p)
const
point operator *
(const
double
&val)
const
point operator /
(const
double
&val)
const
bool operator <
(const point &p)
const
bool operator ==
(const point &p)
const};
///基本運算
//計算兩點間距離
inline
double
dis(
const point &p0,
const point &pi)
//計算兩個向量的叉積
inline
double
mul(
const point &p0,
const point &p1,
const point &p2)
//計算兩個向量的點積
inline
double
dot(
const point &p0,
const point &p1)
//向量長度
inline
double
length
(point &p)
//向量夾角
double
angle
(point a,point b)
//面積
inline
double
area2
(const point &a,
const point &b,
const point &c)
//向量旋轉
point rotate
(point a,
double rad)
//向量法線
point normal
(point a)
///點和直線
//直線交點
point getlineinter
(point p,point v,point q,point w)
//點到直線的距離
double
distancetoline
(point p,point a,point b)
//點到線段的距離
double
distancetosegment
(point p,point a,point b)
// 點在直線上的投影
point getlineprojection
(point p,point a,point b)
// 線段相交判定
bool segmentproperintersection
(point a1,point a2,point b1,point b2)
// 直線情況判定(一次跨立實驗)
inline
intsegmentproperintersection
(const point &a1,
const point &a2,
const point &b1,
const point &b2)
bool onsegment
(point p,point a1,point a2)
// 多邊形的有向面積
double
polygonarea
(point *p,
int n)
/// 點在多邊形內的判定
intispointinpolygon
(point p,point *poly,
int n)
// 1:in 0:out
if(wn!=0)
return1;
return0;
}/// 求凸包(p:所有點)(ch:凸包上的點)
intconvexhull
(point* p,
int n,point* ch)
int k=m;
for(
int i=n-2;
0<=i;i--)if
(1;return m;
}int
main()
//三角形外接圓圓心以及半徑
#include
#include
#include
#include
#include
#include
using namespace std;
typedef
long
long ll;
const
int max_n=
1e5+10;
const
double eps=
1e-10
;const
double pi=
acos(-
1.0)
;inline
intsign
(const
double
&x)struct point
point
(double _x=0,
double _y=0)
:x(_x),y
(_y)
//建構函式
point operator +
(const point &p)
const
point operator -
(const point &p)
const
double operator ^
(const point &p)
const
point operator *
(const
double
&val)
const
point operator /
(const
double
&val)
const
bool operator <
(const point &p)
const
bool operator ==
(const point &p)
const
}p1,p2,p3;
//計算兩點間距離
inline
double
dis(
const point &p0,
const point &pi)
inline
doubles(
const point &p1,
const point &p2,
const point &p3)
//計算兩個向量的點積
inline
double
dot(
const point &p0,
const point &p1)
//向量長度
inline
double
length2
(point &p)
intmain()
return0;
}
二維幾何模板 二維幾何基礎
二維幾何模板 include include include include include include include include include using namespace std 二維幾何基礎 struct point typedef point vector const doub...
計算幾何 圓 二維模板
include include include include include define fir first define sec second using namespace std const double eps 1e 8 const double pi acos 1.0 int dcmp...
二維計算幾何模板(點,線)
include include include include include include include include include include include define e exp 1.0 define mod 1000000007 define inf 0x7fffffff d...