35.瞄准

本文探讨了如何从数学角度预测游戏内猴子扔香蕉的抛掷运动着陆点,通过解析水平和垂直位移公式,实现精确着陆预测。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

35.Take Aim

In our last post, we implemented projectile motion as the start of a game involving monkeys throwing bananas. We saw that projectile motion always follows the same parabolic pattern, which will look something like this:

在我们上一篇帖子里,作为一个涉及猴子扔香蕉游戏的开始,我们实现了抛掷运动。我们看到抛掷运动始终遵循抛物线模式,它看起来像这样:

Since the projectile follows a straightforward motion pattern, we can actually predict, mathematically, where the projectile will land. To do this, let’s work out where the projectile will be, a certain number of frames after it has launched, given an initial velocity of h horizontally, and v vertically, with gravity set to some value g.

由于抛掷遵照一个明确的运动模式,我们能够从数学上真实地预判抛掷的着陆点。为了做到这个,让我们算出抛掷将会落在哪儿,即发射之后的一个确定数量的帧数,给定初始的水平速率h和垂直速率v,并将重力加速度设为g。

 

Horizontal Position

水平位置

Recall that our horizontally velocity stayed constant — the banana moves the same horizontal distance each frame: h

回忆一下我们的水平速率保持不变——香蕉每一帧移动相同的水平距离h:

The distance that the projectile will have moved horizontally is therefore very simple:

抛掷的水平移动距离因而非常简单:

  • 在第0帧后: 0
  • 在第1帧后: 0
  • 在第2帧后: h + h = 2 \times h
  • 在第3帧后: \text h + h + h = 3 \times h

It’s not hard to see that in general, the horizontal position after a given number of frames, f , will be:

不难看出一般来说,在给定帧数下的水平位置f将会是:\text{horizDist} = f \times h

Vertical Position

垂直位置

The vertical position of the projectile is more complex. The distance it moves (initially v) reduces by g each frame:

抛掷的垂直位置更加复杂。它移动的距离(初始为v)每一帧减少g:

So, here’s the distance the projectile will have moved after the first few frames:

于是,这儿是经过开始的一些帧后抛掷将会移动的距离:

  • 在第0帧后: 0
  • 在第1帧后: v
  • 在第2帧后: v + (v-g) = 2 \times v - g
  • 在第3帧后: v + (v-g) + (v-g-g) = 3 \times v - g \times (1 + 2)
  • 在第4帧后: v + (v-g) + (v-g-g) + (v-g-g-g) = 4 \times v - g \times (1 + 2 + 3)

So the overall pattern is that the position will be:

于是总体模式是位置将会是:

\text{vertDist} = f \times v - g \times \displaystyle\sum_{i=1}^{f-1} i

The last part describes the sum of the numbers from 1 up to f-1 — that’s the (1+2+3) part from our pattern above. This need to sum up the numbers is the classic example for summation (wikipedia currently has it as its example for summation), and has the well-known result in mathematics that summing the numbers from 1 to n is equal to\frac{1}{2} \times n \times (n + 1), which we can use here (n being f-1):

 

公式的最后部分描述了从数字1到f-1的和——那是我们公式中的(1+2+3)部分。这种累加数字的需求便是典型的求和示例,同时在数学里关于数字1到n的和有众所周知的结果可供我们在这里使用(n换做f-1),它等于\frac{1}{2} \times n \times (n + 1)

\text{vertDist} = f \times v - g \times \frac{1}{2} \times (f - 1) \times f

Predicting the landing

预测着陆点

So we now have formulae for the horizontal and vertical distance of the projectile (in our case, a banana). The question we want to answer is: where will the banana land? For this, we use the fact that in our game, the banana only lands when the vertical distance reaches zero again (i.e. when the banana returns to ground level), so we can use that to work out how many frames it will be in flight for. Then, once we know the number of frames before it lands, we can then work out how far it will have gone horizontally. So we need to solve for when vertical distance is zero:

于是我们现在拥有了计算抛掷(在我们的例子里指香蕉)的水平和垂直距离的公式。我们希望回答的问题是:香蕉会落在哪儿?为了解答它,我们使用这样的事实,即在我们的游戏中,香蕉只会在其垂直距离重新到达零时着陆(换句话说当香蕉回到地面水平线上),于是我们可以计算出它在飞行时将会经历多少帧。于是,一旦我们知道它着陆前的帧数,我们便可以算出它将会在水平方向移动多远。因此我们需要解析垂直距离什么时候为零:

