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

11178 - Morley's Theorem【几何】

时间:2014-08-29 20:08:28      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   使用   io   ar   2014   cti   

不涉及什么算法,只是简单的套用模板进行计算。

如果一个向量进行逆时针旋转,那么可以使用定义的函数 Rotate(v,rad)进行计算。

但是如果进行顺时针旋转,那么需要将rad改为-rad,也就是Rotate(v,-rad)进行计算。

精度的控制为 1e-10;

14112243 11178 Morley‘s Theorem Accepted C++ 0.055 2014-08-29 11:09:31

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define INF 1 << 30
#define eps 1e-10
#define  Vector Point
/*=============================================*/
double dcmp(double x){
    if(fabs(x) < eps)
        return 0;
    else
        return x < 0 ? -1 : 1;
}
struct Point{
    double x;
    double y;
Point(double a = 0,double b = 0): x(a),y(b) {};
friend bool operator < (Point p,Point q){
        if(p.x != q.y)
                return p.y - q.y;
        else
                return p.x - q.x;
}
friend Vector operator + (Point p,Point q){
        return Vector(p.x + q.x , p.y + q.y);
}
friend Vector operator - (Point p,Point q){
        return Vector(p.x - q.x ,  p.y - q.y);
}
friend Vector operator * (Point p,double t){
        return Vector(p.x * t , p.y * t);
}
friend Vector operator / (Point p,double t){
        return Vector(p.x / t , p.y / t);
}
friend bool operator == (Point p,Point q){
        return dcmp(p.x - q.x) == 0 && dcmp(p.y - q.y) == 0;
}
};
double Dot(Vector p, Vector q){  //向量点积
return p.x * q.x + p.y * q.y;
}
double Length(Vector p){        //向量长度
return sqrt(p.x*p.x + p.y * p.y);
}
double Angle(Vector p ,Vector q){
return acos( Dot(p, q) /( Length(p) * Length(q) ) );
}
double Cross(Vector p,Vector q){
return p.x * q.y - p.y * q.x;
}
double Area(Point a,Point b,Point c){
return Cross(a - b , c - b);
}
Vector Rotate(Vector p,double angle){
 return Vector(p.x * cos(angle) - p.y * sin(angle), p.x * sin(angle) + p.y * cos(angle));
}
Vector Normal(Vector p){  //求法向量
double L = Length(p);
return Vector( - p.y / L , p.x / L);
}
Point GetLineCross(Vector v,Point p,Vector w,Point q){
Vector u = p - q;
double t = Cross(w,u) / Cross(v,w);
return p + v * t;
}
double Distance(Point p,Point a,Point b){  //点到射线的距离
    Vector v1 = b - a;
    Vector v2 = p - a;
    return fabs(Cross(v1,v2)) / Length(v1);
}
double Distance2(Point p,Point a,Point b){
    if(a == b)
        return Length(p - a);
    Vector v1 = b - a , v2 = p - a, v3 = p - b;
    if(dcmp(Dot(v1,v2)) < 0)
        return Length(v2);
    else if(dcmp(Dot(v1,v3)) > 0)
        return Length(v3);
    else
        return fabs(Cross(v1,v2))/ Length(v1);
}
Point GetLinePoint(Point p,Point a,Point b){
    Vector v = b - a;
    return a + v *  (Dot(v, p -a ) / Dot(v,v));
}
bool If_Cross(Point a1,Point a2,Point b1,Point b2){
    double c1 = Cross(a2 - a1 , b1 - a1) , c2 = Cross(a2 - a1 , b2 - a1),
                  c3 = Cross(b2 - b1, a1 - b1),  c4  = Cross(b2 - b1, a2 - b1);
    return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
}
bool If_InLine(Point p,Point a1,Point a2){
    return dcmp(Cross(a1 - p , a2 - p)) == 0 && dcmp(Dot(a1 - p , a2 - p)) < 0;
}
Point GetPoint(Point a,Point b,Point c){
    Vector v1 = c - b;
    double rad = Angle(a - b,v1);
    v1 = Rotate(v1, rad / 3);
    Vector v2 = b - c;
    double _rad = Angle(a - c, v2); //负数代表顺时钟转动
    v2 = Rotate(v2, - _rad / 3);
    return GetLineCross(v1,b,v2,c);
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        Point a , b , c;
        scanf("%lf%lf",&a.x,&a.y);
        scanf("%lf%lf",&b.x,&b.y);
        scanf("%lf%lf",&c.x,&c.y);
        Point d = GetPoint(a,b,c);
        Point e = GetPoint(b,c,a);
        Point f = GetPoint(c,a,b);
        printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",d.x,d.y,e.x,e.y,f.x,f.y);
    }
    return 0;
}


11178 - Morley's Theorem【几何】

标签:style   http   color   os   使用   io   ar   2014   cti   

原文地址:http://blog.csdn.net/u013451221/article/details/38929423

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