1 #include<bits/stdc++.h> 2 using namespace std; 3 const double EPS=1e-6; 4 inline int dcmp(double x){ 5 if(fabs(x)<EPS)return 0; 6 else if(x<0)return -1; 7 else return 1; 8 } 9 struct Vector{ 10 double x,y; 11 Vector(double X=0.0,double Y=0.0):x(X),y(Y){} 12 Vector operator+(const Vector &A)const{ 13 return Vector(x+A.x,y+A.y); 14 } 15 Vector operator-(const Vector &A)const{ 16 return Vector(x-A.x,y-A.y); 17 } 18 double operator*(const Vector &A)const{//点乘· 19 return x*A.x+y*A.y; 20 } 21 Vector operator*(const double &X)const{//数乘 22 return Vector(x*X,y*X); 23 } 24 bool operator==(const Vector&A)const{ 25 return ( !dcmp(x-A.x) && !dcmp(y-A.y) ); 26 } 27 }; 28 inline double polarangle(Vector &A){//向量极角 29 return atan2(A.y,A.x); //?什么函数? 30 } 31 inline double cross(const Vector& A,const Vector& B){//叉乘* (只取数值大小) 32 return A.x*B.y-A.y*B.x; 33 } 34 inline double length(const Vector &A){ 35 return sqrt(A.x*A.x+A.y*A.y); 36 } 37 inline Vector(const Vector& A,const double a){ 38 39 int main(){ 40 printf("%lf",length(Vector(1,1))); 41 return 0; 42 }
原文:https://www.cnblogs.com/a-blog-of-taojiayi-2003/p/12897534.html