B - Collision(简单几何,圆缩点)

B - Collision

ZOJ - 3728

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

题意:

v v v在平面上0,0点,有一个半径为R的圆形区域,并且在0,0点固定着一个半径为RM(<R)的圆形障碍物,现在圆形区域外x,y,有一个半径为r的,并且速度为vx,vy的硬币,如果硬币碰到了障碍物,将会保持原有的速度向反射的方向继续前进,现在给出R,RM,r,x,y,vx,vy,问硬币的任意部分在圆形区域中滑行多少时间?

思路:

​ 对于圆的碰撞问题,我们可以使用缩点这个技巧。把半径为 r r r 的圆看成一个点,让另外两个圆的半径增加 r r r,那么我们只需求该点经过两个圆环之间的时间即可。

​ 可以根据t,写出点的移动坐标方程 ( x + t ∗ v x , y + t ∗ v y ) (x+t*vx,y+t*vy) (x+tvx,y+tvy),分别带入两个圆的方程即可。如果解得的t是负值,则证明该点不会碰撞圆。

#include<bits/stdc++.h>
using namespace std;
const double EPS=1e-10;
double R,Rm,r,x,y,vx,vy;
int ff(double a,double b,double c,double &x1,double &x2)
{
    double m=b*b-4*a*c;
    if(m<0.0)
       return 0;
    m=sqrt(m);
    double xa=(-b+m)/(a*2.0),xb=(-b-m)/(a*2.0);
    x1=min(xa,xb);
    x2=max(xa,xb);
    if(m*m<EPS)
        return 1;
    else
        return 2;
}
int main()
{
    while(cin>>Rm>>R>>r>>x>>y>>vx>>vy)
    {
        Rm+=r;
        R+=r;

        double t1=1,t2=1,t3,t4;
        int num1,num2;
        num1=ff(vx*vx+vy*vy,2*vx*x+2*vy*y,-R*R+x*x+y*y,t1,t2);
        num2=ff(vx*vx+vy*vy,2*vx*x+2*vy*y,-Rm*Rm+x*x+y*y,t3,t4);
        if(t1<0.0||t2<0.0)
        {
            printf("0.000000000\n");
        }
        else if(num2!=2&&num1!=2){
            puts("0.00000000");
        }
        else if(num1==2&&num2!=2){
            double t=t2-t1;
            printf("%.10f\n",t);
        }
        else{
            double t=t2-t1-(t4-t3);
            printf("%.10f\n",t);
        }
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值