2024年3月15日发(作者:祝福妈妈生日快乐的祝福语)
足球机器人程序代码
//应用程序模板
#include
//判断自身与球的方位是否危险
bool AzimuthDanger()
{
double ballX = getBallX();
double myX = getX();
double radius = getBallRadius()+getRadius();
if(getAttack()>0 && myX+radius*2>ballX) return true;
if(getAttack()<0 && myX-radius*2 if( (getAttack()>0 && getBallX() (getAttack()<0 && getBallX()>getCourtWidth()/2) ) { if((getBallY()>getCourtHeight()/2)&&(getY()>getBallY() ))return true; if((getBallY() ))return true; } return fal; } //判断球的运动方向 返回true 危险 bool JudgeDanger() { double ballX = getBallX(); double ballY = getBallY(); double goalMin = getCourtHeight()/2-getGoalWidth()/2; double goalMax = getCourtHeight()/2+getGoalWidth()/2; double b = ballY - tan(getBallHeading())*ballX; if(getAttack()>0 && getBallHeading()>PI/2 && getBallHeading() { if(goalMin<50*tan(getBallHeading()) + b && goalMax>50*tan(getBallHeading()) + b)return true; el return fal; } el if(getAttack()<=0 && (getBallHeading()>=0 && getBallHeading() || getBallHeading()<2*PI && getBallHeading()>3*PI/2)) { if(goalMin && tan(getBallHeading())*(getCourtWidth() - 50) + b return true; el return fal; } el return fal; } //预测足球在times个单位时间后的位置 void Next(int times, double* nextX, double* nextY) { double velocity = getBallVelocity(); double heading = getBallHeading(); double acc = -getBallNegativeAcceleration(); *nextX = getBallX(); *nextY = getBallY(); for (int i = 0; i < times; i++) { if(velocity==0) break; nextPoint(*nextX, *nextY, heading, velocity, nextX, nextY); } } // 摩擦减速 if (velocity > 0) velocity = fmax(0, velocity+acc); el if (velocity < 0) velocity = fmin(0, velocity -acc); // 撞墙检测 if ((*nextX) < 0 || (*nextX) > getCourtWidth()) { heading = PI - heading; modifyInCourt(nextX, nextY, getBallRadius()); } if ((*nextY) < 0 || (*nextY) > getCourtHeight()) { heading = -heading; modifyInCourt(nextX, nextY, getBallRadius()); } // 跌代计算球的运行线路,计算未来的击球点 void OptimumPosition(double* hitedX ,double* hitedY ) { *hitedX = getBallX();
本文发布于:2024-03-15 07:41:39,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/zhishi/a/1710459700286400.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:机器人足球代码1汇编.doc
本文 PDF 下载地址:机器人足球代码1汇编.pdf
留言与评论(共有 0 条评论) |