0 = \text{vertDist}
0 = f \times v - g \times \frac{1}{2} \times (f - 1) \times f
0 = f \times v - \frac{g}{2} \times (f^2 - f)
0 = f \times v - (\frac{g}{2} \times f^2 - \frac{g}{2} \times f)
0 = (v + \frac{g}{2}) \times f - \frac{g}{2} \times f^2

What we have here is a quadratic for f, which we can solve with the usual quadratic formula, where:

我们这儿得到的是一个关于f的二次方程式,可以使用通常的二次公式来求解它,已知:

a = -\frac{g}{2}
b = v + \frac{g}{2}
c = 0

This gives our next step, by filling in the quadratic formula:

下一步带入二次公式:

f = \displaystyle\frac{-(v + \frac{g}{2}) \pm \sqrt{(v + \frac{g}{2})^2 - 0}}{2 * -\frac{g}{2}}

f = \displaystyle\frac{-(v + \frac{g}{2}) \pm (v + \frac{g}{2})}{-g}

f = \textbf{either~~} 0 \textbf{~~or~~} \displaystyle\frac{-2 \times (v + \frac{g}{2})}{-g}

f = \textbf{either~~} 0 \textbf{~~or~~} \displaystyle\frac{2 \times v + g}{g}

f = \textbf{either~~} 0 \textbf{~~or~~} 2 \times \displaystyle\frac{v}{g} + 1

Now, the solution where =0 refers to when the banana is launched, so we can ignore that solution. We want the other solution, which says that the banana will land after2 \times \frac{v}{g} + 1 frames. In our example above, the banana was launched withv = 5, g = 1, so we can predict correctly that it lands after2 \times \frac{5}{1} + 1 = 11 frames.

现在看看,解为0对应的是香蕉发射时的情况,于是我们可以顾略该解。我们希望另一个解,它说明香蕉将会在2 \times \frac{v}{g} + 1帧之后落地。在我们上面的示例中,香蕉发射时v = 5, g = 1,于是我们可以准确地预测出它在2 \times \frac{5}{1} + 1 = 11帧后落地。

The advantage of doing all this maths is that our code ends up nice and simple for calculating the horizontal impact of the banana:

所作的这些数学计算的优点在于我们的代码最终在计算香蕉的水平分量时显得既良好又简单:

        double vx = Player.getVelX(radianAngle, forceFactor);
        double vy = Player.getVelY(radianAngle, forceFactor);
        
        double impactTime = 2.0 * (vy / ProjectileWorld.GRAVITY) - 1;
        
        double impactX = player.getX() + impactTime * vx;

I’ve added this to the scenario so that you can have a play. You can see that the cross on the ground moves as you aim, and once you fire, it correctly predicts where the banana will land. Having the visible target makes our scenario a bit too easy for human players, but the calculation will be useful in future posts.

我已经添加了这个剧本因而你可以试玩一下。你可以看到当你瞄准时地面上的叉在移动,而且一旦你开火,它准确地预测香蕉将会在哪儿落地。拥有可见的目标使得我们的剧本对于人类玩家过于简单,但是在今后的帖子里这个计算将会非常有用。

