码迷,mamicode.com
首页 > 其他好文 > 详细

关于计算几何问题的操作

时间:2015-11-04 23:03:02      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:

#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));
} 

 

关于计算几何问题的操作

标签:

原文地址:http://www.cnblogs.com/handsomecui/p/4937677.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!