graph.ts 840 B

1234567891011121314151617181920212223242526272829
  1. import { Pos, Pos3D } from "@/sdk";
  2. export const calcLatLonsDis = (point1: Pos, point2: Pos) => {
  3. const lat1 = point1.y;
  4. const lat2 = point2.y;
  5. const lng1 = point1.x;
  6. const lng2 = point2.x;
  7. var radLat1 = (lat1 * Math.PI) / 180.0;
  8. var radLat2 = (lat2 * Math.PI) / 180.0;
  9. var a = radLat1 - radLat2;
  10. var b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
  11. var s =
  12. 2 *
  13. Math.asin(
  14. Math.sqrt(
  15. Math.pow(Math.sin(a / 2), 2) +
  16. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)
  17. )
  18. );
  19. s = s * 6378.137; // EARTH_RADIUS;
  20. return s * 1000;
  21. };
  22. export const calcLintDis = (point1: Pos | Pos3D, point2: Pos | Pos3D) => {
  23. const xf = Math.pow(point1.x - point2.x, 2);
  24. const yf = Math.pow(point1.y - point2.y, 2);
  25. let sqDis = xf + yf;
  26. return Math.sqrt(sqDis);
  27. };