POJ1673-EXOCENTER OF A TRIANGLE

EXOCENTER OF A TRIANGLE
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3244 Accepted: 1277

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

Source

//AC代码
/*
题意:给出三角形三个定点,求出三角形的垂心
有公式:三角形的垂心等于过三个定点做高任意两条高的交点
*/
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<map>
#include<cstdlib>
#include<cmath>
#include<vector>
#define LL long long
#define IT __int64
#define zero(x) fabs(x)<eps
#define mm(a,b) memset(a,b,sizeof(a))
const int INF=0x7fffffff;
const double inf=1e8;
const double eps=1e-5;//小心精度,不然会出现-0
const double PI=acos(-1.0);
const int Max=20001;
using namespace std;
int sign(double x)
{
    return (x>eps)-(x<-eps);
}
typedef struct Node
{
    double x;
    double y;
    Node(const double &_x=0, const double &_y=0) : x(_x), y(_y) {}
    void input()
    {
        cin>>x>>y;
    }
    void output()
    {
        cout<<x<<" "<<y<<endl;
    }
}point;
point A,B,C;
point Center;
double k1,k2,k3,k4;
double b1,b2;
double xmult(point p0,point p1,point p2)
{
	return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double dmult(point p0,point p1,point p2)
{
	return(p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y);
}
double Distance(point p1,point p2)// 返回两点之间欧氏距离
{
	return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
double slope(point u,point v)
{
    if(sign(u.x-v.x)==0)
        return inf;
    else
        return (v.y-u.y)/(v.x-u.x);
}
int main()
{
    int n,m,i,j;
    double xx,yy;
    //freopen("D:\\in.txt","r",stdin);
    //freopen("D:\\out.txt","w",stdout);
    cin>>n;
    while(n--)
    {
        A.input();
        B.input();
        C.input();
        k1=slope(A,B);
        if(k1==inf)
            k3=0;
        else
            k3=-1/k1;
        if(k1==0)
            k3=inf;
        else
            k3=-1/k1;
        k2=slope(A,C);
        if(k2==inf)
            k4=0;
        else
            k4=-1/k2;
        if(k2==0)
            k4=inf;
        else
            k4=-1/k2;
        //cout<<k1<<" "<<k2<<endl;
        if(k3==inf&&k4!=inf)
        {
            Center.x=C.x;
            b1=B.y-k4*B.x;
            Center.y=k4*Center.x+b1;
            //Center.y=k4*(Center.x-B.x)+B.y;
            if(sign(Center.x)==0)
                Center.x=0;
            if(sign(Center.y)==0)
                Center.y=0;
            cout<<setprecision(4)<<setiosflags(ios::fixed)<<Center.x<<" "<<Center.y<<endl;
            continue;
        }
        if(k3!=inf&&k4==inf)
        {
            //cout<<"yes asdasd"<<endl;
            Center.x=B.x;
            b1=C.y-k3*C.x;
            Center.y=k3*Center.x+b1;
            //Center.y=k3*(Center.x-C.x)+C.y;
            if(sign(Center.x)==0)
                Center.x=0;
            if(sign(Center.y)==0)
                Center.y=0;
            cout<<setprecision(4)<<setiosflags(ios::fixed)<<Center.x<<" "<<Center.y<<endl;
            continue;
        }
        if(k3==0&&k4!=0)
        {
            Center.y=C.y;
            b1=B.y-k4*B.x;
            Center.x=(Center.y-b1)/k4;
            //Center.x=((Center.y-B.y)/k4)+B.x;
            if(sign(Center.x)==0)
                Center.x=0;
            if(sign(Center.y)==0)
                Center.y=0;
            cout<<setprecision(4)<<setiosflags(ios::fixed)<<Center.x<<" "<<Center.y<<endl;
            continue;
        }
        if(k3!=0&&k4==0)
        {
            Center.y=B.y;
            b1=C.y-k3*C.x;
            Center.x=(Center.y-b1)/k3;
            //Center.x=((Center.y-C.y)/k3)+C.x;
            if(sign(Center.x)==0)
                Center.x=0;
            if(sign(Center.y)==0)
                Center.y=0;
            cout<<setprecision(4)<<setiosflags(ios::fixed)<<Center.x<<" "<<Center.y<<endl;
            continue;
        }
        //cout<<"yes yes"<<endl;
        b1=B.y-k4*B.x;
        b2=C.y-k3*C.x;
        Center.x=(b1-b2)/(k3-k4);
        Center.y=k4*Center.x+b1;
        if(sign(Center.x)==0)
            Center.x=0;
        if(sign(Center.y)==0)
            Center.y=0;
        cout<<setprecision(4)<<setiosflags(ios::fixed)<<Center.x<<" "<<Center.y<<endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值