tzc1200 求两直线的夹角

题目链接:  tzc1200

方法:计算几何 

代码:

#include <iostream>
#include <cmath>
using namespace std;

struct point {double x,y;};
struct line { point s,e; };

const double pi=acos(-1);
//求两条直线的角度 
//返回角度为弧度制,并且以逆时针方向为正方向
double angle(line a,line b)
{
	double dtheta,theta1,theta2; 
	a.s.x-=a.e.x;a.s.y-=a.e.y;
	b.s.x-=b.e.x;b.s.y-=b.e.y;
	theta1 = atan2(a.s.y,a.s.x);
	theta2 = atan2(b.s.y,b.s.x);
	dtheta = theta2 - theta1;
	while (dtheta > pi)dtheta -= pi*2;
	while (dtheta < -pi)dtheta += pi*2; 
	return(dtheta);
}

int main()
{
	line a,b;
	int t;
	cin>>t;
	while(t--)
	{
		cin>>a.s.x>>a.s.y>>a.e.x>>a.e.y;
		cin>>b.s.x>>b.s.y>>b.e.x>>b.e.y;
		double ans=angle(a,b)/pi*180;
		if(ans<0)ans+=180;
		if(ans>180)ans-=180;
		if(ans>90)ans=180-ans;
		printf("%.1lf\n",ans);
	}
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值