sicily 1059. Exocenter of a Trian

原创 2015年11月19日 13:15:39

1059. Exocenter of a Trian

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

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.

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

Sample Output

9.0000 3.7500
-48.0400 23.3600

题目分析

找三角形的质心
具体证明可以见此
为了避免讨论斜率是否存在的问题,转化成向量运算
注意fabs(ans) < 0.0001输出0.0000


#include <stdio.h>
#include <math.h>

struct Point {
   double x, y;
};
struct Line {
   Point start, end;
};

int main() {
   int test;
   scanf("%d", &test);
   while (test--) {
        Point a, b, c;
        scanf("%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y);
        Line u, v;
        u.start = c;
        u.end.x = u.start.x - a.y + b.y;
        u.end.y = u.start.y + a.x - b.x;
        v.start = b;
        v.end.x = v.start.x - a.y + c.y;
        v.end.y = v.start.y + a.x - c.x;       

        Point inter = u.start;
        double t = ((u.start.x - v.start.x) * (v.start.y - v.end.y) - (u.start.y - v.start.y) * (v.start.x - v.end.x)) 
                         / ((u.start.x - u.end.x) * (v.start.y - v.end.y) - (u.start.y - u.end.y) * (v.start.x - v.end.x));
        inter.x += (u.end.x - u.start.x) * t;
        inter.y += (u.end.y - u.start.y) * t;

        inter.x = fabs(inter.x) < 0.0001 ? 0.0 : inter.x;
        inter.y = fabs(inter.y) < 0.0001 ? 0.0 : inter.y;
        printf("%.4lf %.4lf\n", inter.x, inter.y);
   }
   return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

Sicily 1059. Exocenter of a Trian

题目大意:几何法计算三角形ABC的垂心 解题思路:根据题意解题即可,但是计算过程需要三个主要的函数。 1.向量旋转ratate():把向量分解成平行于x坐标轴和y坐标轴的向量,再分别旋转,最合把旋...

1059. Exocenter of a Trian

#include const double eps = 1e-8; typedef struct{ double x; double y; } CPoint; int dcmp(doub...

Sicily 1059. Exocenter of a Triangle

求垂心。 已知三个顶点的坐标,求垂心的坐标的思路

PKU 1673 EXOCENTER OF A TRIANGLE 三角形的垂心

EXOCENTER OF A TRIANGLEDescriptionGiven a triangle ABC, the Extriangles of ABC are constructed as f...

poj 1673 EXOCENTER OF A TRIANGLE

垂心。 /* * Author: stormdpzh * Created Time: 2012/7/19 15:12:17 * File Name: poj_1673.cpp */ #inc...

POJ1673-EXOCENTER OF A TRIANGLE

EXOCENTER OF A TRIANGLE Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:...

poj 1673(EXOCENTER OF A TRIANGLE) (垂心证明)

poj 1673(EXOCENTER OF A TRIANGLE)  (垂心证明) http://poj.org/problem?id=1673       题目简单描述: ...

POJ 1673 EXOCENTER OF A TRIANGLE

这道题就是求点的时候麻烦了点,思路还是很简单的 刚开始把向量反向写成了swap(x,y),其实应该是x=-x,y=-y #include #include #include using namespa...
  • lj94093
  • lj94093
  • 2015年02月27日 23:18
  • 389

poj 1673 EXOCENTER OF A TRIANGLE(求三角形垂心)

EXOCENTER OF A TRIANGLE Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:...
  • fp_hzq
  • fp_hzq
  • 2012年09月15日 16:42
  • 753

zoj 1821 || poj 1673 Exocenter of a Triangle

求垂心。分类上直接说了,无语。如果我看的话应该第一反应是模拟一遍吧。。 pojdiscuss上有证明。 ZOJ死活不过,后来看大黄的题解,可能会输出-0.0000,这个。。。无语shi。。 #i...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:sicily 1059. Exocenter of a Trian
举报原因:
原因补充:

(最多只允许输入30个字)