Collision

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/HYNU_zhizuzhe/article/details/50785796

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 (xy) and initial speed vector (vxvy) 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 RmRrxyvx and vy in one line. Here 1 ≤ Rm < R ≤ 2000, 1 ≤ r ≤ 1000, R + r < |(xy)| ≤ 20000, 1 ≤ |(vxvy)| ≤ 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
题意:光滑的桌面上放两个同心圆,一枚硬币以一定速度行驶,碰到小圆会反弹,求硬币部分在圆环中所花的总时间
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
	double Rm,R,r,x,y,vx,vy;
	while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)!=EOF)
	{
		double ans=0;
		Rm+=r; R+=r;
		double A=vx*vx+vy*vy;
		double B=2*x*vx+2*y*vy;
		double C1=x*x+y*y-R*R;
		double C2=x*x+y*y-Rm*Rm;
		double delta1=B*B-4*A*C1;
		double delta2=B*B-4*A*C2;
		if(delta1>0&&x*vx+y*vy<0)
		{
			if(delta2<=0) ans=fabs(sqrt(delta1)/A);
			else ans=fabs((sqrt(delta1)-sqrt(delta2))/A);
		}
		printf("%.3lf\n",ans);
	}
	return 0;
}

思路:转化成直线与圆的问题

注意:几何中整形数据可用浮点型输入



猜你喜欢

转载自blog.csdn.net/HYNU_zhizuzhe/article/details/50785796
今日推荐