poj 1254 Hansel and Grethel 直线求交

题意:

通过点和方向给出两条直线,求他们的交点。

分析:

裸的直线求交,向量做法可避免特殊情况的的讨论。

代码:

//poj 1254
//sep9
#include <iostream>
#include <cmath>
using namespace std;
const double pi=acos(-1.0);

struct P
{
	double x,y;
}a,b,c,d;

double det(double x1,double y1,double x2,double y2)
{
	return x1*y2-x2*y1;	
}

int main()
{
	int cases;
	scanf("%d",&cases);
	while(cases--){
		double alpha;
		scanf("%lf%lf%lf",&a.x,&a.y,&alpha);
		alpha=pi*(450-alpha)/180;
		b.x=a.x+cos(alpha);
		b.y=a.y+sin(alpha);
		scanf("%lf%lf%lf",&c.x,&c.y,&alpha);
		alpha=pi*(450-alpha)/180;
		d.x=c.x+cos(alpha);
		d.y=c.y+sin(alpha);
		double s1=det(c.x-a.x,c.y-a.y,b.x-a.x,b.y-a.y);
		double s2=det(d.x-a.x,d.y-a.y,b.x-a.x,b.y-a.y);
		double xx=(s1*d.x-s2*c.x)/(s1-s2);
		double yy=(s1*d.y-s2*c.y)/(s1-s2);
		printf("%.4lf %.4lf\n",xx+1e-9,yy+1e-9);
	}
	return 0;	
}

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值