当前位置:网站首页>How to determine the direction based on two coordinate points on the map
How to determine the direction based on two coordinate points on the map
2022-08-02 04:02:00 【dumb papa】
There are two points on the map,黄鹤楼(A点)and the Park Management Office of the Yellow Crane Tower(B点),怎么确定B点在AIn what direction?.
In the geographic coordinate system, the latitude can be regarded as the rectangular coordinate systemY轴,Positive direction from south to North-East;Think of longitude as in Cartesian coordinatesX轴,Positive direction from west to east.Although the earth is a ball,But zoom in,The radian of the sphere does not affect our view of it as a plane Cartesian coordinate system.
以BThe point is the origin to establish a plane Cartesian coordinate system,求B点在AThe problem of the direction of the point becomes the problem of finding the angle,Just calculate the line segmentAB和X轴或者Y轴的夹角,就可以描述A和Bdirection between.
Calculated according to the coordinates of the latitude and longitudeABthe distance between two points andA、Bdifference in longitude between two points、纬度差值,计算出cos值或者sin值,然后利用JavaScript的Math对象的acos或者asin(反三角函数)to find the radian value corresponding to the included angle,Then converts arc Angle value.
JavaScriptIn the arc and Angle for the transformation of the relationship:angle multiplied by 0.017453293 (或2PI/360)to convert to radians,PI为Math对象中的常量.
具体实现
function calculateAngle(points) {
var lastPrePoi = points[0];
var lastPoi = points[1];
if (lastPoi.lng == lastPrePoi.lng) {
if (lastPoi.lat == lastPrePoi.lat) {
// 横坐标相同、纵坐标相同
return;
} else {
// 横坐标相同、The ordinate is different
return lastPoi.lat > lastPrePoi.lat ? 0 : 180;
}
} else {
if (lastPoi.lat == lastPrePoi.lat) {
// The abscissa is different、纵坐标相同
return lastPoi.lng > lastPrePoi.lng ? 90 : -90;
} else {
let first_side_length = lastPoi.lng - lastPrePoi.lng;
let second_side_length = lastPoi.lat - lastPrePoi.lat;
let third_side_length = Math.sqrt(Math.pow(first_side_length, 2) + Math.pow(second_side_length, 2));
let cosine_value = first_side_length / third_side_length;
let radian_value = Math.acos(cosine_value);
let angle_value = radian_value * 180 / Math.PI;
if (angle_value < 90) {
return second_side_length > 0 ? 90 - angle_value : 90 + angle_value;
} else {
return second_side_length > 0 ? 90 - angle_value : angle_value - 270;
}
}
}
}
注:The angle value in this method isYThe positive direction of the axis is the reference,角度为AB线段与Y轴正方向的夹角
边栏推荐
猜你喜欢

MOMENTUM: 2 vulnhub walkthrough

hackmyvm-random walkthrough

(1) the print () function, escape character, binary and character encoding, variables, data type, the input () function, operator

ES6 iterator explanation example

命令执行漏洞

(3) string

Orasi: 1 vulnhub walkthrough

PHP8.2 version release administrator and release plan

Smart Tips for Frida Scripting in Kali Environment

SQL classification, DQL (Data Query Language), and corresponding SQL query statement demonstration
随机推荐
vim edit mode
Scrapy crawler encounters redirection 301/302 problem solution
v-bind usage: class dynamic binding object array style style and function method
Stable and easy-to-use short connection generation platform, supporting API batch generation
New usage of string variable parsing in PHP8.2
一个网络安全小白鼠的学习之路——nmap的基本使用
PHP8.2 version release administrator and release plan
Command Execution Vulnerability
Praying: 1 vulnhub walkthrough
[symfony/finder]最好用的文件操作库
16. JS events, string and operator
Offensive and defensive world - novice MISC area 1-12
Alibaba Cloud MySQL 5.7 installation and some major problems (total)
CTF入门笔记之ping
Pycharm打包项目为exe文件
PHP image compression to specified size
(3) Thinkphp6 database
Xiaoyao multi-open emulator ADB driver connection
MySql Advanced -- Constraints
VIKINGS: 1 vulnhub walkthrough