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 the tri-sectors of angles A, B and C has intersected and created an equilateral triangle DEF.

Of course the theorem has various generalizations, in particular if all of the tri-sectors are intersected one obtains four other equilateral triangles. But in the original theorem only tri-sectors nearest to BC are allowed to intersect to get point D, tri-sectors nearest to CA are allowed to intersect point E and tri-sectors nearest to AB are intersected to get point F. Trisector like BD and CE are not allowed to intersect. So ultimately we get only one equilateral triangle DEF. Now your task is to find the Cartesian coordinates of D, E and F given the coordinates of A, B, and C.

Input

First line of the input file contains an integer N (0<N<5001) which denotes the number of test cases to follow. Each of the next lines contain sixintegers . This six integers actually indicates that the Cartesian coordinates of point A, B and C are  respectively. You can assume that the area of triangle ABC is not equal to zero,  and the points A, B and C are in counter clockwise order.

Output

For each line of input you should produce one line of output. This line contains six floating point numbers  separated by a single space. These six floating-point actually means that the Cartesian coordinates of D, E and F are  respectively. Errors less than   will be accepted.

Sample Input   Output for Sample Input

2
1 1 2 2 1 2
0 0 100 0 50 50

1.316987 1.816987 1.183013 1.683013 1.366025 1.633975

56.698730 25.000000 43.301270 25.000000 50.000000 13.397460

 

Problemsetters: Shahriar Manzoor

