首页 > 其他 > 详细

计算几何

时间:2014-10-03 10:54:24      阅读:200      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
# include<cmath>
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  (A.x+B.x,A.y+B.y);
}

Vector operator -(Vector A,Vector B)
{
    return (A.x-B.x,A.y-B.y);
}

Vector operator *(Vector A,double p)
{
    return (A.x*p, A.x*p);
}

Vector operator /(Vector A,double p)
{
    return (A.x/p, A.x/p);
}

const int esp=1e-10;

bool operator <(const point& a,const point& b)
{
    return a.x<b.x||(a.x==b.x && a.y<b.y);
}

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

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 Length(Vector A)
{
    return sqrt(Dot(A,A));
}

double Angle(Vector A, Vector B)
{
    return acos(Dot(A,B))/Length(A)/Length(B);
}

Vector Rotate (Vector A,double rad)
{
    return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}

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

int main()
{
    return 0;
}

计算几何

原文:http://blog.csdn.net/u013514722/article/details/39753869

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!