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 < ...
随机推荐
- 在MVC的cshtml视图页获取默认路由下的ID值的方法
<a href="/user/resume/index/11"> <span class="title bold">我的 @Reques ...
- knockoutjs -- applyBinding & Observables
applyBindings ko.applyBindings(myViewModel); // Knockout调用applyBindings激活myViewModel(即把myViewModel和V ...
- 17-spring学习-AOP初步实现
AOP是面向方面的编程,在实际开发中,AOP都会工作在业务层,因为业务层要调用数据层,而业务层也要完成所有辅助性的业务层操作. 范例:定义业务层操作接口: package com.Spring.Ser ...
- 简述document.write和 innerHTML的区别。
document.write是重写整个document, 写入内容是字符串的htmlinnerHTML是HTMLElement的属性,是一个元素的内部html内容
- 用ping让对方电脑堵塞瘫痪
用ping让对方电脑堵塞瘫痪2008-04-27 11:32 定义echo数据包大小. 在默认的情况下windows的ping发送的数据包大小为32byt,我们也可以自己定义它的大小, 但有一个大小的 ...
- Windows下phpStudy中的Apache无法启动的排查方法
尝试一:检查端口占用问题 刚开始以为是端口占用,使用 phpStudy 自带的端口检测,查看并没有占用.在 cmd 控制台中输入:services.msc 去系统服务里面看,单独配置的 Apache ...
- php保存快捷方式到桌面
/** * 保存首页到桌面 */ public function save_shortcut() { $shortcut = "[DEFAULT] BASEURL=http://www.19 ...
- C语言的存储类型和关键字extern、static
1.C语言中每个变量都有3个性质:存储期限.作用域.链接 1)存储期限:变量的存储期限决定了为变量预留的内存被释放的时间.共2种,自动存储期限(auto),静态存储期限(static),自动存储(au ...
- vim中不同模式的帮助信息的查找
vim的模式有多种,比如normal(普通模式),insert(插入模式),command(命令行模式),visual(可视化模式).相同的命令和快捷键在不同的模式下功能是不一样的,因此帮助信息也是分 ...
- linux中录屏工具byzanz
linux中录屏工具byzanz: 1.安装 sudo apt install byzanz 2.使用 help:byzanz-record --help 配合xwininfo使用--xwininfo ...