计算几何-Dot-Vector
This article is made by Jason-Cow.
Welcome to reprint.
But please post the article's address.
看了书,然后码
1 struct D{ 2 db x,y; 3 D(db x=0.0,db y=0.0):x(x),y(y){} 4 }; 5 typedef D V; 6 bl op<(D A,D B){return A.x<B.x||(A.x==B.x&&A.y<B.y);} 7 V op+(V A,V B){return V(A.x+B.x,A.y+B.y);} 8 V op-(V A,V B){return V(A.x-B.x,A.y-B.y);} 9 V op*(V A,db N){return V(A.x*N,A.y*N);} 10 V op/(V A,db N){return V(A.x/N,A.y/N);}
int main(){ A[1]=V(1,2); cout<<A[1].x<<" "<<A[1].y<<endl; cout<<A[2].x<<" "<<A[2].y<<endl; A[2].y+=1.0,cout<<"add"<<endl; A[3]=A[1]+A[2]; cout<<A[3].x<<" "<<A[3].y<<endl<<endl; sort(A+1,A+3+1); for(int i=1;i<=3;i++)cout<<A[i].x<<" "<<A[i].y<<endl; return 0; }
1 2 0 0 add 1 3 0 1 1 2 1 3
~~Jason_liu O(∩_∩)O