28 lines
604 B
JavaScript
28 lines
604 B
JavaScript
module.exports = angle
|
|
|
|
var fromValues = require('./fromValues')
|
|
var normalize = require('./normalize')
|
|
var dot = require('./dot')
|
|
|
|
/**
|
|
* Get the angle between two 3D vectors
|
|
* @param {vec3} a The first operand
|
|
* @param {vec3} b The second operand
|
|
* @returns {Number} The angle in radians
|
|
*/
|
|
function angle(a, b) {
|
|
var tempA = fromValues(a[0], a[1], a[2])
|
|
var tempB = fromValues(b[0], b[1], b[2])
|
|
|
|
normalize(tempA, tempA)
|
|
normalize(tempB, tempB)
|
|
|
|
var cosine = dot(tempA, tempB)
|
|
|
|
if(cosine > 1.0){
|
|
return 0
|
|
} else {
|
|
return Math.acos(cosine)
|
|
}
|
|
}
|