# 天行健 君子当自强而不息

## 向量相加

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.

posted on 2008-03-12 10:58 lovedday 阅读(800) 评论(0)  编辑 收藏 引用

 只有注册用户登录后才能发表评论。

• 随笔 - 1360
• 文章 - 75
• 评论 - 520
• 引用 - 0

•