这是一个虚拟机器人的代码
1//计算球在 times 个单位时间后的位置
2private Point2D next(int times)
3{
4 double velocity = getBallVelocity(); // 球当前的速度
5 Point2D location = getBallLocation(); // 球当前的坐标
6 double heading = getBallHeading(); // 球当前的方向
7 double acc = -getBallNegativeAcceleration(); // 球的加速度
8 for (int i = 0; i < times; i++)
9 {
10 if(velocity==0) break;
11 location = MathUtils.nextPoint(location, heading, velocity * 1);
12 // 摩擦减速
13 if (velocity > 0)
14 {
15 velocity += acc * 1;
16 velocity = Math.max(0, velocity);
17 }
18 else if (velocity < 0)
19 {
20 velocity -= acc * 1;
21 velocity = Math.min(0, velocity);
22 }
23 // 撞墙检测
24 if (location.getX() < 0 || location.getX() > getCourtWidth())
25 {
26 heading = Math.PI - heading;
27 modifyInCourt(location, getBallRadius());
28 }
29 if (location.getY() < 0 || location.getY() > getCourtHeight())
30 {
31 heading = -heading;
32 modifyInCourt(location, getBallRadius());
33 }
34 }
35 return location;
36}
速度在什么时候会小于0,第十八行又为什么这样处理?