Morley's Theorem (计算几何基础+向量点积、叉积、旋转、夹角等+两直线的交点)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2119
题面:Morleys 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 trisectors 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 six integers XA,YA,XB,YB,XC,YC. This six integers actually indicates that the Cartesian coordinates of point A, B and C are (XA,YA),(XB,YB) and (XC,YC) respectively. You can assume that the area of triangle ABC is not equal to zero, 0 ≤ XA,YA,XB,YB,XC,YC ≤ 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 XD,YD,XE,YE,XF,YF separated by a single space. These six floating-point actually means that the Cartesian coordinates of D, E and F are (XD,YD),(XE,YE) ,(XF,YF) 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的话,就只需通过套用模板即可解决
代码实现如下:
#include <cstdio>
#include <cmath>
using namespace std; struct Point{
double x,y;
Point(double x = , double y = ) : x(x), y(y) {}
}; typedef Point Vector; int t;
Point A, B, C, D, E, F; Vector operator + (Vector A, Vector B){
return Vector(A.x + B.x, A.y + B.y);
} Vector operator - (Vector A, Vector 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);
} double Dot(Vector A, Vector B){
return A.x * B.x + A.y * B.y;
} 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));
} double Cross(Vector A, Vector B){
return A.x * B.y - A.y * B.x;
} 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 GetD(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(){
scanf("%d", &t);
while(t--){
scanf("%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y);
D = GetD(A, B, C);
E = GetD(B, C, A);
F = GetD(C, A, B);
printf("%.6f %.6f %.6f %.6f %.6f %.6f\n", D.x, D.y, E.x, E.y, F.x, F.y);
}
}
Morley's Theorem (计算几何基础+向量点积、叉积、旋转、夹角等+两直线的交点)的更多相关文章
- 51nod--1265 四点共面 (计算几何基础, 点积, 叉积)
题目: 1265 四点共面 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出三维空间上的四个点(点与点的位置均不相同),判断这4个点是否在同一个平面内(4 ...
- Uva 11178 Morley's Theorem 向量旋转+求直线交点
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9 题意: Morlery定理是这样的:作三角形ABC每个 ...
- UVA_11178_Morley's_Theorem_(计算几何基础)
描述 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=23&pag ...
- uva 11178二维几何(点与直线、点积叉积)
Problem D Morley’s Theorem Input: Standard Input Output: Standard Output Morley’s theorem states tha ...
- AC日记——向量点积计算 openjudge 1.6 09
09:向量点积计算 总时间限制: 1000ms 内存限制: 65536kB 描述 在线性代数.计算几何中,向量点积是一种十分重要的运算. 给定两个n维向量a=(a1,a2,...,an)和b=(b ...
- UVa 11178:Morley’s Theorem(两射线交点)
Problem DMorley’s TheoremInput: Standard Input Output: Standard Output Morley’s theorem states that ...
- UVA 11178 Morley's Theorem(几何)
Morley's Theorem [题目链接]Morley's Theorem [题目类型]几何 &题解: 蓝书P259 简单的几何模拟,但要熟练的应用模板,还有注意模板的适用范围和传参不要传 ...
- SAM4E单片机之旅——24、使用DSP库求向量数量积
DSP(Digital Signal Processing,数字信号处理)中会使用大量的数学运算.Cortex-M4中,配置了一些强大的部件,以提高DSP能力.同时CMSIS提供了一个DSP库,提供了 ...
- uva11178 Morley’s Theorem(求三角形的角三分线围成三角形的点)
Morley’s Theorem Input: Standard Input Output: Standard Output Morley’s theorem states that that the ...
随机推荐
- OSPF学习中的问题
OSPF对接两方,对设置的要求,哪些参数必须相同 (HELLO &dead interval, area ID, authentation, 末节区域(option中的E位), network ...
- 【redis数据库学习】用JAVA连接redis数据库各种报错
最近项目中,需要用到redis数据库,然后使用Jedis让JAVA连接redis. 首先,安装redis数据库,参考的是:http://www.runoob.com/redis/redis-insta ...
- 关于设置Visaul Studio 2010 代码编辑界面背景的方法
1.打开代码编辑界面: 2.找到工具--选项: 3.打开选项后选中纯文本--项背景色: 4.点击自定义,找到自己需要的颜色: [注]: “项前景色”即代码的颜色: “项背景色”即背景颜色. 设置好后, ...
- ExtremeComponents源码解析(一)
一.前言 因参与公司框架改造,在负责前端table组件选型时,原本选了jqGrid和Bootstraptable作为备选方案,评审会上,武哥提了EXtremeComponents,让我也去了解下,看下 ...
- 路由分发原则 get最终传递给get post最终传递给post
- BZOJ 1806 矿工配餐(DP)
很水的DP. 因为每一个餐车的加入只需要知道当前矿洞的前两个餐车种类就行了.而餐车一共就三种. 所以令dp[i][Sa][Sb]表示前i辆餐车送餐完毕后第一个矿洞的前两个餐车种类为Sa,第二个矿洞的前 ...
- 【bzoj4491】我也不知道题目名字是什么 离线扫描线+线段树
题目描述 给定一个序列A[i],每次询问l,r,求[l,r]内最长子串,使得该子串为不上升子串或不下降子串 输入 第一行n,表示A数组有多少元素接下来一行为n个整数A[i]接下来一个整数Q,表示询问数 ...
- CF484E Sign on Fence && [国家集训队]middle
CF484E Sign on Fence #include<bits/stdc++.h> #define RG register #define IL inline #define _ 1 ...
- Leetcode中单链表题总结
以下是个人对所做过的LeetCode题中有关链表类型题的总结,博主小白啊,若有错误的地方,请留言指出,谢谢. 一.有关反转链表 反转链表是在单链表题中占很大的比例,有时候,会以各种形式出现在题中,是比 ...
- sass的mixin,extend,placeholder,function
1. mixin 就是定义了一个函数,可以传参,并且设定默认值,css选择器可以通过@include来引用,mixin混入的代码,就是原样复制,不会合并,会造成冗余 例如: @mixin br6($b ...