【笔记】计算几何

比较函数

int dcmp(double x){
    if(fabs(x)<eps) return 0;
    else return x < 0?-1:1;
}

点、向量

定义

struct Point{
    double x,y;
    Point(double x=0 double y=0) :x(x),y(y){} // 构造函数,方便代码编写
};
typedef Point Vector // 别名

基本运算

点积

  • 满足交换律
  • 向量垂直→点积为0

计算点积

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) / Lenth(A) / Lenth(B));}

叉积

猜你喜欢

转载自www.cnblogs.com/greenty1208/p/9349087.html