欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Uva 10250 The Other Two Trees

程序员文章站 2022-06-02 22:13:12
...
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1191
题意:有一个平行四边形然后分别以四条边为边长向外作正方形,四棵树在四个正方形中心的位置。其实四棵树构成正方形,相当于给出正方形的对角线的两个点,求另外两个。
证明正方形如下:来源:http://m.blog.csdn.net/blog/u014491224/29647971
Uva 10250 The Other Two Trees
下面证△FOE≌△HGO
 
设CD=2a,BC=2b
 
∴EF=OH=a,
    OF=HG=b
 
易知∠DFO=∠OHB
 
∴∠EFO=∠OHG=∠DFO+90°
∴△FOE≌△HGO(边角边)
 
∴∠E=∠GOH
∠EOG=∠EOF+∠DFO+∠E=90°      (因为再加上∠DFE就等于内角和180°了)
 
综上,OE=OG且OE⊥OG
 
由于对称性,四棵树就构成了个正方形。
需要注意pi
 代码:
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
const double pi=acos(-1);
const double eps=1e-10;
double cmp(double x)
{
    if(fabs(x)<eps) return 0;
    else return x;
}
struct Point
{
    double x,y;
    Point(double x,double y):x(x),y(y){};
};
typedef Point Vector;
Vector Rotate(Vector a,double rad)
{
    return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
Vector reduce(Vector a,double time)
{
    return Vector(a.x*time,a.y*time);
}
int main()
{
    double x1,x2,y1,y2;
    while(cin>>x1>>y1>>x2>>y2)
    {
        Vector hypo(x2-x1,y2-y1);
        Vector v=reduce(hypo,sqrt(2)/2);
        Vector v1=Rotate(v,pi/4);
        Vector v2=Rotate(v,-pi/4);
        //cout<<v1.x<<" "<<v1.y<<" "<<v2.x<<" "<<v2.y<<endl;
        Vector ans1(cmp(v1.x+x1),cmp(v1.y+y1));
        Vector ans2(cmp(v2.x+x1),cmp(v2.y+y1));
        printf("%.10lf %.10lf %.10lf %.10lf\n",ans1.x,ans1.y,ans2.x,ans2.y);
        //cout<<ans1.x<<" "<<ans1.y<<" "<<ans2.x<<" "<<ans2.y<<endl;
    }
    return 0;
}