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 < ...
随机推荐
- xml xpath dta笔记
xml: 有且只有一个根元素 默认utf-8 如果是中文且为不是utf-8的必须指定编码 声明的编码必须和文档的内容保持一致 well-formed XML :是否符合xml语法 valid xml: ...
- JDBC 调用存储过程代码示例
曾经有过一个两层构架的时代,前台就是界面,后台就是存储过程,存储过程把业务逻辑和数据操作一手包办了. 用存储过程写东西比较复杂,大部分Java程序员或许都对此不太了解,因为我们如今的三层架构使用高级语 ...
- 解决ssh登录Host key verification failed
使用SSH登录某台机器,有时因为server端的一些变动,会出现以下信息: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: R ...
- python 火车票爬取代码
1.根据搜索词下载百度图片: # -*- coding: utf-8 -*- """根据搜索词下载百度图片""" import re imp ...
- 使用 hibernate validator 进行表单验证
1 引入依赖,如果是 Maven 项目,仅需要添加如下依赖.官网请查看http://hibernate.org/validator/documentation/getting-started/ < ...
- linux kill 关闭进程命令
杀死进程最安全的方法是单纯使用kill命令,不加修饰符,不带标志. 首先使用ps -ef命令确定要杀死进程的PID,然后输入以下命令: # kill -pid 注释:标准的kill命令通常都能达到目的 ...
- 输入LPCWSTR类型字符串
LPCWSTR tmp = L"xxx"; char*转到LPCWSTR LPCSTR(charTmp)
- atitit.获取connection hibernate4
atitit.获取connection hibernate4 1. SessionFactoryUtils法(推荐) 1 2. ConnectionProvider 法( ) 1 3. 嘎自实现法(不 ...
- atitit.MyEclipse10 中增加svn插件故障排除
atitit.MyEclipse10 中增加svn插件故障排除 删除\configuration \org.eclipse.update 不行... 二. 在configuration下的config ...
- 实用crontab命令
常用crontab如下: crontab -e 编辑 crontabcrontab -l 显示 crontabcrontab -r 删除 crontabcrontab -v 显示上一次编辑 cro ...