Browse Source

pav-utils 공식 변경

ctrlDraw
이학준 1 year ago
parent
commit
e9d104b53f
  1. 125
      test/pav-utils.js

125
test/pav-utils.js

@ -1,21 +1,26 @@
// degree -> radian 변환 // degree -> radian 변환
const deg2rad = (deg) => { const deg2rad = deg => {
return deg * (Math.PI / 180); return deg * (Math.PI / 180);
} };
const rad2deg = (rad) => { const rad2deg = rad => {
return rad * (180 / Math.PI); return rad * (180 / Math.PI);
} };
// 좌표간 거리계산 // 좌표간 거리계산
const getDistanceFromCoordByMeter = (coord1, coord2) => { const getDistanceFromCoordByMeter = (coord1, coord2) => {
const R = 6371; // Radius of the earth in km const R = 6371; // Radius of the earth in km
const dLat = deg2rad(coord2[0] - coord1[0]); // deg2rad below const dLat = deg2rad(coord2[0] - coord1[0]); // deg2rad below
const dLon = deg2rad(coord2[1] - coord1[1]); const dLon = deg2rad(coord2[1] - coord1[1]);
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(deg2rad(coord1[0])) * Math.cos(deg2rad(coord2[0])) * Math.sin(dLon / 2) * Math.sin(dLon / 2); const a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(deg2rad(coord1[0])) *
Math.cos(deg2rad(coord2[0])) *
Math.sin(dLon / 2) *
Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
// var d = R * c; // Distance in km // var d = R * c; // Distance in km
const d = R * c * 1000; // Distance in m const d = R * c * 1000; // Distance in m
return d; return d;
} };
// 두 좌표사이 특정 거리만큼의 좌표 추출 // 두 좌표사이 특정 거리만큼의 좌표 추출
const getCoordsFormBetweenCoord = (coord1, coord2, dist) => { const getCoordsFormBetweenCoord = (coord1, coord2, dist) => {
// console.log('init ===> ', {coord1, coord2, dist}) // console.log('init ===> ', {coord1, coord2, dist})
@ -29,9 +34,9 @@ const getCoordsFormBetweenCoord = (coord1, coord2, dist) => {
const dy = coord2[1] - coord1[1]; const dy = coord2[1] - coord1[1];
const singY = dy < 0 ? -1 : 1; const singY = dy < 0 ? -1 : 1;
const m = dy / dx; const m = dy / dx;
const rad = Math.atan(m) const rad = Math.atan(m);
const currentTotalDist = Math.sqrt((dx ** 2) + (dy ** 2)) const currentTotalDist = Math.sqrt(dx ** 2 + dy ** 2);
const currentDivDist = (dist * currentTotalDist) / totalDist; const currentDivDist = (dist * currentTotalDist) / totalDist;
const div = Math.floor(currentTotalDist / currentDivDist); const div = Math.floor(currentTotalDist / currentDivDist);
@ -39,79 +44,83 @@ const getCoordsFormBetweenCoord = (coord1, coord2, dist) => {
const currentDist = currentDivDist * i; const currentDist = currentDivDist * i;
let x = coord1[0]; let x = coord1[0];
let y = coord1[1]; let y = coord1[1];
if (dx == 0) { if (dx === 0) {
y += currentDist * singY; y += currentDist * singY;
} else if (dy == 0) { } else if (dy === 0) {
x += currentDist * singX; x += currentDist * singX;
} else { } else {
x += Math.cos(rad) * currentDist; const angle = Math.atan2(dy, dx);
y += Math.sin(rad) * currentDist; x += Math.cos(angle) * currentDist;
y += Math.sin(angle) * currentDist;
} }
r.push([x, y]) r.push([x, y]);
} }
// 마지막 좌표 // 마지막 좌표
r.push(coord2) r.push(coord2);
return r; return r;
} };
const dumyData = { const dumyData = {
"authKey": "1cc2e08e-0c5c-43b2-8d4d-cddd3de558e3", authKey: '1cc2e08e-0c5c-43b2-8d4d-cddd3de558e3',
"terminalId": "SANDBOX-01", terminalId: 'SANDBOX-01',
"command": "SANDBOX", command: 'SANDBOX',
"body": [ body: [
{ {
"objectId": "JAL497", objectId: 'JAL497',
"lat": 37.52097, lat: 37.52097,
"lon": 126.6146, lon: 126.6146,
"elevType": "M", elevType: 'M',
"elev": 125.4, elev: 125.4,
"speedType": "KM", speedType: 'KM',
"speed": 145.8, speed: 145.8,
"heading": 227.94, heading: 227.94,
"terminalRcvDt": "20210629173145", terminalRcvDt: '20210629173145',
"betteryLevel": 91, betteryLevel: 91,
"betteryVoltage": 50, betteryVoltage: 50,
"dronStatus": "TAKEOFF", dronStatus: 'TAKEOFF',
"moveDistance": 120, moveDistance: 120,
"moveDistanceType": "M", moveDistanceType: 'M',
"sensorCo": 100.11, sensorCo: 100.11,
"sensorSo2": 200.22, sensorSo2: 200.22,
"sensorNo2": 300.33, sensorNo2: 300.33,
"sensorO3": 400.44, sensorO3: 400.44,
"sensorDust": 500.55 sensorDust: 500.55
} }
] ]
} };
module.exports = {getDistanceFromCoordByMeter, deg2rad, getCoordsFormBetweenCoord, dumyData}
module.exports = {
getDistanceFromCoordByMeter,
deg2rad,
getCoordsFormBetweenCoord,
dumyData
};
const test = () => { const test = () => {
const coord1 = [37.5210, 126.6082]; const coord1 = [37.521, 126.6082];
// const coord2 = [37.5210, 126.6057]; // x 절편 // const coord2 = [37.5210, 126.6057]; // x 절편
const coord2 = [37.5200, 126.6082]; // y 절편 const coord2 = [37.52, 126.6082]; // y 절편
// const coord2 = [37.5220, 126.6057]; // 일반 // const coord2 = [37.5220, 126.6057]; // 일반
const r = getCoordsFormBetweenCoord(coord1, coord2, 10) const r = getCoordsFormBetweenCoord(coord1, coord2, 10);
console.log(r) console.log(r);
for (let i = 1; i < r.length; i++) { for (let i = 1; i < r.length; i++) {
const dist = getDistanceFromCoordByMeter(r[i - 1], r[i]); const dist = getDistanceFromCoordByMeter(r[i - 1], r[i]);
console.log(dist) console.log(dist);
}
} }
};
// test(); // test();
const test2 = () => { const test2 = () => {
let m = 10.5 / 14 let m = 10.5 / 14;
console.log(3 / 4, 13.5 / 18, (13.5 - 3) / (18 - 4)) console.log(3 / 4, 13.5 / 18, (13.5 - 3) / (18 - 4));
let rad = Math.atan(m); let rad = Math.atan(m);
let tan = Math.tan(rad) let tan = Math.tan(rad);
let cos = Math.cos(rad) let cos = Math.cos(rad);
let sin = Math.sin(rad) let sin = Math.sin(rad);
console.log({rad, tan, cos, sin}) console.log({ rad, tan, cos, sin });
let x = Math.cos(rad) * 15 let x = Math.cos(rad) * 15;
let y = Math.sin(rad) * 15 let y = Math.sin(rad) * 15;
console.log({x, y}) console.log({ x, y });
};
}
// test2(); // test2();

Loading…
Cancel
Save