-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.js
24 lines (20 loc) · 906 Bytes
/
vector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//var beacon = require('./beacon');
var calculate = function (sourceObj, destinationObj) {
var directionVector = {};
directionVector.x = destinationObj.x - sourceObj.x;
directionVector.y = destinationObj.y - sourceObj.y;
directionVector.magnitude = Math.sqrt((directionVector.x * directionVector.x) + (directionVector.y * directionVector.y) );
directionVector.x /= directionVector.magnitude;
directionVector.y /= directionVector.magnitude;
for(var i in directionVector){
directionVector[i] = Math.floor(directionVector[i] * 100)/100;
}
//console.dir(directionVector);
return directionVector;
};
var getDegree = function(vector){
return Math.atan2(vector.y,vector.x)*180/Math.PI;
}
module.exports.calculate = calculate;
module.exports.getDegree = getDegree;
//calculateDirection(new beacon('mac1','Paras', 3, 2), new beacon('mac2','Shashank', 9, 4));