D3D编程必备的数学知识(2)

Wesley13
• 阅读 574

向量相加

我们能够通过分别把两个向量的各个分量相加得到向量之和,注意在相加之前必须保证它们有相同的维数。

u + v = (_ux_+ vx, _uy_+ vy, _uz_+ vz)

图5显示的是几何学上的向量相加。

D3D编程必备的数学知识(2)

两个向量相加的代码,我们使用重载的加法操作符:

D3DXVECTOR3 u(2.0f, 0.0f, 1.0f);

D3DXVECTOR3 v(0.0f, -1.0f, 5.0f);

// (2.0 + 0.0,  0.0 + (-1.0),  1.0 + 5.0)

D3DXVECTOR3 sum = u + v; // = (2.0f, -1.0f, 6.0f)

向量相减

和加法类似,通过分别把两个向量的各个分量相减得到向量之差。再次重声两个向量必须是相同维数。

u-v = u + (-v) = (ux - vx, uy - vy, uz - vz)

图6显示的是几何学上的向量相减。

D3D编程必备的数学知识(2)

两个向量相减的代码,我们使用重载的减法操作符:

D3DXVECTOR3 u(2.0f, 0.0f, 1.0f);

D3DXVECTOR3 v(0.0f, -1.0f, 5.0f);

D3DXVECTOR3 difference = u - v; // = (2.0f, 1.0f, -4.0f)

图6显示,向量减法得到一个从v向量终点到u向量终点的向量。假如我们解释uv的分量,我们能用向量相减找到从一个点到另一个点的向量。这是非常方便的操作,因为我们常常想找到从一个点到另一个点的方向向量。

标量与向量的乘积

我们能用一个标量与向量相乘,就象名字暗示的一样,向量按比例变化。这种运算不会改变向量的方向,除非标量是负数,这种情况向量方向相反。

ku = (kux, kuy, kuz)

D3DXVECTOR3类提供了向量与标量乘法的操作符。

D3DXVECTOR3 u(1.0f, 1.0f, -1.0f);

D3DXVECTOR3 scaledVec = u * 10.0f; // = (10.0f, 10.0f, -10.0f)

点积

数学上定义点积是两个向量的乘积。按下面等式计算:

u.v = uxvx + uyvy + uzvz = s

The above formula does not present an obvious geometric meaning. Using the law of cosines, we can find the relationship u.v = ∥u∥∥v∥ cosθ , which says that the dot product between two vectors is the cosine of the angle between them scaled by the vectors' magnitudes. Thus, if both u and v are unit vectors, then u.v is the cosine of the angle between them.

Some useful properties of the dot product:

  • If u.v = 0, then uv.

  • If u.v > 0, then the angle θ, between the two vectors is less than 90 degrees.

  • If u.v < 0, then the angle θ, between the two vectors is greater than 90 degrees.

Note 

The ⊥ symbol means "orthogonal," which is synonymous with the term "perpendicular."

We use the following D3DX function to compute the dot product between two vectors:

FLOAT D3DXVec3Dot(          // Returns the result.    CONST D3DXVECTOR3* pV1, // Left sided operand.    CONST D3DXVECTOR3* pV2  // Right sided operand.);D3DXVECTOR3 u(1.0f, -1.0f, 0.0f);D3DXVECTOR3 v(3.0f,  2.0f, 1.0f);//   1.0*3.0 + -1.0*2.0 + 0.0*1.0// = 3.0 + -2.0float dot = D3DXVec3Dot( &u, &v ); // = 1.0

叉积

第二种乘法在向量数学中叫叉积。不象点积,结果值是一个标量,叉积的结果值是另一个向量。通过把两个向量uv相乘得到另一的向量p,向量p垂直于uv。也就是说向量p垂直于u并且垂直于u

The cross product is computed like so:

p = u×v = [(uyvz - uzvy), (uzvx - uxvz), (uxvy - uyvx)]

In component form:

px = (uyvz - uzvy)

py = (uzvx - uxvz)

_p_z = (uxvy - uyvx)

Example: Find j = k × i = (0, 0, 1) × (1, 0, 0) and verify that j is orthogonal to both k and i.

Solution:

jx =(0(0)-1(0)) = 0

jy =(1(1)-0(0) = 1

_j_z=(0(0)-0(1) = 0

So, j = (0, 1, 0). Recall from the section titled "Dot Products" that if u.v = 0, then uv Since j.k = 0 and j.i = 0, we know j is orthogonal to both k and i.

We use the following D3DX function to compute the cross product between two vectors:

D3DXVECTOR3 *D3DXVec3Cross(    D3DXVECTOR3* pOut,      // Result.   CONST D3DXVECTOR3* pV1,  // Left sided operand.   CONST D3DXVECTOR3* pV2   // Right sided operand.);

It is obvious from Figure 7 that the vector -p is also mutually orthogonal to both u and v. The order in which we perform the cross product determines whether we get p or -p as a result. In other words, u × v = -(v × u). This shows that the cross product is not commutative. You can determine the vector returned by the cross product by the left hand thumb rule. (We use a left hand rule because we are using a left-handed coordinate system. We would switch to the right hand rule if we were using a right-handed coordinate system.) If you curve the fingers of your left hand in the direction of the first vector toward the second vector, your thumb points in the direction of the returned vector.

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Karen110 Karen110
2年前
人工智能数学基础-线性代数1:向量的定义及向量加减法
一、向量1.1、向量定义向量也称为欧几里得向量、几何向量、矢量,指具有大小(magnitude)和方向的量。它可以形象化地表示为带箭头的线段。箭头所指:代表向量的方向;线段长度:代表向量的大小。与向量对应的量叫做数量(物理学中称标量),数量(或标量)只有大小,没有方向。1.在物理学和工程学中,几何向量更常被称为矢量。2.一般印刷用黑体的小写
Karen110 Karen110
2年前
人工智能数学基础-线性代数3:线性空间、线性相关及基
一、向量空间(线性空间)及基域线性空间是在考察了大量的数学对象(如几何学与物理学中的向量,代数学中的n元向量、矩阵、多项式,分析学中的函数等)的本质属性后抽象出来的数学概念。1.1、详细定义向量空间也称线性空间,设V是一个非空集合,P是一个数域。若:1.在V中定义了一种运算,称为加法,即对V中任意两个元素α与β都按某一法则对应于V内惟一确定的一个元素α
Stella981 Stella981
2年前
HQS——Half Quadratic Splitting半二次方分裂
变量分裂法变量分裂法(VariableSplitting),解决目标函数是两个函数之和的优化问题。1)其中g是n维向量到d维向量的一个映射。!(https://oscimg.oschina.net/oscnet/1bd6780b6de6fa186751390f5fae00783cd.png)变量分裂将上式变为:!(h
Stella981 Stella981
2年前
Android蓝牙连接汽车OBD设备
//设备连接public class BluetoothConnect implements Runnable {    private static final UUID CONNECT_UUID  UUID.fromString("0000110100001000800000805F9B34FB");
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这