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

计算几何

时间:2014-10-03 12:35:14      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   sp   c   on   amp   r   ad   

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

计算几何

标签:io   os   ar   sp   c   on   amp   r   ad   

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

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