11178 - Morley's Theorem【几何】

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

如果一个向量进行逆时针旋转,那么可以使用定义的函数 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【几何】

时间: 2024-10-13 22:53:23

11178 - Morley's Theorem【几何】的相关文章

UVa 11178 Morley&#39;s Theorem (几何问题)

题意:给定三角形的三个点,让你求它每个角的三等分线所交的顶点. 析:根据自己的以前的数学知识,应该很容易想到思想,比如D点,就是应该求直线BD和CD的交点, 以前还得自己算,现在计算机帮你算,更方便,主要注意的是旋转是顺时针还是逆时针,不要搞错了. 要求BD和CD就得先求那个夹角ABC和ACD,然后三等分. 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <cmath&

简单几何 UVA 11178 Morley&#39;s Theorem

题目传送门 题意:莫雷定理,求三个点的坐标 分析:训练指南P259,用到了求角度,向量旋转,求射线交点 /************************************************ * Author :Running_Time * Created Time :2015/10/21 星期三 15:56:27 * File Name :UVA_11178.cpp ************************************************/ #include

UVA 11178 Morley&#39;s Theorem 计算几何

计算几何: 最基本的计算几何,差积  旋转 Morley's Theorem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the line

UVA 11178 Morley&#39;s Theorem(旋转+直线交点)

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18543 [思路] 旋转+直线交点 第一个计算几何题,照着书上代码打的. [代码] 1 #include<cstdio> 2 #include<cmath> 3 #include<cstring> 4 using namespace std; 5 6 7 struct Pt { 8 double x,y; 9 Pt(double x=0,d

UVA - 11178 - Morley&#39;s Theorem (计算几何~~)

UVA - 11178 Morley's Theorem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecti

uva 11178 Morley&#39;s Theorem(计算几何-点和直线)

Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below

UVA 11178 Morley’s Theorem(莫雷定理 计算几何)

Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below the tri-s

uva 11178 Morley&amp;#39;s Theorem(计算几何-点和直线)

Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below

莫利定理:UVa 11178 Morley&#39;s Theorey

莫利定理(Morley's theorem),也称为莫雷角三分线定理.将三角形的三个内角三等分,靠近某边的两条三分角线相交得到一个交点,则这样的三个交点可以构成一个正三角形.这个三角形常被称作莫利正三角形. 11178 - Morley's Theorem Time limit: 3.000 seconds 参考<算法竞赛入门经典--训练指南>第四章 计算几何 参考代码+部分注释 #include <iostream> #include <cstdio> #includ