mongodb 将公里转换为弧度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12180290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert kilometers to radians
提问by Jonathan Clark
I need to convert kilometers to radians. Is this correct formula? I need radians for nearsphere in MongoDB.
我需要将公里转换为弧度。这是正确的公式吗?我需要 MongoDB 中近球面的弧度。
If I need to convert 5 kilometers to radians I do this:
如果我需要将 5 公里转换为弧度,我会这样做:
5/6371
And I get this result (does it seem correct):
我得到了这个结果(它看起来是否正确):
0.000784806153
UPDATE
更新
This is not a math issue, I really need to know if I am doing the correct calculations from kilometers to radians to be able to do geospatial queries with MongoDB.
这不是数学问题,我真的需要知道我是否正在从公里到弧度进行正确的计算,以便能够使用 MongoDB 进行地理空间查询。
回答by Jason Sebring
Kilometers to radians or distance and radian conversion
公里到弧度或距离和弧度的转换
I arrived here, was confused, then I watched some Khan academy videos and it made more sense at that point and then I was able to actually look at equations from other sources to further educate myself.
我到了这里,很困惑,然后我看了一些可汗学院的视频,那时我觉得更有意义,然后我能够实际查看其他来源的方程来进一步教育自己。
Here's my train of thought.
这是我的思路。
I see a diagram about radians and I first think radius from a geolocation point which is wrong.
Instead, imagine the earth cut perfectly in half and just focus on one of the halves.
我看到一个关于弧度的图表,我首先认为从地理定位点开始的半径是错误的。
相反,想象地球被完美地切成两半,只关注其中的一半。
- Now face that half toward you and look at the math diagram.
- 现在将那一半面向您并查看数学图表。
- Think of the math diagram as showing from the center of the earth measuring the edge of the earth based on the arc length, after all the earth is curved so any measurement will be curved on the surface of the earth.
- Radians are like degrees in a circle and the arc length is literally the distance between A and B in the math diagram.
- To you, its a straight line on a bird's eye view, but really it's just a curve in 3d space along the edge of the earth.
- Eureka! A lightbulb went on in my head.
- 把数学图想象成从地球的中心根据弧长测量地球的边缘,毕竟地球是弯曲的,所以任何测量都会在地球表面弯曲。
- 弧度就像圆中的度数,弧长实际上是数学图中 A 和 B 之间的距离。
- 对你来说,它是鸟瞰图上的一条直线,但实际上它只是沿着地球边缘的 3d 空间中的一条曲线。
- 尤里卡!一个灯泡在我的脑海里亮了起来。
distance = earth radius * radians
distance = earth radius * radians
Thus with some very easy algebra...
因此,通过一些非常简单的代数......
radians = distance / earth radius
radians = distance / earth radius
kmradians = distance in km / 6371
公里radians = distance in km / 6371
miradians = distance in mi / 3959
米radians = distance in mi / 3959
Sometimes thinking it through is fun.
有时仔细想想很有趣。
Double-check this... https://www.translatorscafe.com/unit-converter/en/length/7-89/kilometer-Earth%E2%80%99s%20equatorial%20radius/
Now in regards to Mongo v3.2 specifically using mongoose in node.js
现在关于 Mongo v3.2 专门在 node.js 中使用 mongoose
Despite my best efforts, mongo would not behave correctly as documented for a $geoNear query on a 2d index. never worked
尽管我尽了最大的努力,但 mongo 不会像 2d 索引上的 $geoNear 查询所记录的那样正确运行。从来没有工作过
let aggregate = [
{
$geoNear: {
near: { type: 'Point', coordinates: lonLatArray },
spherical: false,
distanceField: 'dist.calculated',
includeLocs: 'dist.location',
maxDistance: distanceInMeters / (6371 * 1000),
query: {
mode: 'nearme',
fcmToken: { $exists: true }
}
}
},
{ $skip: skip },
{ $limit: LIMIT }
];
However, when I changed to a 2dsphere index, it worked perfectly.
但是,当我更改为 2dsphere 索引时,它运行良好。
let aggregate = [
{
$geoNear: {
near: { type: 'Point', coordinates: lonLatArray },
spherical: true,
distanceField: 'dist.calculated',
includeLocs: 'dist.location',
maxDistance: distanceInMeters,
query: {
mode: 'nearme',
fcmToken: { $exists: true }
}
}
},
{ $skip: skip },
{ $limit: LIMIT }
];
But education never seems like a waste of time.
但教育似乎从来都不是浪费时间。
回答by Sagi Forbes
You are correct. In spherical geometry you divide the distance with the radius of the sphere. Mind that you should keep the units. So if you calculate the sphere radius in kilometers then you should use distance in kilometer. If you use miles then you should use Earth radius in miles (approx: 3,963.2).
你是对的。在球面几何中,您将距离除以球体的半径。请注意,您应该保留这些单位。因此,如果您以公里为单位计算球体半径,那么您应该使用以公里为单位的距离。如果您使用英里,那么您应该使用以英里为单位的地球半径(约:3,963.2)。
回答by Sagi Forbes
To convert:
转换:
distance to radians: divide the distance by the radius of the sphere (e.g. the Earth) in the same units as the distance measurement.
radians to distance: multiply the radian measure by the radius of the sphere (e.g. the Earth) in the units system that you want to convert the distance to.
到弧度的距离:以与距离测量相同的单位将距离除以球体(例如地球)的半径。
弧度到距离:在您要将距离转换为的单位系统中,将弧度测量值乘以球体(例如地球)的半径。
for Example: if you want to convert 5 miles in radians, then we need to divide the distance(5 miles) by the radius of the sphere(also in miles), which is 3959. then 5/3959 is 0.0012629451...
例如:如果您想以弧度转换 5 英里,那么我们需要将距离(5 英里)除以球体的半径(也以英里为单位),即 3959。那么 5/3959 是 0.0012629451...
Thanks
谢谢
回答by Irshad Khan
The equatorial radius of the Earth is approximately 3,963.2 miles or 6,378.1 kilometers.
地球的赤道半径约为3,963.2 英里或6,378.1 公里。
Note : 1 KM = 0.621371 Mile
注意:1 公里 = 0.621371 英里
Here is some simple formulas for calculation :
下面是一些简单的计算公式:
100 KM to Miles :(100 * 0.621371)
100 KM to radiant :100 / 6378.1
100 Miles to radiant :100 / 3963.2
100 公里到英里:(100 * 0.621371)
100 公里到辐射点:100 / 6378.1
100 英里到 radiant :100 / 3963.2
So if you have data in Kilometersthen you must use (100 / 6378.1)and for Milesdata you can use (100 / 3963.2)
因此,如果您有以公里为单位的数据,那么您必须使用(100 / 6378.1)而对于里程数据,您可以使用 (100 / 3963.2)