## D3D编程必备的数学知识（2） 转

rise-worlds

#### 向量相加

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

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)

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)

#### 标量与向量的乘积

``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``

#### 叉积

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)

pz = (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

jz=(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.

### rise-worlds

yuer150
2011/04/26
366
3

yuer150
2011/05/02
1K
0

loving_forever_
2016/07/28
0
0

2018/11/08
0
0

2016/04/25
399
0

C++随笔（四）Nuget打包

Pulsar-V
59分钟前
2
0

naughty

3
0
Python3的日期和时间

python 中处理日期时间数据通常使用datetime和time库 因为这两个库中的一些功能有些重复，所以，首先我们来比较一下这两个库的区别，这可以帮助我们在适当的情况下时候合适的库。 在Python文...

2
0

3
0

davidwbnu

4
0