I am calculating the position of a user using triangulation.
If I use array values it outputs NaN NaN
, but if I hardcode the values it works fine as expected and outputs
Grabbing the values from an array:
var beaconCoordinates = [[10,20], [200,300], [50,500]];
//get values from array
var aX = parseInt(beaconCoordinates[0,0]);
var aY = parseInt(beaconCoordinates[0,1]);
var bX = parseInt(beaconCoordinates[1,0]);
var bY = parseInt(beaconCoordinates[1,1]);
var cX = parseInt(beaconCoordinates[2,0]);
var cY = parseInt(beaconCoordinates[2,1]);
Hardcoding the values:
var aX = 2;
var aY = 4;
var bX = 5.5;
var bY = 13;
var cX = 11.5;
var cY = 2;
Here is the rest of the code:
var dA = 5.7;
var dB = 6.8;
var dC = 6.4;
//trilateration / triangulation formula
var S = parseInt((Math.pow(cX, 2.) - Math.pow(bX, 2.) + Math.pow(cY, 2.) - Math.pow(bY, 2.) + Math.pow(dB, 2.) - Math.pow(dC, 2.)) / 2.0);
var T = parseInt((Math.pow(aX, 2.) - Math.pow(bX, 2.) + Math.pow(aY, 2.) - Math.pow(bY, 2.) + Math.pow(dB, 2.) - Math.pow(dA, 2.)) / 2.0);
var y = ((T * (bX - cX)) - (S * (bX - aX))) / (((aY - bY) * (bX - cX)) - ((cY - bY) * (bX - aX)));
var x = ((y * (aY - bY)) - T) / (bX - aX);
//x and y position of user
console.log(x,y);
Can someone explain this to me please? I am so confused.