UVA_11178_Morley's_Theorem_(计算几何基础)
描述
Morley定理:作三角形ABC每个内角的三等分线,相交形成三角形DEF,则三角形DEF是等边三角形.
给出三角形的三个顶点ABC的坐标,求出DEF的坐标.
11178 - Morley's Theorem
Time limit: 3.000 seconds
Morleys theorem states that that the lines
trisecting the angles of an arbitrary plane
triangle meet at the vertices of an equi-
lateral 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 gen-
eralizations, 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 inter-
sected 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 six integers X A , Y A , X B , Y B , X C , Y C . This six
integers actually indicates that the Cartesian coordinates of point A, B and C are (X A , Y A ),(X B , Y B )
and (X C , Y C ) respectively. You can assume that the area of triangle ABC is not equal to zero, 0 ≤
X A , Y A , X B , Y B , X C , Y C ≤ 1000 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 X D , Y D , X E , Y E , X F , Y F separated by a single space. These six floating-point actually means
that the Cartesian coordinates of D, E and F are (X D , Y D ),(X E , Y E ) ,(X F , Y F ) respectively. Errors
less than 10 −5 will be accepted.
Sample Input
2
1 1 2 2 1 2
0 0 100 0 50 50
Sample Output
1.316987 1.816987 1.183013 1.683013 1.366025 1.633975
56.698730 25.000000 43.301270 25.000000 50.000000 13.397460
分析
DEF三个点的求法是一样的,来看D:
将向量BC逆时针旋转(角ABC)/3,将向量CB顺时针旋转(角ACB)/3,分别得到了直线BD和直线CD的方向向量,再加上点B,C,可以写出直线BD和直线CD(参数方程),然后求两直线的交点即可.
注意:
1.get函数中的后两个参数不可颠倒,因为一边是逆时针转,另一边是顺时针转.
#include <bits/stdc++.h>
using namespace std; const double eps=1e-;
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y){}
};
typedef Point Vector; Vector operator + (Point a,Point 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 * (Point a,double p){ return Vector(a.x*p,a.y*p); }
double dot(Vector a,Vector b){ return a.x*b.x+a.y*b.y; }//点积
double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; }//叉积
double length(Vector a){ return sqrt(dot(a,a)); }//向量的模
double angle(Vector a,Vector b){ return acos(dot(a,b)/length(a)/length(b)); }//两向量夹角
Vector rotate(Vector a,double rad){ return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad)); }//将向量a逆时针旋转rad(弧度制)
Point get_line_intersection(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 get(Point A,Point B,Point C){//分别算DEF三个点的函数
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 get_line_intersection(B,v1,C,v2);
}
int main(){
int n;
Point A,B,C,D,E,F;
scanf("%d",&n);
while(n--){
scanf("%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y);
D=get(A,B,C);//这里B,C不能写反,因为一个是逆时针转,另一个时顺时针转
E=get(B,C,A);
F=get(C,A,B);
printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",D.x,D.y,E.x,E.y,F.x,F.y);
}
return ;
}
UVA_11178_Morley's_Theorem_(计算几何基础)的更多相关文章
- nyis oj 68 三点顺序 (计算几何基础)
三点顺序 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 如今给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,如今让你推断A,B,C是顺时针给出的还是逆 ...
- 【BZOJ】1043: [HAOI2008]下落的圆盘(计算几何基础+贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1043 唯一让我不会的就是怎么求圆的周长并QAAQ... 然后发现好神!我们可以将圆弧变成$[0, 2 ...
- 计算几何基础——矢量和叉积 && 叉积、线段相交判断、凸包(转载)
转载自 http://blog.csdn.net/william001zs/article/details/6213485 矢量 如果一条线段的端点是有次序之分的话,那么这种线段就称为 有向线段,如果 ...
- BZOJ_1610_[Usaco2008_Feb]_Line连线游戏_(计算几何基础+暴力)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1610 给出n个点,问两两确定的直线中,斜率不同的共有多少条. 分析 暴力枚举直线,算出来斜率放 ...
- 二维计算几何基础题目泛做(SYX第一轮)
题目1: POJ 2318 TOYS 题目大意: 给一个有n个挡板的盒子,从左到右空格编号为0...n.有好多玩具,问每个玩具在哪个空格里面. 算法讨论: 直接叉积判断就可以.注意在盒子的边界上面也算 ...
- 计算几何基础算法几何C++实现
This file is implementation of Common Common Computational Geometry Algorithms.Please please pay att ...
- 【POJ】1556 The Doors(计算几何基础+spfa)
http://poj.org/problem?id=1556 首先路径的每条线段一定是端点之间的连线.证明?这是个坑...反正我是随便画了一下图然后就写了.. 然后re是什么节奏?我记得我开够了啊.. ...
- 【POJ】2318 TOYS(计算几何基础+暴力)
http://poj.org/problem?id=2318 第一次完全是$O(n^2)$的暴力为什么被卡了-QAQ(一定是常数太大了...) 后来排序了下点然后单调搞了搞..(然而还是可以随便造出让 ...
- 【POJ】2653 Pick-up sticks(计算几何基础+暴力)
http://poj.org/problem?id=2653 我很好奇为什么这样$O(n^2)$的暴力能过.... 虽然说这是加了链表优化的,但是最坏不也是$O(n^2)$吗...(只能说数据太弱.. ...
随机推荐
- SQL Server调优系列基础篇 - 联合运算符总
前言 上两篇文章我们介绍了查看查询计划的方式,以及一些常用的连接运算符的优化技巧,本篇我们总结联合运算符的使用方式和优化技巧. 废话少说,直接进入本篇的主题. 技术准备 基于SQL Server200 ...
- 解决Android Studio启动速度慢的问题。避免每次启动Android Studio都要fetching Android sdk compoment information。
Android Studio每次启动都要去fetching sdk,由于Android sdk 官网在大陆连不上,所以每次启动时界面都会停在那里很久. 解决办法就是设置取消每次fetching sdk ...
- json(gson) 转换html标签带来的麻烦
gson 转换html标题时,会把html(特殊字符转换为unicode编码) ,所以为了避免这个问题GsonBuilder类 有一个 disablehtmlEscaping方法. 就可以让gson类 ...
- Swift 学习手记1,pod 的 类库使用
问题: 在Swift中,我们无法使用像Objective-c 一样的 #import 例如 在头部输入 #import <ReactiveCocoa/ReactiveCocoa.h> 是不 ...
- c编程:提示用户输入一个0—9的数字进行猜测电脑产生的随机数。一共有三次机会。
// // main.c // 使用c语言进行编程: 题目:由电脑生成一个由0-9之间的随机数,提示用户也输入一个数字进行猜测.当猜测三次仍不中的时候结束程序. 编译环境:Xcode6.3 特别介 ...
- C#操作redis代码汇总
马上要用redis来改造现有的o2o项目了,在linux下部署了个redis,顺便研究了下代码操作,分享下代码 using System; using System.Collections.Gener ...
- struts2 I18n问题 国际化
java国际化 1.了解缺省Locale是由操作系统决定的,Locale是由语言和国家代码组成 2.国际化资源文件是由baseName+locale组成,如:MessageBundle_en_US.p ...
- IntelliJ IDEA14 和 Maven 系列:使用IntelliJ IDEA 14和Maven 7 创建java web项目(一)
Intellij IDEA作为最好的Java IDE,创建Maven项目还是比较简单的,但是创建一个Maven Web项目还是要修改一些配置的,下面进行总结整理. 1前言 在创建项目中,IDEA提供了 ...
- 桶排序之python实现源码
tmp = [] def bucket_sort(old): for i in range(len(old)): tmp.append([]) for i in old: tmp[int( i * l ...
- mysql主从之主键冲突
收到短信报警,两台数据库都报slave同步失败了,先说明一下环境,架构:lvs+keepalived+amoeba+mysql,主主复制,单台写入, 主1:192.168.0.223(写) 主2:19 ...