计算几何模板--zhengjun

二维

using vec=complex<int>;
ll dot(const vec &a,const vec &b){
	return 1ll*real(a)*real(b)+1ll*imag(a)*imag(b);
}
ll cross(const vec &a,const vec &b){
	return dot(a,b*vec(0,-1));
}
ll dis2(const vec &a){
	return dot(a,a);
}

三维

struct vec{
	int x,y,z;
	vec(int a=0,int b=0,int c=0):x(a),y(b),z(c){}
	void read(){
		scanf("%d%d%d",&x,&y,&z);
	}
}a[N],b[N];
#ifdef DEBUG
ostream& operator << (ostream &out,vec a){
	return out<<'('<<a.x<<','<<a.y<<','<<a.z<<')';
}
#endif
bool operator == (const vec &a,const vec &b){
	return a.x==b.x&&a.y==b.y&&a.z==b.z;
}
vec operator + (const vec &a,const vec &b){
	return vec(a.x+b.x,a.y+b.y,a.z+b.z);
}
vec operator - (const vec &a,const vec &b){
	return vec(a.x-b.x,a.y-b.y,a.z-b.z);
}
vec cross(const vec &a,const vec &b){
	return vec(
		a.y*b.z-a.z*b.y,
		a.x*b.z-a.z*b.x,
		a.x*b.y-a.y*b.x
	);
}
ll dot(const vec &a,const vec &b){
	return 1ll*a.x*b.x+1ll*a.y*b.y+1ll*a.z*b.z;
}
ll dis2(const vec &a){
	return dot(a,a);
}
posted @ 2023-10-11 13:43  A_zjzj  阅读(10)  评论(0编辑  收藏  举报