如何找到其他两个点之间的地理点 [英] How to find a geographic point between two other points

查看:136
本文介绍了如何找到其他两个点之间的地理点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的应用程序,我必须找到在谷歌地图上的点只知道它位于其他2点和时间(毫秒)时的坐标已经陷入之间的位置。

在我的code,假设A和B点给出X作为找点,我:

  1. 计算A和B之间的距离

  2. 立足时候,我发现了速度(微度/ MS),从旅行到B

  3. 我发现从点A和点X的距离(使用时间和速度)

  4. 使用类似三角形的规则,我计算纬度和从点A点X的经度

这个工作流程带来了错误的地图上,所以,往往在X标记是不是A和B标记之间的线路。

我怎样才能使它更好地工作?它是与地球的球形出了问题?

感谢您所有。

下面是code:

  INT AX = oldPoint.getLatitude();
    INT AY = oldPoint.getLongitude();

    INT BX = currentPoint.getLatitude();
    通过= currentPoint.getLongitude INT();

    长期处于= oldPoint.getDataRilevamento(); //获取第一时间点
    长BT = currentPoint.getDataRilevamento(); //获取时间第二点
    朗XT = x.getDate(); //点​​时间去寻找

    INT C1 = BX-AX;
    INT C2 =用,唉;
    双HYP =的Math.sqrt(Math.pow(C1,2)+ Math.pow(C2,2));

    双VEL = HYP /(BT-AT);

    双POS = VEL *(XT  -  AT);

    INT POSX =(INT)((POS * 1)/ HYP);
    INT束花=(INT)((POS * C2)/​​ HYP);

    x.setLatitude(AX + POSX); //设置X的纬度
    x.setLongitude(AY +铭文); //设置X的经度
 

解决方案

您的问题,可以通过以下步骤来解决。

  • 计算从点A和B的距离(使用半正矢公式,这是很好的足够在这里,或更复杂的 Vincenty公式)。使用 公式正确,Android的microdegrees,这是什么getLatitude 和getLongitude回报,必须转换为弧度, 使用公式是这样的:

     双弧度= Math.toRadians((双)microdegrees / 1000000);
     

  • 计算从点A和B的方位(方向)(用公式 在同一页上)。这将是从毕达哥拉斯式,因为不同 地球是圆的,不是平的。

  • 然后你可以选择一个新的距离,计算出X点给出 A点和轴承在previous步骤(见或者目标点一定距离,并从起始点轴承在同一页上,或的 Vincenty的 直接式)。
  • 转换所产生的点弧度到使用这个公式microdegrees:

      INT microdegrees =(INT)(Math.toDegrees(弧度)* 1000000);
     

全部放在一起,我们有以下的功能,这是我在公共领域的地方:

 公共静态INT [] getIntermediatePoint(
        INT startLatMicroDeg,
        INT startLonMicroDeg,
        INT endLatMicroDeg,
        INT endLonMicroDeg,
        双T //多少使用的距离,从0到1
    ){
        //转换microdegrees为弧度
        双alatRad = Math.toRadians((双)startLatMicroDeg / 1000000);
        双alonRad = Math.toRadians((双)startLonMicroDeg / 1000000);
        双blatRad = Math.toRadians((双)endLatMicroDeg / 1000000);
        双blonRad = Math.toRadians((双)endLonMicroDeg / 1000000);
        //计算距离,经度
        双dlon = blonRad-alonRad;
        //计算通用变量
        双alatRadSin = Math.sin(alatRad);
        双blatRadSin = Math.sin(blatRad);
        双alatRadCos = Math.cos(alatRad);
        双blatRadCos = Math.cos(blatRad);
        双dlonCos = Math.cos(dlon);
        //查找从远处到B
        双距离= Math.acos(alatRadSin * blatRadSin +
                                  alatRadCos * blatRadCos *
                                  dlonCos);
        //查找从A轴承到B
        双轴承= Math.atan2(
            Math.sin(dlon)* blatRadCos,
            alatRadCos * blatRadSin  - 
            alatRadSin * blatRadCos * dlonCos);
        //寻找新的起点
        双angularDistance =距离* T;
        双angDistSin = Math.sin(angularDistance);
        双angDistCos = Math.cos(angularDistance);
        双xlatRad = Math.asin(alatRadSin * angDistCos +
                                   alatRadCos * angDistSin * Math.cos(轴承));
        双xlonRad = alonRad + Math.atan2(
            Math.sin(轴承)* angDistSin * alatRadCos,
            angDistCos-alatRadSin * Math.sin(xlatRad));
        //转换弧度microdegrees
        INT XLAT =(INT)Math.round(Math.toDegrees(xlatRad)* 1000000);
        INT xlon =(INT)Math.round(Math.toDegrees(xlonRad)* 1000000);
        如果(XLAT> 90000000)XLAT = 90000000;
        如果(XLAT< -90000000)XLAT = -90000000;
        而(xlon> 1.8)xlon- = 3.6;
        而(xlon< =  -  1.8)xlon + = 3.6;
        返回新INT [] {XLAT,xlon};
    }
 

下面是如何使用它:

  INT AX = oldPoint.getLatitude();
INT AY = oldPoint.getLongitude();

INT BX = currentPoint.getLatitude();
通过= currentPoint.getLongitude INT();

长期处于= oldPoint.getDataRilevamento(); //获取第一时间点
长BT = currentPoint.getDataRilevamento(); //获取时间第二点
朗XT = x.getDate(); //点​​时间去寻找

