EXOCENTER OF A TRIANGLE
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 13 Accepted Submission(s) : 7
Problem Description
Given a triangle ABC, the Extriangles of ABC are constructed as follows:
On each side of ABC, construct a square (ABDE, BCHJ and ACFG in the figure below). Connect adjacent square corners to form the three Extriangles (AGD, BEJ and CFH in the figure). The Exomedians of ABC are the medians of the Extriangles, which pass through vertices of the original triangle,extended into the original triangle (LAO, MBO and NCO in the figure. As the figure indicates, the three Exomedians intersect at a common point called the Exocenter (point O in the figure). This problem is to write a program to compute the Exocenters of triangles.
![](https://i-blog.csdnimg.cn/blog_migrate/6cf0fed6830625eaf3d228e4d9a3e902.jpeg)
Input
The first line of the input consists of a positive integer n, which is the number of datasets that follow. Each dataset consists of 3 lines; each line contains two floating point values which represent the (two -dimensional) coordinate of one vertex of a triangle. So, there are total of (n*3) + 1 lines of input. Note: All input triangles wi ll be strongly non-degenerate in that no vertex will be within one unit of the line through the other two vertices.
Output
For each dataset you must print out the coordinates of the Exocenter of the input triangle correct to four decimal places.
Sample Input
2
0.0 0.0
9.0 12.0
14.0 0.0
3.0 4.0
13.0 19.0
2.0 -10.0
0.0 0.0
9.0 12.0
14.0 0.0
3.0 4.0
13.0 19.0
2.0 -10.0
Sample Output
9.0000 3.7500
-48.0400 23.3600
-48.0400 23.3600
Source
PKU
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 typedef struct point{double x,y;}point; 5 typedef struct line{point a,b;}line; 6 7 double distance(point p1,point p2){ 8 return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); 9 } 10 point intersection(line u,line v){ 11 point ret=u.a; 12 double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x)) 13 /((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x)); 14 ret.x+=(u.b.x-u.a.x)*t; 15 ret.y+=(u.b.y-u.a.y)*t; 16 return ret; 17 } 18 //垂心 19 point perpencenter(point a,point b,point c){ 20 line u,v; 21 u.a=c; 22 u.b.x=u.a.x-a.y+b.y; 23 u.b.y=u.a.y+a.x-b.x; 24 v.a=b; 25 v.b.x=v.a.x-a.y+c.y; 26 v.b.y=v.a.y+a.x-c.x; 27 return intersection(u,v); 28 } 29 int main() 30 { 31 int T; 32 point L1,L2,L3,S; 33 scanf("%d",&T); 34 while(T--) 35 { 36 scanf("%lf%lf%lf%lf%lf%lf",&L1.x,&L1.y,&L2.x,&L2.y,&L3.x,&L3.y); 37 S=perpencenter(L1,L2,L3); 38 printf("%.4f %.4f\n",S.x,S.y); 39 } 40 return 0; 41 }