轉自:http://www.cppblog.com/lovedday/archive/2007/04/26/22890.html
向量的點積:
假設向量u(ux, uy)和v(vx, vy),u和v之間的夾角為α,從三角形的邊角關系等式出發,可作出如下簡單推導:
|u - v||u - v| = |u||u| + |v||v| - 2|u||v|cosα
===>
(ux - vx)2 + (uy - vy)2 = ux2 + uy2 +vx2+vy2- 2|u||v|cosα
===>
-2uxvx - 2uyvy = -2|u||v|cosα
===>
cosα = (uxvx + uyvy) / (|u||v|)
這樣,就可以根據向量u和v的坐標值計算出它們之間的夾角。
定義u和v的點積運算: u . v = (uxvx + uyvy),
上面的cosα可簡寫成: cosα = u . v / (|u||v|)
當u . v &#61; 0時&#xff08;即uxvx &#43; uyvy &#61; 0&#xff09;&#xff0c;向量u和v垂直&#xff1b;當u . v > 0時&#xff0c;u和v之間的夾角為銳角&#xff1b;當u . v <0時&#xff0c;u和v之間的夾角為鈍角。
可以將運算從2維推廣到3維。
向量的叉積&#xff1a;
假設存在向量u(ux, uy, uz), v(vx, vy, vz), 求同時垂直於向量u, v的向量w(wx, wy, wz).
因為w與u垂直&#xff0c;同時w與v垂直&#xff0c;所以w . u &#61; 0, w . v &#61; 0; 即
uxwx &#43; uywy &#43; uzwz &#61; 0;
vxwx &#43; vywy &#43; vzwz &#61; 0;
分別削去方程組的wy和wx變量的系數&#xff0c;得到如下兩個等價方程式&#xff1a;
(uxvy - uyvx)wx &#61; (uyvz - uzvy)wz
(uxvy - uyvx)wy &#61; (uzvx - uxvz)wz
於是向量w的一般解形式為&#xff1a;
w &#61; (wx, wy, wz) &#61; ((uyvz - uzvy)wz / (uxvy - uyvx), (uzvx - uxvz)wz / (uxvy - uyvx), wz)
&#61; (wz / (uxvy - uyvx) * (uyvz - uzvy, uzvx - uxvz, uxvy - uyvx))
因為&#xff1a;
ux(uyvz - uzvy) &#43; uy(uzvx - uxvz) &#43; uz(uxvy - uyvx)
&#61; uxuyvz - uxuzvy &#43; uyuzvx - uyuxvz &#43; uzuxvy - uzuyvx
&#61; (uxuyvz - uyuxvz) &#43; (uyuzvx - uzuyvx) &#43; (uzuxvy - uxuzvy)
&#61; 0 &#43; 0 &#43; 0 &#61; 0
vx(uyvz - uzvy) &#43; vy(uzvx - uxvz) &#43; vz(uxvy - uyvx)
&#61; vxuyvz - vxuzvy &#43; vyuzvx - vyuxvz &#43; vzuxvy - vzuyvx
&#61; (vxuyvz - vzuyvx) &#43; (vyuzvx - vxuzvy) &#43; (vzuxvy - vyuxvz)
&#61; 0 &#43; 0 &#43; 0 &#61; 0
由此可知&#xff0c;向量(uyvz - uzvy, uzvx - uxvz, uxvy - uyvx)是同時垂直於向量u和v的。
為此&#xff0c;定義向量u &#61; (ux, uy, uz)和向量 v &#61; (vx, vy, vz)的叉積運算為&#xff1a;u x v &#61; (uyvz - uzvy, uzvx - uxvz, uxvy - uyvx)
上面計算的結果可簡單概括為&#xff1a;向量u x v垂直於向量u和v。
根據叉積的定義&#xff0c;沿x坐標軸的向量i &#61; (1, 0, 0)和沿y坐標軸的向量j &#61; (0, 1, 0)的叉積為&#xff1a;
i x j &#61; (1, 0, 0) x (0, 1, 0) &#61; (0 * 0 - 0 * 1, 0 * 0 - 1 * 0, 1 * 1 - 0 * 0) &#61; (0, 0, 1) &#61; k
同理可計算j x k:
j x k &#61; (0, 1, 0) x (0, 0, 1) &#61; (1 * 1 - 0 * 0, 0 * 0 - 0 * 1, 0 * 0 - 0 * 0) &#61; (1, 0, 0) &#61; i
以及k x i:
k x i &#61; (0, 0, 1) x (1, 0, 0) &#61; (0 * 0 - 1 * 0, 1 * 1 - 0 * 0, 0 * 0 - 0 * 0) &#61; (0, 1, 0) &#61; j
由叉積的定義&#xff0c;可知&#xff1a;
v x u &#61; (vyuz - vzuy, vzux - vxuz, vxuy - vyux) &#61; - (u x v)