3D 向量的示例
向量用于存储变量的多个分量,通常是空间维度的轴。因此,它们通常用于 2D 或 3D。
实际上,有两种方法可以表示向量
- 2D
- 这可以定义为“旋转和大小”或“x 方向上的位移和 y 方向上的位移”。
- 3D
- 这可以定义为“xz 方向上的旋转、y 方向上的旋转和大小”或“x 方向上的位移、y 方向上的位移和 z 方向上的位移”。
通常,在游戏中,我们使用维度上的位移版本,而不是大小和旋转。
向量可以有多种形式
i、j、k 形式 - 其中
i 表示
x 轴 上的
1 个单位,
j 表示
y 轴 上的
1 个单位,如果是在 3D 中,
k 表示
z 轴 上的
1 个单位在 2D 中,它看起来像这样:
,其中 3 表示 正 x 轴 上的 3 个单位,4 表示 正 y 轴 上的 4 个单位。
在 3D 中,它看起来像这样:
,其中 6 表示 正 x 轴 上的 6 个单位,-3 表示 负 y 轴 上的 3 个单位,5 表示 正 z 轴 上的 5 个单位。
列向量 - 这是最常见的向量形式。
在 2D 中,它看起来像这样:
,其中 3 表示 正 x 轴 上的 3 个单位,4 表示 正 y 轴 上的 4 个单位。
在 3D 中,它看起来像这样:
,其中 6 表示 正 x 轴 上的 6 个单位,-3 表示 负 y 轴 上的 3 个单位,5 表示 正 z 轴 上的 5 个单位。
行向量 - 这是最不常见的向量形式。
在 2D 中,它看起来像这样:
,其中 3 表示 正 x 轴 上的 3 个单位,4 表示 正 y 轴 上的 4 个单位。
在 3D 中,它看起来像这样:
,其中 6 表示 正 x 轴 上的 6 个单位,-3 表示 负 y 轴 上的 3 个单位,5 表示 正 z 轴 上的 5 个单位。
在写向量时,你可以用这种方式表示它
或只是 
从一个位置到另一个位置(从 A 到 B)时,可以这样写
加向量就像加同类项一样简单。
- 加法

- 减法

注意:将常数加减到向量中是未定义的。
当一个常数乘以/除以一个向量时,你只需将该乘以/除以操作应用于向量的所有分量。
- 乘法

- 除法

当一个向量乘以另一个向量时,有两种定义的向量乘法方式:向量点积 和 向量叉积。
二维中的单位向量基于此,这意味着x和y不能同时为1,否则它将不会形成一个圆,而是形成一个正方形,并且大小将大于1(一个单位)。
当大小不重要,只有方向重要时,使用单位向量。在二维中,它基于单位圆,在三维中,它基于单位球;x、y和z的值介于-1和1之间。
它的表示法是:
要将向量转换为单位长度向量,请使用以下公式:
,这被称为归一化向量。
零向量(有时称为零向量)是一个所有内容都是 0 的向量。如果零向量用
表示;
... 并且它在 2D 中,它看起来像:
... 并且它在 3D 中,它看起来像:
... 并且它在
D 中,它看起来像:
零位置向量的示例是原点;这是因为它有一个原点
或
。
另一个示例是,如果您想停止物体移动,您可以将 速度 设置为零向量。
由于向量由许多部分组成,因此用于每个维度的数字表示每个方向的距离。为了找到对角线穿过维度的点到点的距离,您需要找到向量的模。
二维向量的模由(根据勾股定理)给出
三维向量的模由给出
位置向量是一个被视为坐标的向量,因此它是一个从原点到点的向量。字母O 通常用于表示原点。
位置向量可以写成
等同于说有一个点
,其坐标为:

练习:找出这些位置向量之间的向量
答案
|
点积有两个公式
其中
是两个向量之间的夹角。
从这些公式,我们可以得到另一个计算它们之间夹角的公式
如果
,则这意味着这两个向量是垂直的。
要注意的是
。
- 参见:w:Dot_product#Scalar_projection_and_first_properties
标量投影
标量投影(或标量分量)是求一个向量(**A**)在另一个向量(**B**)上的投影的长度。

