Molly's theorem (Morley's theorem), also known as the three-point theorem of the Morey angle. The three inner corners of the triangle are divided into three equal points, and the two three-point lines near one side intersect to get an intersection, so that three intersections can form a positive triangle. This triangle is often called the Molly Triangle.
11178-morley ' s theorem Time limit:3.000 seconds |
Morley ' s theorem
Input: standard input
Output: Standard Output
Morley ' s theorem states that, the lines trisecting the angles of a arbitrary plane triangle meet at the vertices of a n equilateral triangle. For example in the figure below the tri-sectors of Angles A, B and C have intersected and created an equilateral triangle D Ef.
Of course the theorem have various generalizations, in particular if all of the tri-sectors is intersected one obtains fou R other equilateral triangles. But the original theorem is tri-sectors nearest to BC is allowed to intersect to get point D, tri-sectors nearest to CA is allowed to intersect point E and tri-sectors nearest to AB is intersected to get point F. trisector like BD and C E is not allowed to intersect. So ultimately we get only one equilateral triangle DEF. Now your task was 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 a integer N (0<n<5001) which denotes the number of test cases to follow. Each of the next lines contain six integers. This six integers actually indicates is the Cartesian coordinates of Point A, B and C is respectively. You can assume this area of Triangle ABC was not equal to zero, and the points A, B and C were in counter clockwise Ord Er. output for each line of input should produce one line of output. This line contains six floating point numbers separated is a single space. These six floating-point actually means that the Cartesian coordinates of D, E and F is respectively. Errors less than'll 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
|
refer to the introduction to algorithmic competition-the fourth chapter of the training guide-Calculating Geometry
Reference code + partial comment
#include <iostream> #include <cstdio> #include <algorithm> #include <map> #include <vector > #include <queue> #include <cstring> #include <cmath> #include <climits> #define EPS 1e-10 usi
NG namespace Std;
typedef long Long LL;
const int Inf=int_max;
const int MAXN = 110;
int dcmp (double x) {///three-state function, overcoming floating-point precision traps, judging x==0?x<0?x>0?
if (fabs (x) <eps) return 0;else return x<0?-1:1;
} struct point{double x, y;
Point (Double x=0,double y=0): X (x), Y (y) {}//constructor, convenient for code writing};
typedef point Vector;//vector is the alias of point 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);} bool operator < (const point& A,const point& b) {return a.x<b.x| |
(A.X==B.X&&A.Y<B.Y);} BOOL operator = = (Const point& a,const Point& b) {return dcmp (a.x-b.x) ==0&&dcmp (A.Y-B.Y) ==0;} 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, A)/length (A)/length (B)), Double Cross (Vector a,vector B) {return a.x*b.y-a.y*b.x;}
Rad is radian is not angular vector Rotate (vector a,double rad) {return vector (A.x*cos (RAD)-a.y*sin (RAD), A.x*sin (RAD) +a.y*cos (RAD));} Make sure that the two lines p+tv,q+tw have a unique intersection before calling.
When and only if Cross (v,w) is not 0 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/3);//positive indicates counterclockwise rotation of the Vector v2=b-c;
Double A2=angle (A-C,V2);
V2=rotate (V2,-A2/3);//negative indicates clockwise rotation of return getlineintersection (B,V1,C,V2);
} int main () {//Freopen ("Input.txt", "R", stdin);
Point A,b,c,d,e,f;
int t;cin>>t; while (t--) {cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;
D=GETD (A,B,C);
E=GETD (b,c,a);//Note the direction corresponds to F=GETD (C,A,B);
printf ("%f%f%f%f%f%f\n", d.x,d.y,e.x,e.y,f.x,f.y);
} return 0;
}