#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0); //高精度圆周率
const double eps = 1e-8; //偏差值
const int maxp = 1010; //点的数量
int sgn(double x){
//判断x是否等于0
if(fabs(x) < eps) return 0;
else return x<0?-1:1;
}
int Dcmp(double x, double y){
//比较两个浮点数:0 相等;-1 小于;1 大于
if(fabs(x - y) < eps) return 0;
else return x<y ?-1:1;
}
//---------------平面几何:点和线--------
struct Point{
//定义点和基本运算
double x,y;
Point(){
}
Point(double x,double y):x(x),y(y){
}
Point operator + (Point B){
return Point(x+B.x,y+B.y);}
Point operator - (Point B){
return Point(x-B.x,y-B.y);}
Point operator * (double k){
return Point(x*k,y*k);} //长度增大k倍
Point operator / (double k){
return Point(x/k,y/k);} //长度缩小k倍
bool operator == (Point B){
return sgn(x-B.x)==0 && sgn(y-B.y)==0;}
bool operator < (Point B){
return sgn(x-B.x)<0 || (sgn(x-B.x)==0 && sgn(y-B.y)<0);} //用于凸包
};
typedef Point Vector; //定义向量
double Dot(Vector A,Vector B){
return A.x*B.x + A.y*B.y;} //点积
double Len(Vector A){
return sqrt(Dot(A,A));} //向量的长度
double Len2(Vector A){
return Dot(A,A);} //向量长度的平方
double Angle(Vector A,Vector B){
return acos(Dot(A,B)/Len(A)/Len(B));} //A与B的夹角
double Cross(Vector A,Vector B){
return A.x*B.y - A.y*B.x;} //叉积
double Area2(Point A, Point B, Point C){
return Cross(B-A, C-A);} //三角形ABC面积的2倍
double Distance(Point A, Point B){
return hypot(A.x-B.x,A.y-B.y);} //两点的距离
double Dist(Point A,Point B){
return sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));}
Vector Normal(Vector A){
return Vector(-A.y/ Len(A), A.x/ Len(A));} //向量A的单位法向量
bool Parallel(Vector A, Vector B){
return sgn(Cross(A,B)) == 0;}//向量平行或重合)
Vector Rotate(Vector A, double rad){
//向量A逆时针旋转rad度
return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}
struct Line{
Point p1,p2;//线上的两个点
Line(){
}
Line(Point p1,Point p2):p1(p1),p2(p2){
}
// Line(Point x,Point y){p1 = x;p2 = y;}
// Point(double x,double y):x(x),y(y){}
//根据一个点和倾斜角 angle 确定直线,0<=angle<pi
Line(Point p,double angle){
p1 = p;
if(sgn(angle - pi/2) == 0){
p2 = (p1 + Point(0,1));}
else{
p2 = (p1 + Point(1,tan(angle)));}
}
//ax+by+c=0
Line(double a,double b,double c){
if(sgn(a) == 0){
p1 = Point(0,-c/b);
p2 = Point(1,
计算几何模板
最新推荐文章于 2024-03-31 15:51:24 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)