POJ 1673 EXOCENTER OF A TRIANGLE(解三角形重心)

题目链接:http://poj.org/problem?id=1673

AC代码:

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const double eps = 1e-8;
const double pi = acos(-1.0);
int sgn(double x)
{
    if(fabs(x) < eps) return 0;
    else return x < 0 ? -1 : 1;
}
struct Point{
    double x, y;
    Point(){}
    Point(double _x, double _y){
        x = _x, y = _y;
    }
    bool operator == (Point b) const{
        return sgn(x - b.x) == 0 && sgn(y - b.y) == 0;
    }
    bool operator < (Point b)const{
        return sgn(x - b.x) == 0 ? sgn(y - b.y < 0) : x < b.x;
    }
    Point operator - (const Point &b)const{
        return Point(x - b.x, y - b.y);
    }
    //²æ»ý
    double operator ^(const Point &b){
        return x * b.y - y * b.x;
    }
    //µã»ý
    double operator *(const Point &b){
        return x * b.x + y * b.y;
    }
    double len(){
        return hypot(x, y);
    }
    double len2(){
    return x * x + y * y;
    }
    double distant(Point p){
        return hypot(x - p.x, y - p.y);
    }
    Point operator + (const Point &b)const{
        return Point (x + b.x, y + b.y);
    }
    Point operator * (const double &k)const{
        return Point(x * k, y * k);
    }
    Point operator / (const double &k)const{
        return Point(x / k, y / k);
    }
    Point rotate(Point p, double angle){
        Point v = (*this) - p;
        double c = cos(angle), s = sin(angle);
        return Point(p.x + v.x * c - v.y * s, p.y + v.x * s + v.y * c);
    }
};
Point GetLineIntersection(Point P, Point v, Point Q, Point w){
    Point u = P - Q;
    double t =(w^u)/(v^w);
    return P + v*t;
}
int main()
{
    Point A, B, C;
    int n;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%lf %lf %lf %lf %lf %lf",&A.x, &A.y, &B.x, &B.y, &C.x, &C.y);
        Point v = B,u = C;
        v = v.rotate(A, pi / 2.0), u = u.rotate(B, pi / 2.0);
        Point c = GetLineIntersection(C, v - A, A, u - B);
        printf("%.4f %.4f\n",c.x + eps, c.y + eps);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/Carered/p/11406710.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值