UVa 11178:Morley’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 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(两射线交点)的更多相关文章
- uva 11178 - Morley's Theorem
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 简单几何(求交点) UVA 11178 Morley's Theorem
题目传送门 题意:莫雷定理,求三个点的坐标 分析:训练指南P259,用到了求角度,向量旋转,求射线交点 /*********************************************** ...
- UVA 11178 Morley's Theorem (坐标旋转)
题目链接:UVA 11178 Description Input Output Sample Input Sample Output Solution 题意 \(Morley's\ theorem\) ...
- UVA 11178 Morley's Theorem(几何)
Morley's Theorem [题目链接]Morley's Theorem [题目类型]几何 &题解: 蓝书P259 简单的几何模拟,但要熟练的应用模板,还有注意模板的适用范围和传参不要传 ...
- Uva 11178 Morley's Theorem 向量旋转+求直线交点
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9 题意: Morlery定理是这样的:作三角形ABC每个 ...
- UVA 11178 Morley's Theorem(旋转+直线交点)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18543 [思路] 旋转+直线交点 第一个计算几何题,照着书上代码打 ...
- UVA 11178 - Morley's Theorem 向量
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 11178 Morley's Theorem (几何问题)
题意:给定三角形的三个点,让你求它每个角的三等分线所交的顶点. 析:根据自己的以前的数学知识,应该很容易想到思想,比如D点,就是应该求直线BD和CD的交点, 以前还得自己算,现在计算机帮你算,更方便, ...
- UVA 11178 Morley's Theorem 计算几何模板
题意:训练指南259页 #include <iostream> #include <cstdio> #include <cstring> #include < ...
随机推荐
- Java同步机制总结--synchronized
不久前用到了同步,现在回过头来对JAVA中的同步做个总结,以对前段时间工作的总结和自我技术的条理话.JAVA中synchronized关键字能够 作为函数的修饰符,也可作为函数内的语句,也就是平时说的 ...
- Java泛型中extends和super的理解
作者:zhang siege链接:https://www.zhihu.com/question/20400700/answer/91106397来源:知乎著作权归作者所有.商业转载请联系作者获得授权, ...
- 【LeetCode】100. Same Tree (2 solutions)
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- 常见URL字符及URL编码值
大家上网的时候一定会看到很多这类情况有的网页地址都是%22%32%11%23%21等这种机器语言恐怕只有机器能马上辨认吧现在我把大概知道的总结一下 字符 ...
- TextWatcher
对于一些需求,如非法字符限制(例如不允许输入#号,如果输入了#给出错误提示),做成动态判断更方便一些,而且容易扩展: 在Android里使用TextWatcher接口可以很方便的对EditText进行 ...
- EasyUI combobox的panelHeight自动高度
在使用EasyUI的时候,有时会用到combobox组件,这里的记录数不是很固定,设置为auto可能会被挡住,设置固定高度时,option很少时,也很丑 所以这里给出我自己自动调整combobox的p ...
- Atitit . 编程模型的变革总结
Atitit . 编程模型的变革总结 1. 面向对象与面向过程程序设计有如下不同: 1 1.1. 函数与数据是否分离.... 1 1.2. 以功能为中心;以数据为中心..... 1 1.3. 事件驱 ...
- Object-C支持多继承吗?可以实现多个接口吗?Category是什么?
转自:http://blog.sina.com.cn/s/blog_7afd7d7801016t3t.html Object-C支持多继承吗?可以实现多个接口吗?Category是什么?重写一个类的方 ...
- mount -o remount,rw / (这是个求命的命令)
当系统无法启动的时候.我们会前进入单用户模式(正常情况下单用户莫式是权限是正常的,只在在无法启动的情况下, 再进入单用户模式,权限才会是只读),这时候没有对文件的修改权限(所有的文件都是只读) 用这条 ...
- 进程控制函数(2)-setpgid() 修改当前进程的进程组ID
定义:int setpgid(pid_t pid,pid_t pgid); 表头文件:#include<unistd.h> 说明:setpgid()将参数pid 指定进程所属的组识别码设为 ...