#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; struct Point{ double x,y; Point(double x=0,double y=0):x(x),y(y){} }; typedef Point Vector; Vector operator + (Vector a,Vector b){//向量相加,点加向量 return Vector(a.x+b.x,a.y+b.y); } Point operator - (Point a,Point b){//点相减得到向量 return Point(a.x-b.x,a.y-b.y); } Vector operator * (Vector a,double p){//向量与数的想乘 return Vector(a.x*p,a.y*p); } Vector operator / (Vector a,double p){//向量与数的相除 return Vector(a.x/p,a.y/p); } bool operator < (const Point &a,const Point &b){ return a.x<b.x||(a.x==b.x&&a.y<b.y);//排序 } double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x;//差集 } double area(Point A,Point B,Point C){ return Cross(B-A,C-A);//面积; } double Dot(Vector a,Vector b){ return a.x*b.x+a.y*b.y;//点积; } double Length(Vector a){ return sqrt(Dot(a,a));//求长度; } double Angle(Vector a,Vector b){ return acos(Dot(a,b)/Length(a)/Length(b)); }
时间: 2024-10-14 14:02:14