其中θ是**A**和**B**之间的夹角[1]。
这个投影的向量(**A** 投影到 **B** 上)也可以用下面的公式求出[1]

一个基本的向量方程由一个向量和另一个向量的变量系数组成。独立的向量被称为位置向量,而带有变量系数的向量被称为方向向量。位置向量表示向量在3D空间中的位置,而方向向量表示向量指向的方向。位置向量的向量可以是直线上任何点的的位矢。
一个典型的方程可能看起来像这样:
或者 
当直线的方向向量是彼此的标量倍数时,这些直线是平行的。
示例
直线 1:
直线 2: 
它们是平行的,因为
.
所以,如果该点的位置向量是
,而直线方程是
,并且你想看看 **P** 是否位于 **直线** 上,那么你需要执行以下操作
将 **点** 等于 **方程**

从此你可以从每行创建 3 个独立的方程



然后解出每个方程以找到 **t**
→ 
→ 
→ 
只有当所有 3 个 **t** 的值都相同时,**点** 才在 **直线** 上,因为其中一个 **t** 值与另外两个不同,所以 **点** 不在 **直线** 上。
因此,在这个例子中,你需要两条直线,直线 1:
和直线 2:
然后你需要将这两个方程设为相等。

然后减去一组常数以将常数保留在一侧。

由此,你可以从每一行创建一个方程



在找到 t 和 u 的值时,你只需要使用两个方程,这样你就可以检查第三个方程是否匹配(在 2D 中不需要此检查步骤)。我将使用方程 1 和方程 2: *使用任何你想要的联立方程求解方法*
→
*将此方程的两边都乘以 2*

*得到方程 1,并从中减去方程 2*
求解得到u
将u代回方程1
求解得到t
现在让我们检查一下它是否适用于最终方程式,将u和t的值代入你没有用过的方程式。



如果你得到一个等式表达式(一个常数等于它自身),这意味着它们相交,否则它们不相交。这被称为斜交。
假设有一个向量方程
,并且有一个点P,其位置向量为:
。我们想要找到直线上距离P最近的点的坐标以及该点和P之间的距离。
我们将直线上的这个点称为X。
首先,我们需要使用我们的点积规则,因为从P到X的直线将垂直于直线本身。为此,我们需要找到直线的方向和从P到X的向量。
直线的方向就是直线的方向向量(我们称之为A):
至于P到X的方向,我们需要先找到X,即使它用t表示。
- X就是直线方程本身写成一个向量

- 由此,我们可以使用“计算两个位置向量之间的向量”找到用t表示的
:
现在我们有了两个方向,就可以使用点积了






现在我们有了t的值,可以将其代入
的方程式中
,这就是我们一直在寻找的位置向量(X)。
至于P和X之间的距离,我们需要将t代入我们的
方程式中

- 这是我们的向量,现在我们只需要找到向量的长度/大小
≈
, 这是 **点 P 到直线上最近点 X 的距离**。
叉积定义为:
,其中
是 它们之间的夹角,而
是一个 单位向量,它同时垂直于
和
。叉积只在 3 维和 7 维中有效 (你不需要 7 维版本)。
有两个向量同时垂直于 A 和 B,一个指向页面/屏幕外,另一个指向屏幕内。一个是
,另一个是
。由于它们都指向不同的方向,并且大小相同,这意味着:
。你可以使用 右手定则 来找到叉积向量的方向。
由于你的电脑没有 "右手",你可以使用这个公式,它能做同样的事情
[2]
法向量是一个指向几何体表面向外的单位长度向量。对于每块平面几何体,存在两个法向量,一个直接向上(相对于表面),另一个直接向下(相对于表面),使得一个与另一个相反。
要计算法向量,首先需要找到几何体的一个角点。在该点处将有两个边延伸出来。你需要找到这两条边的向量。然后你需要找到边 1 (E1) 和边 2 (E2) 的叉积。之后你需要将向量归一化使其单位长度。
重写成一个方程
注意:从数学上来说,这更好,但在计算上更差,使用计算机时使用第一个版本来避免计算两次叉积。这将需要存储一个额外的变量,但对于处理器来说要容易得多。
要找到另一个法向量 (n2),可以使用以下任一方程
或者 