详解向量的点积(dot product)

两个向量之间的点积(dot product),也称数量积和内积。向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 和向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 的点积表示为 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ ⋅ b ⃗ \vec{a} \cdot \vec{b} </math>a ⋅b 。点积的结果都是一个标量,表示两个向量的相似程度。

点积的计算方法

点积有两种常见的计算方法,一种是使用向量的坐标分量进行计算,另一种是使用向量的长度和夹角进行计算。

坐标分量计算方法

点积的坐标分量计算方法是:将两个向量对应分量相乘,然后相加。对于两个三维向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 和 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b :
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> a ⃗ ⋅ b ⃗ = A x ⋅ B x + A y ⋅ B y + A z ⋅ B z \vec{a} \cdot \vec{b} = A_x \cdot B_x + A_y \cdot B_y + A_z \cdot B_z </math>a ⋅b =Ax⋅Bx+Ay⋅By+Az⋅Bz

其中, <math xmlns="http://www.w3.org/1998/Math/MathML"> A x A_x </math>Ax, <math xmlns="http://www.w3.org/1998/Math/MathML"> A y A_y </math>Ay, <math xmlns="http://www.w3.org/1998/Math/MathML"> A z A_z </math>Az 是向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 的分量, <math xmlns="http://www.w3.org/1998/Math/MathML"> B x B_x </math>Bx, <math xmlns="http://www.w3.org/1998/Math/MathML"> B y B_y </math>By, <math xmlns="http://www.w3.org/1998/Math/MathML"> B z B_z </math>Bz 是向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 的分量。

这种计算方法涉及到向量的坐标分量,适用于已知向量坐标分量的情况,可以直接按照公式进行计算。这是一种较为数学化的描述,它在考虑向量在各个坐标轴上的投影分量,并将它们相乘再相加,得到最终的结果。

几何意义

投影的概念是将一个向量投影到另一个向量上,得到在另一个向量方向上的投影分量。

向量的定义:即向量在某个方向上的投影分量等于该向量在该方向上的长度乘以该方向的单位向量。

在这里,我们考虑 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在 X 轴上的投影。在 X 轴上,单位向量为 <math xmlns="http://www.w3.org/1998/Math/MathML"> i ⃗ = ( 1 , 0 , 0 ) \vec{i}=(1,0,0) </math>i =(1,0,0)。因此, <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在 X 轴上的投影分量可以表示为内积(点积):
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> 在 X 轴上的投影分量 = a ⃗ ⋅ i ⃗ = A x ⋅ 1 + A y ⋅ 0 + A z ⋅ 0 = A x \begin{aligned} 在 X 轴上的投影分量 &= \vec{a} \cdot \vec{i} \\ &= A_x \cdot 1 + A_y \cdot 0 + A_z \cdot 0 \\ &= A_x \end{aligned} </math>在 X 轴上的投影分量=a ⋅i =Ax⋅1+Ay⋅0+Az⋅0=Ax

这个概念可以推广到 Y 轴和 Z 轴上的投影分量,其中单位向量分别为 <math xmlns="http://www.w3.org/1998/Math/MathML"> j ⃗ = ( 0 , 1 , 0 ) \vec{j}=(0,1,0) </math>j =(0,1,0) 和 <math xmlns="http://www.w3.org/1998/Math/MathML"> k ⃗ = ( 0 , 0 , 1 ) \vec{k}=(0,0,1) </math>k =(0,0,1)。
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> 在 Y 轴上的投影分量 = a ⃗ ⋅ j ⃗ = A x ⋅ 0 + A y ⋅ 1 + A z ⋅ 0 = A y \begin{aligned} 在 Y 轴上的投影分量 &= \vec{a} \cdot \vec{j} \\ &= A_x \cdot 0 + A_y \cdot 1 + A_z \cdot 0 \\ &= A_y \\ \end{aligned} </math>在 Y 轴上的投影分量=a ⋅j =Ax⋅0+Ay⋅1+Az⋅0=Ay
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> 在 Z 轴上的投影分量 = a ⃗ ⋅ k ⃗ = A x ⋅ 0 + A y ⋅ 0 + A z ⋅ 1 = A z \begin{aligned} 在 Z 轴上的投影分量 &= \vec{a} \cdot \vec{k} \\ &= A_x \cdot 0 + A_y \cdot 0 + A_z \cdot 1 \\ &= A_z \end{aligned} </math>在 Z 轴上的投影分量=a ⋅k =Ax⋅0+Ay⋅0+Az⋅1=Az

