zoj 1560 Hansel and Grethel(求两条直线的交点)

题目地址

题目大意:给出2个点及其各自夹角,求2条直线的交点

解题思路:数学公式推导,用tan()求斜率时要将角度转换成弧度

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <list>

using namespace std;

const double PI = acos(-1.0);

struct Point
{
    double x,y;
    double angle;
}p1,p2;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf",&p1.x,&p1.y,&p1.angle);
        p1.angle = 90-p1.angle;
        scanf("%lf%lf%lf",&p2.x,&p2.y,&p2.angle);
        p2.angle = 90-p2.angle;
        double k1 = tan(p1.angle/180*PI);
        double k2 = tan(p2.angle/180*PI);
        double x = (k1*p1.x-k2*p2.x+p2.y-p1.y)/(k1-k2);
        double y = ((p2.x-p1.x)*k1*k2+p1.y*k2-p2.y*k1)/(k2-k1);
        printf("%.4lf %.4lf\n",x,y);
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值