//找到相对时间从A点到B点
双T =(BT == AT)? 0:((双)(XT-AT))/((双)(BT-AT));
//寻找新点给出的起点和终点和相对时间
INT [] XPOS = getIntermediatePoint(AX,AY,BX,BY,T);
x.setLatitude(XPOS [0]); //设置X的纬度
x.setLongitude(XPOS [1]); //设置X的经度
 

For my application I have to find the position of a point on Google map knowing only that it's located between 2 other points and the time (in ms) when the coordinates have been caught.

In my code, assumed A and B as the points given and X as the point to find, I:

  1. calculate distance between A and B

  2. basing on time I found out the speed (in micro degrees /ms) to travel from A to B

  3. I found the distance from point A and point X (using time and speed)

  4. using similar triangle's rule, I calculate latitude and longitude of point X from point A

This workflow bring out errors on the map, so, often the X marker is not on the line between A and B markers.

How can I make it works better? Is it a problem with the sphericity of the globe?

Thank you to all.

Here is the code:

    int ax = oldPoint.getLatitude();
    int ay = oldPoint.getLongitude();

    int bx = currentPoint.getLatitude();
    int by = currentPoint.getLongitude();

    long at = oldPoint.getDataRilevamento(); //get time first point
    long bt = currentPoint.getDataRilevamento(); // get time second point
    long xt = x.getDate(); // time of point to find

    int c1 = bx-ax;
    int c2 = by-ay;
    double hyp =  Math.sqrt(Math.pow(c1, 2) + Math.pow(c2, 2));

    double vel = hyp / (bt-at);

    double pos = vel*(xt - at);

    int posx = (int)((pos*c1)/hyp);
    int posy = (int)((pos*c2)/hyp);

    x.setLatitude(ax+posx); //set the latitude of X
    x.setLongitude(ay+posy); // set the longitude of X

解决方案

Your problem can be solved by taking the following steps.

  • Calculate the distance from points A and B (use the Haversine formula, which is good enough here, or the more complicated Vincenty formula). To use the formula correctly, Android's microdegrees, which is what getLatitude and getLongitude return, must be converted to radians, using a formula like this:

     double radians = Math.toRadians((double)microdegrees/1000000);
    

  • Calculate the bearing (direction) from points A and B (use the formula on the same page). This will be different from the Pythagorean formula because the earth is round, not flat.

  • Then you can choose a new distance and calculate point X given point A and the bearing found in the previous step (see either "Destination point given distance and bearing from start point" on the same page, or Vincenty's direct formula).
  • Convert the radians from the generated point into microdegrees using this formula:

     int microdegrees = (int)(Math.toDegrees(radians)*1000000);
    

Putting it all together, we have the following function, which I place in the public domain:

    public static int[] getIntermediatePoint(
        int startLatMicroDeg,
        int startLonMicroDeg,
        int endLatMicroDeg,
        int endLonMicroDeg,
        double t // How much of the distance to use, from 0 through 1
    ){
        // Convert microdegrees to radians
        double alatRad=Math.toRadians((double)startLatMicroDeg/1000000);
        double alonRad=Math.toRadians((double)startLonMicroDeg/1000000);
        double blatRad=Math.toRadians((double)endLatMicroDeg/1000000);
        double blonRad=Math.toRadians((double)endLonMicroDeg/1000000);
        // Calculate distance in longitude
        double dlon=blonRad-alonRad;
        // Calculate common variables
        double alatRadSin=Math.sin(alatRad);
        double blatRadSin=Math.sin(blatRad);
        double alatRadCos=Math.cos(alatRad);
        double blatRadCos=Math.cos(blatRad);
        double dlonCos=Math.cos(dlon);
        // Find distance from A to B
        double distance=Math.acos(alatRadSin*blatRadSin +
                                  alatRadCos*blatRadCos *
                                  dlonCos);
        // Find bearing from A to B
        double bearing=Math.atan2(
            Math.sin(dlon) * blatRadCos,
            alatRadCos*blatRadSin -
            alatRadSin*blatRadCos*dlonCos);
        // Find new point
        double angularDistance=distance*t;
        double angDistSin=Math.sin(angularDistance);
        double angDistCos=Math.cos(angularDistance);
        double xlatRad = Math.asin( alatRadSin*angDistCos +
                                   alatRadCos*angDistSin*Math.cos(bearing) );
        double xlonRad = alonRad + Math.atan2(
            Math.sin(bearing)*angDistSin*alatRadCos,
            angDistCos-alatRadSin*Math.sin(xlatRad));
        // Convert radians to microdegrees
        int xlat=(int)Math.round(Math.toDegrees(xlatRad)*1000000);
        int xlon=(int)Math.round(Math.toDegrees(xlonRad)*1000000);
        if(xlat>90000000)xlat=90000000;
        if(xlat<-90000000)xlat=-90000000;
        while(xlon>180000000)xlon-=360000000;
        while(xlon<=-180000000)xlon+=360000000;
        return new int[]{xlat,xlon};
    }

And here's how it's used:

int ax = oldPoint.getLatitude();
int ay = oldPoint.getLongitude();

int bx = currentPoint.getLatitude();
int by = currentPoint.getLongitude();

long at = oldPoint.getDataRilevamento(); //get time first point
long bt = currentPoint.getDataRilevamento(); // get time second point
long xt = x.getDate(); // time of point to find

// Find relative time from point A to point B
double t=(bt==at) ? 0 : ((double)(xt-at))/((double)(bt-at));
// Find new point given the start and end points and the relative time
int[] xpos=getIntermediatePoint(ax,ay,bx,by,t);
x.setLatitude(xpos[0]); //set the latitude of X
x.setLongitude(xpos[1]); // set the longitude of X

这篇关于如何找到其他两个点之间的地理点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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