Utilizing this script to calculate the distance between two sets of xyz coordinates.
function getDistance(x0, y0, z0, x1, y1, z1){
let deltaX = x1 - x0;
let deltaY = y1 - y0;
let deltaZ = z1 - z0;
let distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
return distance;
}
Given the following coordinates:
arr1 = [1524519105.309092, 575131.076859, 4141688.619666, -14.086608]
arr2 = [1524519105.310092, 575131.082497, 4141688.628375, -14.086852]
Where index 0 is the timestamp and the next 3 numbers represent xyz values. The objective is to compare these coordinates and determine speed. Here's the current progress:
let x2 = arr2[1] // Array 2 x
let y2 = arr2[2] // Array 2 y
let z2 = arr2[3] // Array 2 z
let x1 = arr1[1] // Array 1 x
let y1 = arr1[2] // Array 1 y
let z1 = arr1[3] // Array 1 z
var c = getDistance(x1, y1, z1, x2, y2, z2)
var timeDifference = arr1[0] - arr2[0] // difference in time
var speed = Math.round(c / timeDifference);
The formula is not yielding the correct speed at times; occasionally resulting in -0, indicating a possible error in the time difference calculation. Ultimately, aiming to obtain the speed in meters per second.