#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
const double pai=3.14159265358979323;
int n;
struct BALL
{
double x,y;
double angle; //角度
double v;
int times;
}ball_pos[100000];
struct PLAY
{
double x,y;
double v;
};
struct PLAY player;
struct BALL ball;
int dis(double player_x,double player_y,double ball_x,double ball_y)
{
double distance=0;
double x2=(player_x-ball_x)*(player_x-ball_x);
double y2=(player_y-ball_y)*(player_y-ball_y);
distance=sqrt(x2+y2);
return distance;
}
void line(double & k,double & b,double & ball_x,double & ball_y,double & angle,double ball_v)
{
double temp=0,vx=0,vy=0;
n=1;
k=tan(angle);
b=ball_y-(k*ball_x);
temp=ball_v;
vx=ball_v*(cos((angle*pai)/180));
vy=ball_v*(sin((angle*pai)/180));
ball_pos[1].x=ball_x+vx;
ball_pos[1].y=ball_y+vy;
ball_pos[1].times=1;
while(temp!=0)
{
n++;
vx=vx*0.94,vy=vy*0.94;
temp=temp*0.94;
ball_pos[n].x=ball_pos[n-1].x+vx;
ball_pos[n].y=ball_pos[n-1].y+vy;
ball_pos[n].times=n;
if(temp<0.0000000000001)
temp=0;
}
}
int main()
{
double distance=0,player_angle=0,temp=0,k=0,b=0,tempx=0,tempy=0;
cin>>player.x>>player.y;
player.v=0.6;
cin>>ball.x>>ball.y>>ball.v>>ball.angle;
printf("球员的信息:位置(%.2lf,%.2lf),速度:%.2lf\n",player.x,player.y,player.v);
printf("球的信息:位置(%.2lf,%.2lf),速度:%.2lf,角度:angle:%.2f\n",ball.x,ball.y,ball.v,ball.angle);
line(k,b,ball.x,ball.y,ball.angle,ball.v);
for(int i=2;i<=n;i++)
{
player.v=0.6;
double xx=player.x,yy=player.y;
temp=(ball_pos[i].y-player.y)/(ball_pos[i].x-player.x);
player_angle=atan(temp)*180/pai;
for(int j=2;j<=i;j++)
{
if(j==3)
player.v=0.75;
if(j==4)
player.v=0.9;
if(j>=5)
player.v=1.0;
tempx=player.v*(cos((player_angle*pai)/180));
tempy=player.v*(sin((player_angle*pai)/180));
xx+=tempx;
yy+=tempy;
}
distance=dis(xx,yy,ball_pos[i].x,ball_pos[i].y);
if(distance<=0.5)
{
printf("times=%d\n",ball_pos[i].times);
printf("player_angle= %.2lf度\n",player_angle);
break;
}
}
return 0;
}
robocup(测试)
猜你喜欢
转载自blog.csdn.net/m0_43400575/article/details/84638816
今日推荐
周排行