Uva_11178_morley ' s_theorem_ (vector rotation + straight line intersection)

Source: Internet
Author: User
Tags cos

Describe

Https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=23&page=show_ problem&problem=2119

Morley theorem: Make triangle ABC each inner corner of the three equal lines, intersect to form the triangle Def, then the triangle def is equilateral triangle.

Give the coordinates of the three vertex ABC of the triangle, and find the coordinates of def.

11178-morley ' s theorem

Time limit:3.000 seconds

Morleys theorem states that, the lines
Trisecting the angles of an arbitrary plane

Triangle meet at the vertices of a equi-
Lateral triangle. For example in the figure
Below the tri-sectors of Angles A, B and C
Have intersected and created an equilateral
Triangle DEF.
Of course the theorem has various gen-
Eralizations, in particular if all of the tri-
Sectors is intersected one obtains four
Other equilateral triangles. But in the
Original theorem only 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 inter-
Sected to get Point F. trisector like BD and CE 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 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 is (x A, y a), (x B, y B)
and (X C, Y c) respectively. You can assume this area of Triangle ABC was 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 is in counter clockwise order.
Output
For each line of input 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 is (x D, y D), (x e, y E), (x F, y F) respectively. Errors
Less than 10−5 would 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

Analysis

Def three points of the same method, to see D:

The vector BC counterclockwise rotation (angle ABC)/3, the vector cb clockwise rotation (angle ACB)/3, respectively, the linear BD and the linear CD direction vector, plus point b,c, you can write straight BD and straight CD (parametric equation), and then the intersection of two straight lines can be obtained.

Attention:

The next two parameters in the 1.get function cannot be reversed, because one side is counterclockwise, and the other side is clockwise.

1#include <bits/stdc++.h>2 using namespacestd;3 4 Const Doubleeps=1e-8;5 structpoint{6     Doublex, y;7Point (Doublex=0,Doubley=0): X (x), Y (y) {}8 };9 typedef point Vector;Ten  OneVectoroperator+ (point A,point b) {returnVector (a.x+b.x,a.y+b.y); } AVectoroperator-(point A,point b) {returnVector (a.x-b.x,a.y-b.y); } -Vectoroperator* (Point A,DoubleP) {returnVector (a.x*p,a.y*p); } - DoubleDot (Vector A,vector b) {returnA.X*B.X+A.Y*B.Y; }//dot Product the DoubleCross (Vector A,vector b) {returna.x*b.y-a.y*b.x; }//Cross Product - DoubleLength (Vector a) {returnsqrt (dot (a,a)); }//the modulus of a vector - DoubleAngle (Vector A,vector b) {returnACOs (Dot (a)/length (a)/length (b)); }//two vector angles -Vector Rotate (vector a,Doublerad) {returnVector (A.x*cos (RAD)-a.y*sin (RAD), A.x*sin (RAD) +a.y*cos (RAD)); }//rotates the vector a counterclockwise by rad (Radian System) +Point Get_line_intersection (Point p,vector v,point q,vector W) {//finding the intersection of two straight lines (parametric equation) -Vector u=p-Q; +     DoubleT=cross (w,u)/Cross (v,w); A     returnp+v*T; at } -PointGet(Point a,point b,point C) {//A function that calculates the DEF three points respectively -Vector v1=c-B; -     DoubleA1=angle (A-b,v1); -V1=rotate (v1,a1/3); -Vector v2=b-C; in     DoubleA2=angle (A-c,v2); -V2=rotate (v2,-a2/3); to     returnget_line_intersection (B,V1,C,V2); + } - intMain () { the     intN; * Point a,b,c,d,e,f; $scanf"%d",&n);Panax Notoginseng      while(n--){ -scanf"%LF%LF%LF%LF%LF%LF",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y); theD=Get(A,B,C);//here b,c can not write counter, because one is counterclockwise, the other clockwise turn +E=Get(b,c,a); Af=Get(c,a,b); theprintf"%.6lf%.6lf%.6lf%.6lf%.6lf%.6lf\n", D.X,D.Y,E.X,E.Y,F.X,F.Y); +     } -     return 0; $}
View Code

Uva_11178_morley ' s_theorem_ (vector rotation + straight line intersection)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.