三角形外心与垂心

转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove

POJ 1329 Circle Through Three Points

http://poj.org/problem?id=1329

题目:就是求外心,但是要输出外接圆方程,输出真DT

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<ctime>
#include<cassert>
#define LL long long
#define eps 1e-8
#define inf 999999.0
#define zero(a) abs(a)<eps
#define N 20
#define MOD 100000007
#define pi acos(-1.0)
using namespace std;
struct Point{
    double x,y;
    Point(){}
    Point(double tx,double ty){x=tx;y=ty;}
}a,b,c;
Point Circumcenter(Point a,Point b,Point c){
    double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/2;
    double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/2;
    double d = a1 * b2 - a2 * b1;
    return Point(a.x + (c1*b2 - c2*b1)/d,a.y + (a1*c2 - a2*c1)/d);
}
double dist(Point p1,Point p2){
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
int main(){
    while(scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y)!=EOF){
        Point central=Circumcenter(a,b,c);
        double r=dist(central,a);
        char ch1,ch2,ch3;
        if(central.x<eps) ch1='+';else ch1='-';
        if(central.y<eps) ch2='+';else ch2='-';
        double d=central.x*central.x+central.y*central.y-r*r;
        if(d<eps ) ch3='-';else ch3='+';
        printf("(x %c %.3f)^2 + (y %c %.3f)^2 = %.3f^2\n",ch1,fabs(central.x),ch2,fabs(central.y),r);
        printf("x^2 + y^2 %c %.3fx %c %.3fy %c %.3f = 0\n\n",ch1,2*fabs(central.x),ch2,2*fabs(central.y),ch3,fabs(d));
    }
    return 0;
}

POJ 1673 EXOCENTER OF A TRIANGLE

http://poj.org/problem?id=1673

题目:很纠结的一个图,求出那个点,转换成三角形的垂心。

将三角形BEJ沿B点,逆时针旋转90度,这样子BE与BA重合,而且BJ与BC共线

而M是AJ的中点,而且BC==BJ,那么BM是三角形AJC的中位线,即BM平行于AC

而BM是经过旋转90度的,则原先BM垂直AC,同理可得其它边。

则点O为三角形ABC的垂心

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<ctime>
#define LL long long
#define eps 1e-8
#define inf 999999.0
#define zero(a) abs(a)<eps
#define N 20
#define MOD 100000007
#define pi acos(-1.0)
using namespace std;
struct Point{
    double x,y;
    Point(){}
    Point(double tx,double ty){x=tx;y=ty;}
}a,b,c;
Point Orthocenter(Point p0,Point p1,Point p2){
    double a1,b1,a2,b2,c1,c2;
    a1 = p2.x-p1.x; b1=p2.y-p1.y;c1 = 0;
    a2 = p2.x-p0.x; b2=p2.y-p0.y;c2 = (p1.x-p0.x)*a2+(p1.y-p0.y)*b2;
    double d = a1 * b2 - a2 * b1;
    return Point(p0.x+(c1*b2-c2*b1)/d,p0.y+(a1*c2-a2*c1)/d);
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
        Point central=Orthocenter(a,b,c);
        printf("%.4f %.4f\n",central.x,central.y);
    }
    return 0;
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值