x,y 두 좌표의 직선거리 구하기

|
var dist; // 직선거리
var aXpos; // A지점 x좌표
var aYpos; // A지점 y좌표
var bXpos; // B지점 x좌표
var bYpos; // B지점 y좌표

// 두 지점의 거리를 계산 후 km로 변환

// Math.sqrt(9); // 3 // 제곱근 반환
// Math.pow(7, 2); // 49 // 제곱한 값
// / 1000 / 2.52; // km 변환
dist = Math.sqrt(Math.pow(aXpos - bXpos, 2) + Math.pow(aYpos - bYpos, 2)) / 1000 / 2.52;

// 소수점 변환
dist = Math.round(dist * 100) / 100;

'JavaScript' 카테고리의 다른 글

Reflow  (0) 2023.01.02
디바운스(Debounce), 스로틀(Throttle), 레이아웃 스레싱(Layout Thrashing)  (0) 2023.01.02
dotenv, express, axios  (0) 2021.12.31
var, let, const의 차이점은?  (0) 2021.11.30
Promise & Aysnc & Await  (0) 2021.10.18
And