如何精确计算两个牵引点的距离? [英] How to calculate the distance of tow points precisely ?

查看:93
本文介绍了如何精确计算两个牵引点的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(float X1,float Y1,float X2,float Y2)
    {
        float dx = X1 - X2;
        float dy = Y1 - Y2;
        float sx = (float)cos( Y1 * 0.01745329252f);
        return ((float)sqrt(dx * dx * sx * sx + dy * dy) * 111195.0f);
    }



我找到了这样的实现。它的含义是什么?


I found a implementation like this. What is its meaning ?

推荐答案

我无法识别上述数学。计算两点距离的最简单方法是



I can't recognize the mentioned math. The simplest way to calculate two points distance is

float GetDistance(float X1,float Y1,float X2,float Y2)
    {
        float dx = X1 - X2;
        float dy = Y1 - Y2;
        return (float)sqrt(dx * dx + dy * dy);
    }





查看此两点之间的距离(给定其坐标) [ ^ ] for detail



Check this Distance between two points (given their coordinates)[^] for detail


这是球体上两点距离的近似公式。因子0.0174 ...是PI / 180.这告诉我们Y值是以度为单位提供的。乘以PI / 180将值转换为辐射。



dx * dx与sx * sx的乘积是经络在一起运行的补偿高纬度。



因子111195对应地球表面一度的距离。



总而言之:X和Y值是以度为单位的纬度和经度,公式以米为单位提供两点的距离。它只有在两点相对接近时才有效。
This is an approximation formula for the distance of two points on a sphere. The factor 0.0174... is PI / 180. That tells us that the Y values are provided in degrees. The multiplication with PI/180 converts the value to radiant.

The multiplication of dx*dx with sx*sx is the compensation for the fact that meridians run closer together in higher latitudes.

The factor 111195 corresponds to distance of one degree on the surface of the earth.

So in summary: The X und Y values are latitude and longitude in degrees and the formula delivers the distance of the two points in meters. It works only if the two points are relatively close together.


它只是实现了毕达哥拉斯定理 [ ^ ]



将这两个点视为直角三角形斜边的两端。
It's just implementing Pythagoras theorem[^]

Treat the two points as the two ends of the hypotenuse of a right angle triangle.


这篇关于如何精确计算两个牵引点的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