计算几何专项:UVa 12301

由角a、b、c、d、e可以确定三角形ABC的形状,所以不妨以A为原点,AB为x轴建立直角坐标系。然后求出D、E的坐标,然后在三角形ADE中运用余弦定理就可以求出结果了。

#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps=1e-8;
int dcmp(double x)
{
    if(fabs(x)<eps) return 0;
    else return x<0?-1:1;
}
struct point
{
    double x,y;
    point(double x=0,double y=0):x(x),y(y){}
};
point operator-(point a,point b){return point(a.x-b.x,a.y-b.y);}
point operator+(point a,point b){return point(a.x+b.x,a.y+b.y);}
point operator*(point a,double p){return point(a.x*p,a.y*p);}
double cross(point a,point b){return a.x*b.y-a.y*b.x;}
double length(point a){return sqrt(a.x*a.x+a.y*a.y);}
point rot(point a,double rad){return point(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));}
double torad(double deg)
{
    return deg/180*acos(-1.0);
}
point getinter(point p,point v,point q,point w)
{
    point u=p-q;
    double t=cross(w,u)/cross(v,w);
    return p+v*t;
}
int main()
{
    freopen("in.txt","r",stdin);
    int a,b,c,d,e;
    while(cin>>a>>b>>c>>d>>e)
    {
        if(!a&&!b&&!c&&!d&&!e) break;
        if(a+b+c+d+e!=180||a<=0||b<=0||c<=0||d<=0||e<=0)
        {
            cout<<"Impossible"<<endl;
            continue;
        }
        point A=point(0,0),B=point(1,0);
        point ac=rot(B-A,torad(b+c));
        point bc=rot(B-A,torad(180-d-e));
        point ae=rot(B-A,torad(c));
        point bd=rot(B-A,torad(180-e));
        point D=getinter(B,bd,A,ac);
        point E=getinter(A,ae,B,bc);
        double l1=length(D-E),l2=length(A-E),l3=length(A-D);
        double ans=acos((l1*l1+l2*l2-l3*l3)/(2*l1*l2));
        printf("%.2f\n",ans/acos(-1.0)*180);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值