标题基于SpringBoot+Vue的社区便民服务平台研究AI更换标题第1章引言介绍社区便民服务平台的研究背景、意义,以及基于SpringBoot+Vue技术的研究现状和创新点。1.1研究背景与意义分析社区便民服务的重要性,以及SpringBoot+Vue技术在平台建设中的优势。1.2国内外研究现状概述国内外在社区便民服务平台方面的发展现状。1.3研究方法与创新点阐述本文采用的研究方法和在SpringBoot+Vue技术应用上的创新之处。第2章相关理论介绍SpringBoot和Vue的相关理论基础,以及它们在社区便民服务平台中的应用。2.1SpringBoot技术概述解释SpringBoot的基本概念、特点及其在便民服务平台中的应用价值。2.2Vue技术概述阐述Vue的核心思想、技术特性及其在前端界面开发中的优势。2.3SpringBoot与Vue的整合应用探讨SpringBoot与Vue如何有效整合,以提升社区便民服务平台的性能。第3章平台需求分析与设计分析社区便民服务平台的需求,并基于SpringBoot+Vue技术进行平台设计。3.1需求分析明确平台需满足的功能需求和性能需求。3.2架构设计设计平台的整体架构,包括前后端分离、模块化设计等思想。3.3数据库设计根据平台需求设计合理的数据库结构,包括数据表、字段等。第4章平台实现与关键技术详细阐述基于SpringBoot+Vue的社区便民服务平台的实现过程及关键技术。4.1后端服务实现使用SpringBoot实现后端服务,包括用户管理、服务管理等核心功能。4.2前端界面实现采用Vue技术实现前端界面,提供友好的用户交互体验。4.3前后端交互技术探讨前后端数据交互的方式,如RESTful API、WebSocket等。第5章平台测试与优化对实现的社区便民服务平台进行全面测试,并针对问题进行优化。5.1测试环境与工具介绍测试
资源下载链接为: https://pan.quark.cn/s/9648a1f24758 Java中将Word文档转换为PDF是一种常见的技术需求,尤其在跨平台共享、保持格式一致性和便于在线预览等场景中非常实用。通常,开发者会借助专门的库来实现这一功能,其中Aspose.Words是一个非常强大的选择。Aspose.Words是由Aspose公司开发的文档处理组件,支持多种文件格式,包括Word和PDF。它提供了丰富的API,方便开发者在Java应用程序中进行文件转换、编辑和格式化操作,尤其在Word转PDF方面表现卓越。 使用Aspose.Words进行Word转PDF的步骤如下: 添加依赖:通过Maven或Gradle等工具将Aspose.Words的Java库引入项目。 加载Word文档:使用Document类加载Word文件,例如: 配置输出选项:创建PdfSaveOptions对象,用于设置PDF保存时的选项,如图像质量、安全性等。 执行转换:调用Document的save方法,传入输出路径和PdfSaveOptions对象,例如: 支持多种输出格式:Aspose.Words不仅支持将Word转换为PDF,还能转换为HTML、EPUB、XPS等多种格式,只需更换SaveOptions的子类即可。 保持格式与样式:在转换过程中,Aspose.Words能够最大程度地保留源文档的格式和样式,包括文本样式、图像位置、表格布局等。 优化性能:Aspose.Words支持并行处理和多线程技术,可以显著提高大量文档转换的速度。 处理复杂文档:它能够处理包含宏、复杂公式、图表、脚注等元素的Word文档,确保转换后的PDF内容完整且可读。 安全性与版权:在转换过程中,可以设置PDF的访问权限,例如禁止打印或复制文本,从而保护文档内容。 在实际开发中,还需要注意错误和异常的处理,以
资源下载链接为: https://pan.quark.cn/s/f989b9092fc5 欧瑞E2000系列变频器是一款高性能矢量控制通用变频器,适用于交流异步感应电机及永磁同步电机调速控制。它具备优良动态性能与丰富应用功能,可增强产品可靠性与环境适应性。说明书包含以下内容: 安全注意事项:强调操作安全,指出潜在危险及防范措施。要求操作人员需经专业培训且合格,未断电时禁止接线、检查、更换器件等作业。通电后要先安全检查,运行时避免触摸高温散热器底座以防烫伤。 产品简介:涵盖E2000变频器型号命名规则、功能代号命名规则、铭牌、外观、技术规范及选配件等。技术规范详细列出电压范围、频率范围、功率范围等关键性能指标。 控制面板介绍:说明控制面板结构尺寸、操作方法及参数设置方式,还介绍功能码区切换方法和面板显示内容。 安装接线:提供外围接线图、安装方法、接线步骤、控制端子功能简介及主回路和功率回路测量方法,强调保护导体(地线)截面积和传导辐射干扰对策。 简易操作与运行指南:介绍产品基本知识、简易操作指南和基本控制运行指南,帮助用户掌握变频器基本操作和控制方法。 功能参数:详细阐述变频器多个功能参数区域,包括基本参数、运行控制、多功能输入输出端子、模拟量输入输出、脉冲输入输出控制、多段速度控制、辅助功能、故障与保护、电机参数区、通讯参数、PID参数区、保留参数区、转矩控制参数区、第二电机参数区和显示参数区。 保养和维护:包含日常保养维护、定期维护、易损件更换及储存等内容。 附录部分提供常见故障处理、供水系统参考连线图、产品及结构型式一览表、制动电阻选型表、通讯手册、功能码速查表、通用编码器扩展卡使用说明、主/从控制调试、输入滤波器型号尺寸和总线通讯简介等。手册还记录了升级信息,并提醒用户关注公司网站更新内容,以确保安全使用。 这份说明书是欧瑞E2000系列变频器的标准使用指南,覆盖设备
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值