本文出现的代码我连到哪里测试都不知道,完全不保证正确性。
指路 wind_whisper 神仙的博客。
基础运算
typedef double db;
const db eps=1e-8;
struct V{
db x,y;
};
inline bool operator ==(const V &a,const V &b) {return fabs(a.x-b.x)<=eps&&fabs(a.y-b.y)<=eps;}
inline bool operator !=(const V &a,const V &b) {return !(a==b);}
inline V operator +(const V &a,const V &b) {return {a.x+b.x,a.y+b.y};}
inline V operator -(const V &a,const V &b) {return {a.x-b.x,a.y-b.y};}
inline V operator *(const V &a,const db &x) {return {a.x*x,a.y*x};}
inline V operator *(const db &x,const V &a) {return {a.x*x,a.y*x};}
inline V operator /(const V &a,const db &x) {return {a.x/x,a.y/x};}
inline db operator *(const V &a,const V &b) {return a.x*b.x+a.y*b.y;}
inline db operator ^(const V &a,const V &b) {return a.x*b.y-a.y*b.x;}
inline db len(const V &a) {return sqrt(a*a);}
inline V mid(const V &a,const V &b) {return {(a.x+b.x)/2,(a.y+b.y)/2};}
inline V cui(const V &a) {return {a.y,-a.x};}
inline V dw(const V &a) {return a/len(a);}
inline db tri_S(const V &a,const V &b,const V &c) {return abs((a-c)^(b-c))/2;}
inline db angle(const V &a,const V &b) {return acos(a*b/len(a)/len(b));}
inline V turn(const V &a,db t){
db s=sin(t),c=cos(t);
return {a.x*c-a.y*s,a.x*s+a.y*c};
}
标签:const,全家,几何,db,计算,whisper,operator
From: https://www.cnblogs.com/ying-xue/p/17054903.html