当前位置:网站首页>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轴正方向的夹角
边栏推荐
猜你喜欢

Smart Tips for Frida Scripting in Kali Environment

(3) 字符串

(7) 浅学 “爬虫” 过程 (概念+练习)
![[league/climate] A robust command-line function manipulation library](/img/ce/39114b1c74af649223db97e5b0e29c.png)
[league/climate] A robust command-line function manipulation library

MOMENTUM: 2 vulnhub walkthrough

hackmyvm: may walkthrough

Phpstudy installs Thinkphp6 (problem + solution)

Phonebook

hackmyvm-hopper walkthrough

一个网络安全小白鼠的学习之路—nmap高级用法之脚本使用
随机推荐
c语言用栈实现计算中缀表达式
JS objects, functions and scopes
一个网络安全小白鼠的学习之路—nmap高级用法之脚本使用
Kali install IDEA
[league/flysystem] An elegant and highly supported file operation interface
(8) requests, os, sys, re, _thread
What will be new in PHP8.2?
uniapp | Compilation error after updating with npm update
CTF入门笔记之SQL注入
vim编辑模式
攻防世界—MISC 新手区1-12
VIKINGS: 1 vulnhub walkthrough
Alfa: 1 vulnhub walkthrough
When PHP initiates Alipay payment, the order information is garbled and solved
CSRF(跨站请求伪造)
hackmyvm-bunny walkthrough
Baidu positioning js API
14. JS Statements and Comments, Variables and Data Types
Smart Tips for Frida Scripting in Kali Environment
Phonebook