Collision Ball Game-计算几何基础题

Collision ball game is one of my favorite game when I was young. I was so fond of this game that I nearly decided to be a physical scientist (But I am not now). Firstly I wanted to construct a problem to describe the whole process of this game. But it is too difficult for me and I hate being bsed by others for wrong data.

So I decide to make it easier, but maybe I will construct one next time.

Assume the game is in a triangle with the lower-right angle k (in degree) and height h. (see the picture)

The ball's initial place is in (0, a) and it eventually arrives at (b, 0) with collising the bevel edge only once. The two points (0, a) and (b, 0) will always be on the edge of the triangle.

You are to calculate the distance the ball pass. The process of collision obey the physical law. The angle of incidence equals to the angle of reflection.

Input

The input contains multiple test cases. Each test cases contain four number (all double). The first line is the angle of the triangle k (in degree, 0 < k < 90). The second line is the height h (h > 0). The third line is a. The fourth line is b (a, b >= 0).

Process to the end-of-file.

Output

For each test case print a single line that contains the distance the ball pass (rounded to 2 decimal places).

Sample Input

45
2
1
1

30
2
1
2.3094

Sample Output

2.00
2.89
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
#define pi acos(-1)
int main()
{
	double a,b,k,h;
	while(~scanf("%lf %lf %lf %lf",&k,&h,&a,&b))
	{
		//double s = 2*cos(k)*(h-a);
		double y = 2*cos(k*pi/180)*(h-a)*cos(k*pi/180)+a;
		double x = 2*cos(k*pi/180)*(h-a)*sin(k*pi/180);
		double u =sqrt((b-x)*(b-x)+y*y);
		printf("%.2lf\n",u);		
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43568078/article/details/88725364