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. bzoj-1492 货币兑换Cash (2)——CDQ分治

    题意: 略 见上一篇 题解: 方程还是那个方程f[i]=A[i] * X[j] + B[i] * Y[j]. 化简为Y[i]=(-A[i]/B[i]) * X[i] + f[i]/B[i]这一坨: 既 ...

  2. Qt 5.3更新无数,更改C++控制台输出最为赞

    迁移至 多色网

  3. 如何判断自己家的宽带是否有公网IP

    1)点击链接 http://www.net.cn/static/customercare/yourIP.asp 抓取自己的IP地址 2)打开一个命令提示符窗口 tracert <刚才获取的IP& ...

  4. 这些小工具让你的Android 开发更高效

    在做Android 开发过程中,会遇到一些小的问题.尽管自己动手也能解决.可是有了一些小工具,解决这些问题就得心应手了,今天就为大家推荐一下Android 开发遇到的小工具,来让你的开发更高效. Vy ...

  5. 【JS】jQuery中将数组转换成字符串join()和push()使用

    1.push()将元素依次添加至数组:2.join()将数组转换成字符串,里面可以带参数分隔符,默认[,] <script type = text/javascript> $(docume ...

  6. 列举一些常见的系统系能瓶颈 Common Bottlenecks

    http://www.nowamagic.net/librarys/veda/detail/2408在 Zen And The Art Of Scaling - A Koan And Epigram ...

  7. C#中byte类型转换为double类型

    // Initialize unmanged memory to hold the array. int size = Marshal.SizeOf(bytes[0]) * bytes.Length; ...

  8. machine_learning-knn算法具体解释(近邻算法)

    近邻算法是机器学习算法中的入门算法,该算法用于针对已有数据集对未知数据进行分类. 该算法核心思想是通过计算预測数据与已有数据的相似度猜測结果. 举例: 如果有例如以下一组数据(在下面我们统一把该数据作 ...

  9. jQuery操作CheckBox的方法(选中,取消,取值)

    jQuery操作CheckBox的方法(选中,取消,取值). 代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional/ ...

  10. IP地址欺骗

    1.什么是IP地址欺骗按照IP网络协议,数据包头包含来源地和目的地信息,而IP地址欺骗,就是通过伪造数据包爆头,使显示的信息源不是实际的来源,就像这个数据包是从另一台计算机上发送的. 2.IP地址欺骗 ...