13.理论知识:向量

来源:互联网 发布:mac屏蔽广告插件 编辑:程序博客网 时间:2024/05/14 20:56

13.Theory: Vectors

This post is a bit of theory about vectors, ready for more work onour bus scenario.

这篇帖子介绍一点关于向量的理论,这是为进一步完善巴士游戏剧本做准备。

A lot of the recent posts on this blog (e.g. on drifting, braking) have involved manipulating X and Y speeds. In mathematics, these speeds are termed a two-dimensional vector, written as either (xSpeed, ySpeed), or like this:

这个博客里最近许多帖子(比如漂移,刹车)都涉及到操作x和y方向的速度。在数学里,这样的速度被称为二维向量,记做(xSpeed, ySpeed),或是如下形式:

\begin{pmatrix} \text{xSpeed} \\ \text{ySpeed} \end{pmatrix}

So if our current speed is 3 in the X direction and -4 in the Y direction, we can write this as (3, -4) or\begin{pmatrix} 3 \\ -4 \end{pmatrix}.We saw in the drifting post how to form X and Y speeds that move at a given speed and angle. This can be written in mathematical notation as:

因此如果当前x方向的速度是3而y方向的速度是-4,则我们可以记做(3,-4)或\begin{pmatrix} 3 \\ -4 \end{pmatrix}。我们在漂移帖子里了解了如何根据给定的速度和角度值来产生x和y的速度值。这可以写为数学标记:

\begin{pmatrix} \text{speed} \times \cos(\text{angle}) \\ \text{speed} \times \sin(\text{angle}) \end{pmatrix}

In fact, it’s so common that all parts of a vector get multiplied by the same number that mathematicians use a notation whereby the number is moved outside the vector — so this is the same as the above:

事实上,由于向量的所有分量都被乘上了相同的数字,因此数学里使用了另一种标记把该相同的数字移到向量的外部——其实这和上面是相同的:

\text{speed} \times \begin{pmatrix} \cos(\text{angle}) \\ \sin(\text{angle}) \end{pmatrix}

A vector can represent anything where one element is X and one is Y, so it can be a position or a speed or an acceleration.

一个向量可以表示任意事物,其中一个元素是x而另一个是y,因此它可以表示位置、速度或者加速度。

Adding and Splitting Vectors

累加及分解向量

Vectors can be added together, by independently adding their X components together and adding their Y components together. This is easily seen graphically, by joining one vector’s end point to the start point of the next, e.g.

向量可以累加在一起,通过将其x和y分量分别相加得到。用图形的方式很容易明白,比如,通过连接一个向量的终点和另一个向量的起点来相加。

The black vector is added to the red vector, which is equivalent to travelling along the black, then along the red. This adds up to the blue vector. The X component of the blue vector, 6, is the addition of the X component of the black vector (2) and of the red vector (4). Similarly, the Y component of the blue vector, 3, is the addition of the Y component of the black vector (5) and of the red vector (-2).

黑色的向量被累加到红色的向量上,这相当于沿着黑色的向量前进,接着沿着红色的前进。相加的结果形成了蓝色的向量。蓝色向量的x分量6,是黑色向量的x分量(2)和红色向量的x分量(4)的和。类似地,蓝色向量的y分量3,是黑色向量的y分量(5)和红色向量的y分量(-2)的和。

Just as you can add two vectors to make one, you can take one vector and subdivide it into two. The most helpful application of this is in splitting a vector into its X component and Y component:

正如你可以将两个向量累加为一个,你也可以将一个向量分解为两个。最有益的应用是将一个向量分解为其x分量和y分量。

This is quite trivial, but it turns out to often be useful to split the vector this way, as we will see in our next post.

这样做是十分平常的,但是按这种方式分解向量的结果往往是很有用的,我们将在下一篇帖子中看到。

 

原创粉丝点击