同理,向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 上的投影分量为
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> 在 X 轴上的投影分量 = a ⃗ ⋅ i b ⃗ = a ⃗ ⋅ ( B x , 0 , 0 ) = A x ⋅ B x + A y ⋅ 0 + A z ⋅ 0 = A x ⋅ B x \begin{aligned} 在 X 轴上的投影分量 &= \vec{a} \cdot \vec{i_b} \\ &= \vec{a} \cdot (B_x, 0, 0) \\ &= A_x \cdot B_x + A_y \cdot 0 + A_z \cdot 0 \\ &= A_x \cdot B_x \\ \end{aligned} </math>在 X 轴上的投影分量=a ⋅ib =a ⋅(Bx,0,0)=Ax⋅Bx+Ay⋅0+Az⋅0=Ax⋅Bx
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> 在 Y 轴上的投影分量 = a ⃗ ⋅ j b ⃗ = a ⃗ ⋅ ( 0 , B y , 0 ) = A x ⋅ 0 + A y ⋅ B y + A z ⋅ 0 = A y ⋅ B y \begin{aligned} 在 Y 轴上的投影分量 &= \vec{a} \cdot \vec{j_b} \\ &= \vec{a} \cdot (0, B_y, 0) \\ &= A_x \cdot 0 + A_y \cdot B_y + A_z \cdot 0 \\ &= A_y \cdot B_y \\ \end{aligned} </math>在 Y 轴上的投影分量=a ⋅jb =a ⋅(0,By,0)=Ax⋅0+Ay⋅By+Az⋅0=Ay⋅By
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> 在 Z 轴上的投影分量 = a ⃗ ⋅ k b ⃗ = a ⃗ ⋅ ( 0 , 0 , B z ) = A x ⋅ 0 + A y ⋅ 0 + A z ⋅ B z = A z ⋅ B z \begin{aligned} 在 Z 轴上的投影分量 &= \vec{a} \cdot \vec{k_b} \\ &= \vec{a} \cdot (0, 0, B_z) \\ &= A_x \cdot 0 + A_y \cdot 0 + A_z \cdot B_z \\ &= A_z \cdot B_z \end{aligned} </math>在 Z 轴上的投影分量=a ⋅kb =a ⋅(0,0,Bz)=Ax⋅0+Ay⋅0+Az⋅Bz=Az⋅Bz

所以, <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 方向上的投影分量为:

  1. 在 X 轴上的投影分量: 向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在 X 轴上在向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 方向上的投影分量为 <math xmlns="http://www.w3.org/1998/Math/MathML"> A x ⋅ B x A_x \cdot B_x </math>Ax⋅Bx。这是通过将向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在 X 轴上的长度乘以向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 在 X 轴上的长度得到的。
  2. 在 Y 轴上的投影分量: 向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在 Y 轴上在向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 方向上的投影分量为 <math xmlns="http://www.w3.org/1998/Math/MathML"> A y ⋅ B y A_y \cdot B_y </math>Ay⋅By。这是通过将向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在 Y 轴上的长度乘以向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 在 Y 轴上的长度得到的。
  3. 在 Z 轴上的投影分量: 向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在 Z 轴上在向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 方向上的投影分量为 <math xmlns="http://www.w3.org/1998/Math/MathML"> A z ⋅ B z A_z \cdot B_z </math>Az⋅Bz。这是通过将向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在 Z 轴上的长度乘以向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 在 Z 轴上的长度得到的。

最后,将这些投影分量相加,得到的结果就是两个向量在各个坐标轴上的投影分量的总和,即点积的值。它描述了两个向量之间的相似程度。

长度和夹角计算方法

点积还可以通过向量的长度和夹角来计算,计算公式为:

