一般来说dot2 个向量的乘积等于cosine两个向量之间的角度乘以两个向量的大小(长度)。
dot( A, B ) == | A | * | B | * cos( angle_A_B )
由此可见,dot2 个单位向量的乘积等于cosine两个向量之间的角度,因为单位向量的长度为 1。
uA = normalize( A )
uB = normalize( B )
cos( angle_A_B ) == dot( uA, uB )
In *three.js* all the calculations can be done by the operations of a [`THREE.Vector3`][2]:
var a = new THREE.Vector3( ... );
var b = new THREE.Vector3( ... );
a.normalize();
b.normalize();
var cosAB = a.dot( b );
var angle_in_radians = Math.acos( cosAB );
As mentioned in the comment below, in *three.js* there is an operation **`.angleTo`**, which simplifies the things a lot:
var angle_in_radians = a.angleTo(b);
If you have 4 points `Pa`, `Pb`, `Pc`, `Pd`, which define 2 lines from `Pa` to `Pb` and form `Pc` to `Pd`, then the 2 vectors can be calculated as follows:
var Pa = new THREE.Vector3( ... );
var Pb = new THREE.Vector3( ... );
var Pc = new THREE.Vector3( ... );
var Pd = new THREE.Vector3( ... );
var a = new THREE.Vector3();
a.copy( Pb ).sub( Pa );
var b = new THREE.Vector3();
a.copy( Pd ).sub( Pc );