• 计算几何模板存储


    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    const double eps=1e-10;
    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;//定义向量
    //定义向量基本计算运算符
    Vector operator + (Point A,Point B){
        return Vector(A.x+B.x,A.y+B.y);
    }//定义向量加符合三角形定则
    Vector operator - (Point A,Point B){
        return Vector(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);
    }//定义向量比较这里优先比较x维
    bool operator > (const Point& a,const Point& b){
        return a.x>b.x||(a.x==b.x&&a.y>b.y);
    }//定义向量比较这里优先比较x维
    bool operator == (const Point& a,const Point& b){
        return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;
    }//定义向量相等为完全相同
    //向量点积相关
    double Dot(Vector A,Vector B){
        return A.x*B.x+A.y*B.y;
    }//计算向量点积
    double Lenth(Vector A){
        return sqrt(Dot(A,A));
    }//计算向量长
    double Angle(Vector A,Vector B){
        return acos(Dot(A,B)/Lenth(A)/Lenth(B));
    }//计算向量夹角(有序的) 
    //向量叉积相关
    double Cross(Vector A,Vector B){
        return A.x*B.y-A.y*B.x;
    }//计算向量叉积
    double Area(Point A,Point B,Point C){
        return fabs(Cross(B-A,C-A)/2);
    }//计算abc三点三角形的数值面积
    int main()
    {
        return 0;
    }
  • 相关阅读:
    vim插件管理利器
    Ubuntu下安装java
    Eclipse的vim插件viPlugin的安装
    Ubuntu下如何检查文件的md5,sha-512码
    C语言的工具集
    ubuntu下禁用和恢复触摸板
    linux下开发C语言需要安装的manpages手册
    linux下C++的man文件安装
    源码编译安装git
    EditText属性详解
  • 原文地址:https://www.cnblogs.com/nietzsche-oier/p/6647996.html
Copyright © 2020-2023  润新知