Special Thanks: Joachim Wulff


  计算几何基础练习,求两射线交点

  题意

  Morley定理是这样的:作三角形ABC每个内角的三等分线,相交成三角形DEF,则DEF是等边三角形,如图所示。

  你的任务是根据A、B、C 3个点的位置确定D、E、F 3个点的位置。

  ———— 《算法竞赛入门经典——训练指南》

  思路

  分别求出三角形每对顶点形成内角的三等分线,求这两条三等分线的交点。

  因为是练习基础的一道题,所以我自己敲了好几个模板,但实际上只用到了求交点的函数,求2向量角度的函数以及向量旋转的函数,没有太复杂的算法,思路很好理解。

  代码

 #include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y) {} //构造函数
};
typedef Point Vector;
//向量 + 向量 = 向量
Vector operator + (Vector A,Vector B)
{
return Vector(A.x + B.x,A.y + B.y);
}
//点 - 点 = 向量
Vector operator - (Point A,Point B)
{
return Vector(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);
}
const double eps = 1e-;
//减少精度问题
int dcmp(double x)
{
if(fabs(x)<eps)
return ;
else
return x<?-:;
}
bool operator == (const Point& a,const Point& b)
{
return dcmp(a.x-b.x)== && dcmp(a.y-b.y)==;
}
double Dot(Vector A,Vector B)
{
return A.x*B.x + A.y*B.y;
}
double Length(Vector A)
{
return sqrt(A.x*A.x + A.y*A.y);
}
//求两向量夹角的弧度
double Angle(Vector A,Vector B)
{
return acos(Dot(A,B) / Length(A) / Length(B));
}
//求叉积
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);
}
Vector Rotate(Vector A,double rad)
{
return Vector(A.x*cos(rad) - A.y*sin(rad),A.x*sin(rad) + A.y*cos(rad));
}
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
{
Vector u = P-Q;
double t = Cross(w,u) / Cross(v,w);
return P+v*t;
}
Point GetPoint(Point A,Point B,Point C)
{
Vector v1 = C-B;
double a1 = Angle(A-B,v1);
v1 = Rotate(v1,a1/); Vector v2 = B-C;
double a2 = Angle(A-C,v2);
v2 = Rotate(v2,-a2/); //负数代表顺时针旋转 return GetLineIntersection(B,v1,C,v2);
} int main()
{
int n;
cin>>n;
while(n--){
Point a,b,c,d,e,f;
cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;
d = GetPoint(a,b,c);
e = GetPoint(b,c,a);
f = GetPoint(c,a,b);
cout<<setiosflags(ios::fixed)<<setprecision();
cout<<d.x<<' '<<d.y<<' '
<<e.x<<' '<<e.y<<' '
<<f.x<<' '<<f.y<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

UVa 11178:Morley’s Theorem(两射线交点)的更多相关文章

  1. uva 11178 - Morley's Theorem

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. 简单几何(求交点) UVA 11178 Morley's Theorem

    题目传送门 题意:莫雷定理,求三个点的坐标 分析:训练指南P259,用到了求角度,向量旋转,求射线交点 /*********************************************** ...

  3. UVA 11178 Morley's Theorem (坐标旋转)

    题目链接:UVA 11178 Description Input Output Sample Input Sample Output Solution 题意 \(Morley's\ theorem\) ...

  4. UVA 11178 Morley's Theorem(几何)

    Morley's Theorem [题目链接]Morley's Theorem [题目类型]几何 &题解: 蓝书P259 简单的几何模拟,但要熟练的应用模板,还有注意模板的适用范围和传参不要传 ...

  5. Uva 11178 Morley's Theorem 向量旋转+求直线交点

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9 题意: Morlery定理是这样的:作三角形ABC每个 ...

  6. UVA 11178 Morley's Theorem(旋转+直线交点)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18543 [思路] 旋转+直线交点 第一个计算几何题,照着书上代码打 ...

  7. UVA 11178 - Morley's Theorem 向量

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. UVa 11178 Morley's Theorem (几何问题)

    题意:给定三角形的三个点,让你求它每个角的三等分线所交的顶点. 析:根据自己的以前的数学知识,应该很容易想到思想,比如D点,就是应该求直线BD和CD的交点, 以前还得自己算,现在计算机帮你算,更方便, ...

  9. UVA 11178 Morley's Theorem 计算几何模板

    题意:训练指南259页 #include <iostream> #include <cstdio> #include <cstring> #include < ...

随机推荐

  1. 【微信开发】JS和PHP分别判断当前浏览器是否微信浏览器

    1.PHP端 //判断是否微信浏览器 -xzz1125 function is_weixin() { if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMes ...

  2. mysql索引二

    理解MySQL——索引与优化 写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优 的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储1 ...

  3. SIFT 、Hog 、LBP 了解

    SIFT.HOG.LBP,这三者都属于局部特征. 一.三者原理上的区别 1.SIFT:Scale-Invariant Feature Taransform,尺度不变特征变换. 尺度空间的极值检测:搜索 ...

  4. ubuntu下将CapsLock改为Ctrl键

    需求:Ubuntu下用Vim时,ESC因为在左上角,还算是好按,但是Ctrl就太坑了,在左右两个下角,实在是太不方便了. 经过分析决定将:CapsLock键改为Ctrl,但仍然保留下面的原Ctrl键( ...

  5. Atitit. 悬浮窗口的实现 java swing c# .net c++ js html 的实现

    Atitit. 悬浮窗口的实现 java swing c# .net c++ js html 的实现 1. 建立悬浮窗口引用代码 1 1.1. 定义悬浮窗口,设置this主窗口引用,是为了在悬浮窗口中 ...

  6. sqlzoo练习答案--SUM and COUNT

    World Country Profile: Aggregate functions This tutorial is about aggregate functions such as COUNT, ...

  7. Java多线程简析——Synchronized(同步锁)、Lock以及线程池

    Java多线程 Java中,可运行的程序都是有一个或多个进程组成.进程则是由多个线程组成的.最简单的一个进程,会包括mian线程以及GC线程. 线程的状态 线程状态由以下一张网上图片来说明: 在图中, ...

  8. Struts2初学 struts2自定义类型转换器

    一.问题的引出      Struts2的类型转换是基于OGNL表达式的,由于请求的参数都是字符串,而JAVA 本身属于强类型的的语言,这样就需要把请求参数字符串转换成其他类型.     Struts ...

  9. XML异步请求实例

    其实还是很格式化的: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type&qu ...

  10. CSS学习笔记(4)--选择器(w3school)

    CSS3 选择器 在 CSS 中,选择器是一种模式,用于选择需要添加样式的元素. "CSS" 列指示该属性是在哪个 CSS 版本中定义的.(CSS1.CSS2 还是 CSS3.) ...