ZOJ-3728 Collision 计算几何

There's a round medal fixed on an ideal smooth table, Fancy is trying to throw some coins and make them slip towards the medal to collide. There's also a round range which shares exact the same center as the round medal, and radius of the medal is strictly less than radius of the round range. Since that the round medal is fixed and the coin is a piece of solid metal, we can assume that energy of the coin will not lose, the coin will collide and then moving as reflect.

Now assume that the center of the round medal and the round range is origin ( Namely (0, 0) ) and the coin's initial position is strictly outside the round range. Given radius of the medal Rm, radius of coin r, radius of the round range R, initial position (x, y) and initial speed vector (vx, vy) of the coin, please calculate the total time that any part of the coin is inside the round range.

Please note that the coin might not even touch the medal or slip through the round range.

Input

There will be several test cases. Each test case contains 7 integers Rm, R, r, x, y, vx and vy in one line. Here 1 ≤ Rm < R ≤ 2000, 1 ≤ r ≤ 1000, R + r < |(x, y)| ≤ 20000, 1 ≤ |(vx, vy)| ≤ 100.

Output

For each test case, please calculate the total time that any part of the coin is inside the round range. Please output the time in one line, an absolute error not more than 1e-3 is acceptable.

Sample Input

5 20 1 0 100 0 -1
5 20 1 30 15 -1 0

Sample Output

30.000
29.394

题解:设 a 为圆盘运动向量 , 点A为初始位置, O为原点,若(a 点成 AO)小于 0 的话 肯定没有交点。如果大于0的话,原点到运动轨迹的最短距离就可以算出来了,在分运动轨迹  没有接触大圆 ,在两圆之间 和  碰撞小圆 即可

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define eps 1e-8
double Rm,R,r,x,y,vx,vy;
double get_D()
{
	if(fabs(vx)<eps) return x;
	if(fabs(vy)<eps) return y;
	double k=vy/vx;
	double b=y-k*x;
	return b/sqrt(k*k+1);	
}
int main()
{
	while(~scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy))
	{
		Rm+=r;
		R+=r;
		double d=fabs(get_D());
	//	cout<<x*vx+y*vy<<endl;
		if((x*vx+y*vy)>eps||d-R>eps) printf("0.000\n");
		else if(d-Rm>eps)
		{
			double l=sqrt(R*R-d*d)*2;
			printf("%.3f\n",l/sqrt(vx*vx+vy*vy));
		}
		else
		{
			double l=sqrt(R*R-d*d)*2-sqrt(Rm*Rm-d*d)*2;
			printf("%.3f\n",l/sqrt(vx*vx+vy*vy));
		}
	}
	return 0;
} 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值