[计算几何] zoj 3728 Collision

题目链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3728


Collision

Time Limit: 2 Seconds       Memory Limit: 65536 KB       Special Judge

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

Author:  FAN, Yuzhe
Contest:  The 2013 ACM-ICPC Asia Changsha Regional Contest
Submit     Status


题目意思:

给一个以原点(0,0)为圆

心,半径为Rm固定的圆饼。给一个以原点(0,0)为圆心,半径为R的大圆。有一个圆硬币,圆心为(x,y),半径为r,速度为vx,vy,硬币碰到圆饼后会以同样的能量从反射方向弹回。求硬币从进入大圆开始到离开大圆所花的时间。

解题思路:

简单计算几何。

先把圆饼和大圆的半径都加上硬币的半径,这样就可以把硬币看成是一个点。

假设硬币在A点,原点为B点,运动方向向量为AC,先用点集(AB,AC)判断硬币运动,如果向量AB,AC夹角大于等于90度,肯定不会经过大圆。

然后用叉积求出AB在AC方向上距离(高)d。

如果d>R 与大圆无交点

如果Rm<d<R说明是直线穿过大圆(在大圆里面的运行距离为sqrt(R*R-d*d))

如果d<Rm说明先射向圆饼然后反弹(在大圆里的运行距离为2*(sqrt(R*R-d*d)-sqrt(Rm*Rm-d*d))

代码:

//#include<CSpreadSheet.h>

#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#include<cmath>
#define eps 1e-9
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;

struct Point
{
    double x,y;
}p0,p1;
double Rm,R,r,x0,yy0,v;

double dianji(Point a,Point b)
{
    return a.x*b.x+a.y*b.y;
}
double chaji(Point a,Point b)
{
    return a.x*b.y-a.y*b.x;
}

int main()
{
   //freopen("in.txt","r",stdin);
   //freopen("out.txt","w",stdout);
   while(~scanf("%lf%lf%lf",&Rm,&R,&r))
   {
       Rm+=r,R+=r;
       scanf("%lf%lf",&x0,&yy0);
       scanf("%lf%lf",&p1.x,&p1.y);

       v=sqrt(p1.x*p1.x+p1.y*p1.y);

       p0.x=-x0,p0.y=-yy0;

       if(dianji(p0,p1)<eps)
       {
           printf("0.000\n");
           continue;
       }
       //system("pause");
       double d=fabs(chaji(p0,p1))/v;

       if(d-R>eps) //在外面
       {
           printf("0.000\n");
           continue;
       }
       if(d-Rm>eps)
       {
           printf("%.3lf\n",2*sqrt(R*R-d*d)/v);
           continue;
       }
       printf("%.3lf\n",(2*(sqrt(R*R-d*d)-sqrt(Rm*Rm-d*d)))/v);


   }
   return 0;
}



1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可私 6信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 、可私信6博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 、可私信6博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值