-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from adedolapoadegboye/maps-and-stats
Maps and stats
- Loading branch information
Showing
12 changed files
with
246 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { useEffect, useRef } from "react"; | ||
import Chart from "chart.js/auto"; | ||
|
||
const LineChart = (data) => { | ||
const chartRef = useRef(null); | ||
|
||
console.log("3D errors: ", data); | ||
|
||
useEffect(() => { | ||
const ctx = chartRef.current.getContext("2d"); | ||
|
||
// Destroy the previous chart instance before creating a new one | ||
if (chartRef.current.chart) { | ||
chartRef.current.chart.destroy(); | ||
} | ||
|
||
// Create the new chart instance | ||
chartRef.current.chart = new Chart(ctx, { | ||
type: "line", | ||
data: { | ||
labels: data.altPlotData.map((_, i) => i), | ||
datasets: [ | ||
{ | ||
label: "3D Fix Error (m)", | ||
data: data.altPlotData.map((value, index) => ({ | ||
x: index, | ||
y: value, | ||
})), | ||
borderColor: "rgba(175, 92, 92, 1)", | ||
backgroundColor: "rgba(255, 255, 255, 1)", | ||
color: "rgba(75, 92, 192, 1)", | ||
tension: 0.5, | ||
}, | ||
], | ||
}, | ||
options: { | ||
scales: { | ||
x: { | ||
beginAtZero: true, | ||
}, | ||
y: { | ||
beginAtZero: true, | ||
}, | ||
}, | ||
animations: { | ||
tension: { | ||
duration: 1000, | ||
easing: "linear", | ||
from: 0.1, | ||
to: 0, | ||
loop: true, | ||
}, | ||
}, | ||
elements: { | ||
line: { | ||
borderWidth: 1, | ||
borderJoinStyle: "bevel", | ||
}, | ||
}, | ||
plugins: { | ||
title: { | ||
display: true, | ||
text: "Plot of 3D Fix Error with respect to Reference 3D Coordinates", | ||
}, | ||
}, | ||
}, | ||
}); | ||
}, [data]); | ||
|
||
return <canvas ref={chartRef} />; | ||
}; | ||
|
||
export default LineChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,40 @@ | ||
import LatLonEllipsoidal from "geodesy/latlon-ellipsoidal"; | ||
|
||
/** | ||
* Calculates the 3D Cartesian distance between two geographical points using ellipsoidal coordinates. | ||
* @param {number} lat1 - Latitude of the first point. | ||
* @param {number} lon1 - Longitude of the first point. | ||
* @param {number} alt1 - Altitude of the first point. | ||
* @param {number} lat2 - Latitude of the second point. | ||
* @param {number} lon2 - Longitude of the second point. | ||
* @param {number} alt2 - Altitude of the second point. | ||
* @returns {string} - The Cartesian distance between the two points in meters, formatted to two decimal places. | ||
*/ | ||
const calc3DDistance = (lat1, lon1, alt1, lat2, lon2, alt2) => { | ||
const earthRadius = 6371e3; // Earth's radius in meters | ||
const latDiff = (lat2 - lat1) * (Math.PI / 180); | ||
const lonDiff = (lon2 - lon1) * (Math.PI / 180); | ||
const altDiff = alt2 - alt1; | ||
const a = | ||
Math.sin(latDiff / 2) * Math.sin(latDiff / 2) + | ||
Math.cos(lat1 * (Math.PI / 180)) * | ||
Math.cos(lat2 * (Math.PI / 180)) * | ||
Math.sin(lonDiff / 2) * | ||
Math.sin(lonDiff / 2); | ||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | ||
const distance = Math.sqrt( | ||
Math.pow(earthRadius * c, 2) + Math.pow(altDiff, 2) | ||
); // 3D distance | ||
return distance; | ||
try { | ||
// Convert geographical points to Cartesian coordinates | ||
const refPoint = new LatLonEllipsoidal(lat1, lon1, alt1).toCartesian(); | ||
const testPoint = new LatLonEllipsoidal(lat2, lon2, alt2).toCartesian(); | ||
|
||
// Log the Cartesian points for debugging | ||
// console.log(refPoint, testPoint); | ||
|
||
// Calculate the Cartesian distance between the two points | ||
const distance = Math.sqrt( | ||
(refPoint.x - testPoint.x) ** 2 + | ||
(refPoint.y - testPoint.y) ** 2 + | ||
(refPoint.z - testPoint.z) ** 2 | ||
); | ||
|
||
// console.log(distance); | ||
|
||
// Return the distance formatted to two decimal places | ||
return distance.toFixed(2); | ||
} catch (error) { | ||
// Log any errors that occur during the distance calculation | ||
console.error("Error occurred while calculating 3D distance:", error); | ||
return ""; | ||
} | ||
}; | ||
|
||
export default calc3DDistance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.