<math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ ⋅ b ⃗ = ∣ a ⃗ ∣ ⋅ ∣ b ⃗ ∣ ⋅ c o s ( θ ) \vec{a} \cdot \vec{b}= |\vec{a}| \cdot |\vec{b}| \cdot cos(\theta) </math>a ⋅b =∣a ∣⋅∣b ∣⋅cos(θ)

其中: <math xmlns="http://www.w3.org/1998/Math/MathML"> ∣ a ⃗ ∣ |\vec{a}| </math>∣a ∣ 和 <math xmlns="http://www.w3.org/1998/Math/MathML"> ∣ b ⃗ ∣ |\vec{b}| </math>∣b ∣ 分别是向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 和 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 的长度, <math xmlns="http://www.w3.org/1998/Math/MathML"> θ \theta </math>θ 是向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 和向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 之间的夹角。

这种计算方法适用于已知向量的长度和夹角的情况,可以使用向量的长度和夹角的三角函数(余弦)关系来计算点积。

几何意义

设 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec a </math>a 终点为 <math xmlns="http://www.w3.org/1998/Math/MathML"> A ( x 1 , y 1 , z 1 ) A(x_1,y_1,z_1) </math>A(x1,y1,z1), <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec b </math>b 的终点为 <math xmlns="http://www.w3.org/1998/Math/MathML"> B ( x 2 , y 2 , z 2 ) B(x_2,y_2,z_2) </math>B(x2,y2,z2),原点为 <math xmlns="http://www.w3.org/1998/Math/MathML"> O O </math>O,则 <math xmlns="http://www.w3.org/1998/Math/MathML"> A B ⃗ = ( x 2 − x 1 , y 2 − y 1 , z 2 − z 1 ) \vec {AB}=(x_2-x_1,y_2-y_1,z_2-z_1) </math>AB =(x2−x1,y2−y1,z2−z1)

在 <math xmlns="http://www.w3.org/1998/Math/MathML"> △ O A B \triangle{OAB} </math>△OAB 中,由余弦定理得:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∣ A B ⃗ ∣ 2 = ∣ a ⃗ ∣ 2 + ∣ b ⃗ ∣ 2 − 2 ∣ a ⃗ ∣ ∣ b ⃗ ∣ cos ⁡ θ \left |\vec {AB}\right |^2=\left |\vec a \right |^2+\left |\vec b \right |^2-2\left |\vec a \right |\left |\vec b \right |\cos\theta </math> AB 2=∣a ∣2+ b 2−2∣a ∣ b cosθ

