From dd7107b1a9bacea380f79fbac2f2bf3fe103203b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 Jan 2021 17:48:41 +0100 Subject: [PATCH] changed formula for calculating earth distances --- static/scripts/accChart.js | 27 +++++++++++++-------------- static/scripts/chartfull.js | 4 ++-- static/scripts/refull.js | 1 + 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/static/scripts/accChart.js b/static/scripts/accChart.js index a789f90..2e4557d 100644 --- a/static/scripts/accChart.js +++ b/static/scripts/accChart.js @@ -75,10 +75,11 @@ function addDistances(tcpDataList, serialDataList){ for(let i = 0; i < tcpCoords.length; i++){ let distance = distanceInMetersBetweenEarthCoordinates - (serialCoords[i][1],serialCoords[i][0],tcpCoords[i][1],tcpCoords[i][0]) + (serialCoords[i][0],serialCoords[i][1],tcpCoords[i][0],tcpCoords[i][1]) distances.push(distance) } + console.log("tcp coords: " + tcpCoords) console.log("distances: " + distances) accChart.data.labels = tcpTimes @@ -87,21 +88,19 @@ function addDistances(tcpDataList, serialDataList){ accChart.update() } -function degreesToRadians(degrees) { - return degrees * Math.PI / 180; -} +//https://www.movable-type.co.uk/scripts/latlong.html +function distanceInMetersBetweenEarthCoordinates(long1, lat1, long2, lat2) { + var earthRadiusM = 6371000 -function distanceInMetersBetweenEarthCoordinates(lat1, lon1, lat2, lon2) { - var earthRadiusKm = 6371 + var phi1 = lat1 * Math.PI / 180 + var phi2 = lat2 * Math.PI / 180 - var dLat = degreesToRadians(lat2-lat1) - var dLon = degreesToRadians(lon2-lon1) + var dlat = (lat2-lat1) * Math.PI / 180 + var dlong = (long2 - long1) * Math.PI / 180 - lat1 = degreesToRadians(lat1) - lat2 = degreesToRadians(lat2) - - var a = Math.sin(dLat/2) * Math.sin(dLat/2) + - Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2) + var a = Math.sin(dlat/2) * Math.sin(dlat/2) + + Math.cos(phi1) * Math.cos(phi2) * + Math.sin(dlong/2) * Math.sin(dlong/2) var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)) - return (earthRadiusKm * c) * 1000 + return earthRadiusM * c } \ No newline at end of file diff --git a/static/scripts/chartfull.js b/static/scripts/chartfull.js index 4ba426c..ab04059 100644 --- a/static/scripts/chartfull.js +++ b/static/scripts/chartfull.js @@ -11,7 +11,7 @@ var speedChart = new Chart(ctx, { borderColor: 'rgba(214, 69, 65, 1)', borderWidth: 1, fill: false, - pointRadius: 1, + pointRadius: 0.5, lineTension: 0.5, data: [] }, @@ -21,7 +21,7 @@ var speedChart = new Chart(ctx, { borderColor: 'rgba(30, 139, 195, 1)', borderWidth: 1, fill: false, - pointRadius: 1, + pointRadius: 0.5, lineTension: 0.5, data: [] }] diff --git a/static/scripts/refull.js b/static/scripts/refull.js index b4af836..0d32a2f 100644 --- a/static/scripts/refull.js +++ b/static/scripts/refull.js @@ -55,6 +55,7 @@ function findSerialDataIndex(tcpdataList, serialdataList) { indexes.push(index) } }) + console.log("indexes: " + indexes) } window.addEventListener("load", function(evt) {