解释脚本语言 计算两个向量的夹角度数。

A face always has 3 vertices.
--一个面总是有3 个点构成
Each pair of vertices define one of the 3 edges of the face, and at the same time can be seen as a vector
 --每一对点 看看做是连着3 条变 还有就是一个面。同时 很多时候我们是吧他看做一个向量。
 every vertex is already a vector
--每个点都能看做是一个向量。
 and the edge vector connecting two vertices can be calculated easily by subtracting the two vertex positions
---一条边是由两个向量组成 k可以很容易的利用减法 算出两个点的位置。
Let's call the 3 vertices A, B and C.
--让我们看看有3 个向量 ABC (图在本子上画 )


If you want to calculate the angle at vertex A, you will need the two vectors which start from vertex A and point at B and C respectively
---如果想知道A 的角度,你必须要用到两个向量 点AB 点AC

These two vectors would be expressed as

V1 = B-A

V2 = C-A
---------这两个向量可以表示为
The image shows point A with coordinates [0,0,0], point B with coordinates [2,0,1] and point C with coordinates [-1,0,2].
--这张图片上 显示的是点 A 的坐标 点B 的坐标 点C 的坐标。
Now you have two vectors, but the vector dot product requires normalized vectors to return usable results.
---现在你有两个向量,向量的点乘 要用到标准化向量。
A normalized vector has the same direction as the original vector, but the length of 1.0.
---标准化向量是一些有方向的向量,但是长度都是为1 的。
You can calclulate the normalized vector by using the normalize method on the vectors V1 and V2:
---你能 把向量进行 标准化用 normalize 的方法
N1 = normalize V1
N1 = normalize V1
In the case of V1 = [2,0,1], N1 = normalize V1 returns [0.894427,0,0.447214] because length V1 = 2.23607
---说明原向量 标准化向量 还有就是向量的长度 原、
 and the normalized vector is calculated by dividing the X, Y and Z coordinates by the length, in this case [2/2.23607, 0/2.23607, 1/2.23607].
---标准化向量就是用 分量的值分别/ 他的长度 (这个说明了算法)
N2 = normalize V2 returns [-0.447214,0,0.894427] because the length of the vector [-1,0,2] is also 2.23607, and the normalized vector is calculated as [-1/2.23607, 0/2.23607, 2/2.23607].
----N2的算法 同N1时一样的。
 as explained in the How do I find the angle between two vectors?,
---下面来解释怎么找到向量的角度。
 we need to calculate the acos of the dot product of these normalized vectors
 ---我们打算用反余弦 还有点乘 还有那些标准化的向量。
 acos is the reverse operations of cos
  --反余弦是 余弦的反向操作 就是倒数    --------cos 是返回的比值 acos 是返回的角度。
 returning the angle whose cos is equal to the operand (in other words, if X = cos Alpha, then Alpha = acos X).
---返回的是角度。cos 返回的角度 就是这个角度  换句话说就是这个一个运算操作 if cos 20 = x then acos x =20 就是
 ---求一个度数的表现。
 Angle = acos (dot N1 N2) ---出来是一却值角度 而cos 则表示说明用关系说明角度。
 The Angle will range between 0 (when the two vectors are parallel) and 180 degrees (when the two vectors are pointing in opposite directions).
 --这个角度总是在0 到180 度之间不等。
 
 
 
 acos (dot [2/2.23607, 0/2.23607, 1/2.23607] [-1/2.23607, 0/2.23607, 2/2.23607])
 ---可以得出角度为 90 度。
 

posted on 2011-09-05 14:32  盖天00  阅读(2698)  评论(0编辑  收藏  举报

导航