生成给定距离的坐标,距中心的角度

2023-03-17前端开发问题
7

本文介绍了生成给定距离的坐标,距中心的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在地图 [x1,y1] 中有一个给定的中心.从那个中心我画一个半径为 1 英里的圆.我需要在圆周围再生成 8 个点,各个点到中心的距离应该是 1 英里,所以它们在圆的边界上.我确实知道得到 x2, y2 的公式,但问题是它不适用于地球地图,因为它不是一个完美的球体.

I have a given center in the map [x1,y1]. From that center I am drawing a circle with a 1 mile radius. I need to generate 8 more points around the circle, the distance between the individual points to center should be 1 mile, so they are on the circle bounds. I do know the formulas to get x2, y2 but the problem is it doesn't apply to earth's map since it isn't a perfect sphere.

我尝试过使用 this,但没有成功.

I've tried using this, but with no luck.

谁能指出我的某个地方,或者我弄错了?

Could anyone point me somewhere or maybe I got this wrong ?

已解决!

所以仔细阅读整个 Movable Type Scripts 我发现了这个(为了我的使用稍微修改了):

So reading carefully throughout Movable Type Scripts I found this (slightly modified for my use):

   let getPoint = (distance, bearing, center) => {

    let δ = Number(distance) / 6371e3; 
    let θ = Number(bearing).toRadians();

    let φ1 = center[0].toRadians();
    let λ1 = center[1].toRadians();

    let sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1);
    let sinδ = Math.sin(δ), cosδ = Math.cos(δ);
    let sinθ = Math.sin(θ), cosθ = Math.cos(θ);

    let sinφ2 = sinφ1*cosδ + cosφ1*sinδ*cosθ;
    let φ2 = Math.asin(sinφ2);
    let y = sinθ * sinδ * cosφ1;
    let x = cosδ - sinφ1 * sinφ2;
    let λ2 = λ1 + Math.atan2(y, x);

    return [φ2.toDegrees(), (λ2.toDegrees()+540)%360-180]; 
};

它确实解决了我的问题.

It did solved my problem.

推荐答案

您正在尝试解决所谓的 第一个(或直接的)大地测量问题.知道这个名字会让你的研究更容易.

You are trying to solve what is known as the first (or direct) geodetic problem. Knowing this name will make your research easier.

正如如何使用 Leaflet" 和 "在给定起始坐标、方位角和距离的情况下查找目的地坐标",您在 javascript 中解决此问题的主要选项是 cheap-ruler 用于小(ish)区域和 greographiclib 适合远距离.

As pointed out by the answers to "How to draw polyline perpendicular to another polyline using Leaflet" and "Find destination coordinates given starting coodinates, bearing, and distance", your main options to approach this problem in javascript are cheap-ruler for small(ish) areas and greographiclib for large distances.

cheap-ruler 往往非常快但不准确,geographiclib 往往较慢但非常准确.

cheap-ruler tends to be very fast but inaccurate, and geographiclib tends to be slower but very accurate.

您可能会发现其他实现,每个都有自己的妥协.大地测量学很难,所以 没有一种真正的方法"来计算距离或方位角.

You might find other implementations, each with its own compromises. Geodesy is hard, so there is no "one true way" to calculate distances or azimuths.

这篇关于生成给定距离的坐标,距中心的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui laydate日期时间范围,时间默认设定为23:59:59
在Layui中,如果你想设置日期时间选择器(datetime)的默认结束时间为当天的23:59:59,你可以使用如下代码: laydate.render({ elem: '#test10' ,type: 'datetime' ,range: true ,max: '{:date("Y-m-d 23:59:59")}' ,ready: function(date){ $(".layui-laydat...
2024-10-24 前端开发问题
279

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

JavaScript(js)文件字符串中丢失"\"斜线的解决方法
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转...
2024-10-17 前端开发问题
437

layui中table列表 增加属性 edit="date",不生效怎么办?
如果你想在 layui 的 table 列表中增加 edit=date 属性但不生效,可能是以下问题导致的: 1. 缺少日期组件的初始化 如果想在表格中使用日期组件,需要在页面中引入 layui 的日期组件,并初始化: script type="text/javascript" src="/layui/layui.js"/scrip...
2024-06-11 前端开发问题
455