Dot Product

These are vectors:

They can be multiplied using the "Dot Product" (also see Cross Product).

Calculating

You can calculate the Dot Product of two vectors this way:

a · b = |a| × |b| × cos(θ)

Where:
|a| is the magnitude (length) of vector a
|b| is the magnitude (length) of vector b
θ is the angle between a and b

So we multiply the length of a times the length of b, then multiply by the cosine of the angle between a and b

OR you can calculate it this way:

a · b = ax × bx + ay × by

So we multiply the x‘s, multiply the y‘s, then add.

Both methods work!

Example: Calculate the dot product of vectors a and b:

a · b = |a| × |b| × cos(θ)

a · b = 10 × 13 × cos(59.5°)

a · b = 10 × 13 × 0.5075...

a · b = 65.98... = 66 (rounded)

a · b = ax × bx + ay × by

a · b = -6 × 5 + 8 × 12

a · b = -30 + 96

a · b = 66

Both methods came up with the same result (after rounding)

Also note that we used minus 6 for ax (it is heading in the negative x-direction)

Note: you can use the Vector Calculator to help you.

Why cos(θ) ?

OK, to multiply two vectors it makes sense to multiply their lengths together but only when they point in the same direction.

So we make one "point in the same direction" as the other by multiplying by cos(θ):

We take the component of a
that lies alongside b

Like shining a light to see
where the shadow lies

THEN we multiply !

It works exactly the same if we "projected" b alongside a then multiplied:

Because it doesn‘t matter which order we do the multiplication:

|a| × |b| × cos(θ) = |a| × cos(θ) × |b|

Right Angles

When two vectors are at right angles to each other the dot product is zero.

Example: calculate the Dot Product for:

a · b = |a| × |b| × cos(θ)

a · b = | a| × | b| × cos(90°)

a · b = | a| × | b| × 0

a · b = 0

a · b = ax × bx + ay × by

a · b = -12 × 12 + 16 × 9

a · b = -144 + 144

a · b = 0

This can be a handy way to find out if two vectors are at right angles.

Three or More Dimensions

This all works fine in 3 (or more) dimensions, too.

And can actually be very useful!

Example: Sam has measured the end-points of two poles, and wants to know the angle between them:

We have 3 dimensions, so don‘t forget the z-components:

a · b = ax × bx + ay × by + az × bz

a · b = 9 × 4 + 2 × 8 + 7 × 10

a · b = 36 + 16 + 70

a · b = 122

Now for the other formula:

a · b = |a| × |b| × cos(θ)

But what is |a| ? It is the magnitude, or length, of the vector a. We can use Pythagoras:

  • |a| = √(42 + 82 + 102)
  • |a| = √(16 + 64 + 100)
  • |a| = √180

Likewise for |b|:

  • |b| = √(92 + 22 + 72)
  • |b| = √(81 + 4 + 49)
  • |b| = √134

And we know from the calculation above that a · b = 122, so:

a · b = |a| × |b| × cos(θ)

122 = √180 × √134 × cos(θ)

cos(θ) = 122 / (√180 × √134)

cos(θ) = 0.7855...

θ = cos -1(0.7855...) = 38.2...°

Done!

I tried a calculation like that once, but worked all in angles and distances ... it was very hard, involved lots of trigonometry, and my brain hurt. The method above is much easier.

Cross Product

The Dot Product gives a scalar (ordinary number) answer, and is sometimes called the scalar product.

But there is also the Cross Product which gives a vector as an answer, and is sometimes called the vector product.

时间: 2024-10-14 05:02:54

Dot Product的相关文章

Dot product of sparse vectors

Suppose we have very large sparse vectors (most of the elements in vector are zeros) Find a data structure to store them Compute the Dot Product. Follow-up:What if one of the vectors is very small? 1 a = [(1,2),(2,3),(100,5)] 2 b = [(0,5),(1,1),(100,

(转载)Cross product

原文地址:https://en.wikipedia.org/wiki/Cross_product Cross product From Wikipedia, the free encyclopedia This article is about the cross product of two vectors in three-dimensional Euclidean space. For other uses, see Cross product (disambiguation). In m

Cross Product

Cross Product These are two vectors: They can be multiplied using the "Cross Product" (also see Dot Product) The Cross Product a × b of two vectors is another vector that is at right angles to both: And it all happens in 3 dimensions! Calculatin

【译】Unity3D Shader 新手教程(2/6) —— 积雪Shader

如果你是一个shader编程的新手,并且你想学到下面这些酷炫的技术,我觉得你可以看看这篇教程: 实现一个积雪效果的shader 创建一个具有凹凸纹理的shader 为每个像素修改其对应纹理值 在表面着色器中修改模型的顶点数据 引论 这是我们系列教程的第二部分,我们将在此部分实现些有用的技术.在学习完第一部分的所有背景知识后,我们将利用所学的知识实现一个简单的积雪效果的shader.效果如下: 准备工作 我们想做的其实很简单,简单介绍一下: 随着Snow Level(表示积雪的程度,该值越大,积雪

基于支持向量机SVM的人脸识别

一.线性SVM 1. 背景: 1.1 最早是由 Vladimir N. Vapnik 和 Alexey Ya. Chervonenkis 在1963年提出 1.2 目前的版本(soft margin)是由Corinna Cortes 和 Vapnik在1993年提出,并在1995年发表 1.3 深度学习(2012)出现之前,SVM被认为机器学习中近十几年来最成功,表现最好的算法 2. 机器学习的一般框架: 训练集 => 提取特征向量 => 结合一定的算法(分类器:比如决策树,KNN)=>

CG 标准函数库

(1)数学函数 函数 功能描述 abs(x) 返回输入参数的绝对值 acos(x) 反余切函数,输入参数范围为[-1,1], 返回[0,π]区间的角度值 all(x) 如果输入参数均不为0,则返回ture: 否则返回flase.&&运算 any(x) 输入参数只要有其中一个不为0,则返回true. asin(x) 反正弦函数,输入参数取值区间为[?1,1],返回角度值范围为, [?π2,π2] atan(x) 反正切函数,返回角度值范围为[?π2,π2] atan2(y,x) 计算y/x的

Asm Shader Reference --- Shader Model 1 part

ps部分 ps_1_1,ps_1_2,ps_1_3,ps_1_4 总览                   Instruction Set                               版本   指令槽 1_1 1_2 1_3 1_4   ps 版本号 0 x x x x   常数指令     1_1 1_2 1_3 1_4   def - ps 定义常数 0 x x x x   相位指令     1_1 1_2 1_3 1_4   phase - ps 在相位1与相位2之间转换

KCF目标跟踪方法分析与总结

KCF目标跟踪方法分析与总结 correlation filter Kernelized correlation filter tracking 读"J. F. Henriques, R. Caseiro, P. Martins, J. Batista, 'High-speed tracking with kernelized correlation filters'" 笔记 KCF是一种鉴别式追踪方法,这类方法一般都是在追踪过程中训练一个目标检测器,使用目标检测器去检测下一帧预测位置

Android高效计算——RenderScript(二)

3 RenderScript运行时层与反射层 3.1 RenderScript运行时层 RenderScript运行时层是指.rs代码运行时所在的层级.当对安卓项目进行编译的时候,.rs或者.rsh中编写的代码都会被llvm编译器编译成字节码.当该安卓应用在设备上运行的时候,这些字节码将会被设备上另外一个llvm编译(just-in-time)成机器码.这些机器码是针对该设备进行了优化的,且缓存在设备上,等到下次被应用的时候就不需要重新编译了,以加快速度.虽然RenderScript运行时层很像