HDU5572 An Easy Physics Problem 【计算几何】

An Easy Physics Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2113    Accepted Submission(s): 410


Problem Description
On an infinite smooth table, there's a big round fixed cylinder and a little ball whose volume can be ignored.

Currently the ball stands still at point A, then we'll give it an initial speed and a direction. If the ball hits the cylinder, it will bounce back with no energy losses.

We're just curious about whether the ball will pass point B after some time.


Input
First line contains an integer T, which indicates the number of test cases.

Every test case contains three lines.

The first line contains three integers Ox, Oy and r, indicating the center of cylinder is (Ox,Oy) and its radius is r.

The second line contains four integers Ax, Ay, Vx and Vy, indicating the coordinate of A is (Ax,Ay) and the initial direction vector is (Vx,Vy).

The last line contains two integers Bx and By, indicating the coordinate of point B is (Bx,By).

⋅ 1 ≤ T ≤ 100.

⋅ |Ox|,|Oy|≤ 1000.1 ≤ r ≤ 100.

⋅ |Ax|,|Ay|,|Bx|,|By|≤ 1000. 

⋅ |Vx|,|Vy|≤ 1000.

⋅ Vx≠0 or Vy≠0.

⋅ both A and B are outside of the cylinder and they are not at same position.


Output
For every test case, you should output "Case #x: y", where x indicates the case number and counts from 1. y is "Yes" if the ball will pass point B after some time, otherwise y is "No".


Sample Input
2
0 0 1
2 2 0 1
-1 -1
0 0 1
-1 2 1 -1
1 2


Sample Output
Case #1: No
Case #2: Yes


Source
2015ACM/ICPC亚洲区上海站-重现赛(感谢华东理工)

情况有好几种
如果将整个图旋转一下 ,让 (Vx,Vy) 旋转到 X 轴正方向 ,处理起来就简单很多
当A能射中B:

①A直接射到B上:
这种情况ABxABA,B线y=Ay
Ay==ByAx<Bx(Ox<Ax||Ox>Bx||Ay>Oy+r||Ay<Oyr)

②A射到圆上,且沿着反方向反弹,射中B
Ay==By==OyAx>BxOx>Ax

other:
ACACC线α,A线α
B线AC线BC线
dis=BC,BD=(Cx+dis,Cy)线线BD线


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<math.h>
#include<list>
#include<cstring>
#include<fstream>
#include<queue>
#include<sstream>
//#include<memory.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define INF 1000000007
#define pll pair<ll,ll>
#define pid pair<int,double>

const int inf=1e9+7;
const double EPS=1e-7;

struct P{
    double x,y;
    double operator*(const P&p){//点乘
        double ans=x*p.x+y*p.y;
        return ans;
    }
    double crossProd(const P&p){//叉乘
        return x*p.y-y*p.x;
    }
    double mod(){
        return sqrt(x*x+y*y);
    }

    void roate(double angle){//逆时针旋转angle度 angle=x*PI
        double tx=x*cos(angle)-y*sin(angle);
        double ty=y*cos(angle)+x*sin(angle);
        x=tx;
        y=ty;
    }
    double distance(const P&p){
        double tmp=(p.x-x)*(p.x-x)+(p.y-y)*(p.y-y);
        return sqrt(tmp);
    }
}a,b,o,v;

istream&operator>>(istream&in,P&p){
    in>>p.x>>p.y;
    return in;
}

int r;

bool slove(){
    P vec={1,0};
    double cosVal=vec*v/(vec.mod()*v.mod());
    double angle=acos(cosVal);
    if(v.crossProd(vec)<EPS){
        angle=-angle;
    }
    a.roate(angle);
    b.roate(angle);
    o.roate(angle);
    if(fabs(a.y-b.y)<EPS){
        if(b.x<a.x){
            if(o.x>a.x&&fabs(o.y-a.y)<EPS){
                return true;
            }
            return false;
        }
        if(a.x<=o.x&&o.x<=b.x){
            if(o.y-r<=a.y+EPS&&a.y<=o.y+r+EPS){
                return false;
            }
        }
        return true;
    }

    double ta=1;
    double tb=-2.0*o.x;
    double tc=o.x*o.x+a.y*a.y-2*o.y*a.y+o.y*o.y-r*r;
    double dt=tb*tb-4.0*ta*tc;
    if(dt<0){
        return false;
    }
    P c;
    c.x=(-tb-sqrt(dt))/(2.0*ta);
    c.y=a.y;
    double k_co=(c.y-o.y)/(c.x-o.x);
    double k=-1.0/k_co;

    double dis=b.distance(c);
    P d;
    d.x=c.x+dis;
    d.y=c.y;

    P mid={(b.x+d.x)/2.0,(b.y+d.y)/2.0};
    return fabs(mid.y-c.y-k*(mid.x-c.x))<EPS;
}

int main()
{
    //freopen("/home/lu/Documents/r.txt","r",stdin);
    //freopen("/home/lu/Documents/w.txt","w",stdout);
    int T;
    scanf("%d",&T);
    for(int t=1;t<=T;++t){
        cin>>o>>r>>a>>v>>b;
        printf("Case #%d: %s\n",t,slove()?"Yes":"No");
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值