使用距离公式进行处理,可得:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∣ a ⃗ ∣ ∣ b ⃗ ∣ cos ⁡ θ = x 1 2 + y 1 2 + z 1 2 + x 2 2 + y 2 2 + z 2 2 − [ ( x 2 − x 1 ) 2 + ( y 2 − y 1 ) 2 + ( z 2 − z 1 ) 2 ] 2 \left |\vec a \right |\left |\vec b \right |\cos\theta=\frac {x_1^2+y_1^2+z_1^2+x_2^2+y_2^2+z_2^2-[(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2]}{2} </math>∣a ∣ b cosθ=2x12+y12+z12+x22+y22+z22−[(x2−x1)2+(y2−y1)2+(z2−z1)2]

去括号后合并,可得:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> ∣ a ⃗ ∣ ∣ b ⃗ ∣ cos ⁡ θ = x 1 x 2 + y 1 y 2 + z 1 z 2 = a ⃗ ⋅ b ⃗ \left |\vec a \right |\left |\vec b \right |\cos\theta=x_1x_2+y_1y_2+z_1z_2=\vec a\cdot \vec b </math>∣a ∣ b cosθ=x1x2+y1y2+z1z2=a ⋅b

根据上面的公式可计算 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec a </math>a 与 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec b </math>b 之间的夹角: <math xmlns="http://www.w3.org/1998/Math/MathML"> θ = arccos ⁡ ( a ⃗ ⋅ b ⃗ ∣ a ⃗ ∣ ∣ b ⃗ ∣ ) \theta=\arccos (\frac {\vec a\cdot\vec b} {\left |\vec a \right |\left |\vec b \right |}) </math>θ=arccos(∣a ∣∣b ∣a ⋅b )

无论使用哪种方法,点积的结果都是一个标量,表示两个向量的相似程度。

证明一致性

现在我们来证明这两种计算方法的一致性,即证明上述两个表达式是等价的。我们可以使用向量的定义以及三角函数的关系:

首先,两个向量的夹角余弦值可以表示为:

<math xmlns="http://www.w3.org/1998/Math/MathML"> c o s ( θ ) = A ⋅ B ∣ A ∣ ⋅ ∣ B ∣ cos(\theta) = \frac{A \cdot B }{|A| \cdot |B|} </math>cos(θ)=∣A∣⋅∣B∣A⋅B

将坐标分量计算的点积公式代入,得到:

<math xmlns="http://www.w3.org/1998/Math/MathML"> c o s ( θ ) = A x ⋅ B x + A y ⋅ B y + A z ⋅ B z A x 2 + A y 2 + A z 2 ⋅ B x 2 + B y 2 + B z 2 cos(θ) = \frac{A_x \cdot B_x + A_y \cdot B_y + A_z \cdot B_z}{\sqrt{{A_x}^2 + {A_y}^2+ {A_z}^2} \cdot \sqrt{{B_x}^2 + {B_y}^2 + {B_z}^2}} </math>cos(θ)=Ax2+Ay2+Az2 ⋅Bx2+By2+Bz2 Ax⋅Bx+Ay⋅By+Az⋅Bz

通过化简,可以证明上述等式成立。这就证明了两种计算方法得到的点积是一致的。

总体来说,两种计算方法从不同的角度描述了向量之间的关系,但它们最终得到的结果是相同的,这是因为它们实际上描述的是同一个几何关系。

点积的意义

点积的几何意义:

  1. 夹角和正交性:点积的值可以用来判断两个向量的相似性,例如:

    • 如果两个向量的点积为零,意味着它们是正交的(垂直),因为它们之间的夹角为90度。
    • 如果点积为正,表示两个向量之间的夹角小于90度,它们趋向于同一方向。
    • 如果点积为负,表示两个向量之间的夹角大于90度,它们趋向于相反的方向。
  2. 投影 :点积可以用来计算一个向量在另一个向量方向上的投影。具体而言,两个向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 和 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 的点积除以向量 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 的长度,得到的结果就是 <math xmlns="http://www.w3.org/1998/Math/MathML"> a ⃗ \vec{a} </math>a 在 <math xmlns="http://www.w3.org/1998/Math/MathML"> b ⃗ \vec{b} </math>b 方向上的投影的长度。

  3. 向量长度和夹角关系:点积的公式中包含向量的长度,因此可以用点积来推导夹角的余弦值。

Three.js 中的点积

在Three.js中,Vector3dot方法计算的是两个向量之间的点积(dot product),示例代码如下:

javascript 复制代码
var vectorA = new THREE.Vector3(2, 3, 4);
var vectorB = new THREE.Vector3(1, 0, -1);

var dotProduct = vectorA.dot(vectorB);
// 输出点积的结果
console.log("Dot Product:", dotProduct);

参考

相关推荐
好看资源平台3 分钟前
前端框架对比与选择:如何在现代Web开发中做出最佳决策
前端·前端框架
4triumph5 分钟前
Vue.js教程笔记
前端·vue.js
程序员大金22 分钟前
基于SSM+Vue+MySQL的酒店管理系统
前端·vue.js·后端·mysql·spring·tomcat·mybatis
清灵xmf25 分钟前
提前解锁 Vue 3.5 的新特性
前端·javascript·vue.js·vue3.5
白云~️38 分钟前
监听html元素是否被删除,删除之后重新生成被删除的元素
前端·javascript·html
金灰1 小时前
有关JS下隐藏的敏感信息
前端·网络·安全
Yxmeimei1 小时前
css实现居中的方法
前端·css·html
6230_1 小时前
git使用“保姆级”教程2——初始化及工作机制解释
开发语言·前端·笔记·git·html·学习方法·改行学it
二川bro1 小时前
Vue 修饰符 | 指令 区别
前端·vue.js
一只欢喜1 小时前
uniapp使用uview2上传图片功能
前端·uni-app