需要一个基于方位,地理位置,距离和角度的扇区 [英] Need a sector based on bearing, geopoint, distance and angle

查看:118
本文介绍了需要一个基于方位,地理位置,距离和角度的扇区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.我试图以轴承(lat,lon),速度的方式编写 JAVA 代码,我需要获取形成一个扇区的所有点(如图所示( x1,y1),(x2,y2)以及在方位角给定的方向上形成 Arc 的点的列表(我对方位角的了解非常有限).

I have a problem. I am trying to write a JAVA code were in given bearing, (lat,lon) , speed I need to get all points which form a sector (like in the diagram (x1,y1) , (x2,y2) and list of points which form an Arc in the direction which is given by bearing (I have very limited knowledge on bearing).

我的第一件事是基于带有硬编码的距离和角度的方向来实现扇形. (即固定值表示d = 5kmangle = 60 deg.)

My first thing is to achieve sector based on the direction with hard-coded distance and angle. (i.e fixed values say d = 5km and angle = 60 deg.)

下一步基于我想要计算d = func(speed)angle = func(speed)的距离dangle的速度,但这将在以后.

Next Step is based on the speed I want distance d and angle to be calculated like d = func(speed) and angle = func(speed) but this will be later.

由于方位度是给定的,所以我不知道如何计算方向. 我在想什么,如果我能够将轴承转换为同一方向上的单位矢量.那么我认为我们可以吸引这个领域.

Since bearing is given in terms of degree I don't know how to calculate direction. What i was thinking like If i am able to convert the bearing to a unit vector on the same direction. then i think we can draw the sector.

如果我的理论/解释不正确,请纠正我.请我需要帮助的人....

Correct me if i am wrong in my theory/explanation. Please I need help guys.....

我正在研究一个小项目,当时我在手机上浏览Google地图,可以得到(lat,lon) - current position of userbearing - in the direction in which I am headedspeed - what speed i am travelling.

I am working on a small project were in while tracking through google maps on phone I can get (lat,lon) - current position of user, bearing - in the direction in which I am headed and speed - what speed i am travelling.

距离和角度与速度的关系:

如果我以更高的速度行驶,则d应该更大,而angle应该更少(电弧会更窄)

If i am travelling with more speed the d should be more and angle should be less (arc will be more narrower)

如果我以较低的速度行驶,则d应该更小,而角度应该更大(弧会更宽)

If i am travelling with less speed then d should be less and `angle should be more (arc will be wider)

如果我静止不动,速度为0,那么我将在当前的(lat,lon)周围画一个圆并找到我周围的兴趣点.

If i am stationary the speed is 0 , then i will draw a circle around my current (lat,lon) and find my POI around me.

一旦找到该扇区,我将使用弹性搜索(它提供一些func(),例如附近搜索和多边形搜索)来跟踪我沿途的所有兴趣点

Once i get this sector i will use Elastic search ( It provide some func() like nearby search and polygon search) to get all the Point Of Interest along my way while i am tracking

最终,当我开车时,我想向用户展示他沿途获得的POI是什么. (我们不知道用户的目的地)

Ultimately, while i am driving i want to show user what are the POI he gets along his way. ( we don't know user's destination)

public class Test {

    // N is the number of points on the arc
    // e.g. const int N = 15;
    private static final int N = 10;

    public static void main(String[] args){

        final double deg2Rad = Math.PI / 180.0; //degree to Radian
        final double Rad2deg = 180.0 / Math.PI; //Radian to degree
        double bearing =  90; //direction
        double angle = 60; //sector angle   
        double R = 6371.0; //Radius of earth

        double lat = 12.926428 * deg2Rad;
        double lon = 77.677705 * deg2Rad;

        double d = 5; 

        Geopoint[] array = new Geopoint[N];

        double A = bearing - angle * 0.5;    // starting angle / bearing
        double dA = angle / (double)(N - 1); // angle step between adjacent points

        /* convert lat, lon to cartesian here! */
        double  x = R * Math.cos(lat) * Math.cos(lon);
        System.out.println(x);
        double  y = R * Math.cos(lat) * Math.sin(lon);
        System.out.println(y);
        double  z = R * Math.sin(lat);
        System.out.println(z);


        for (int i = 0; i < N; i++, A += dA)
        {
          double c = Math.cos(A * deg2Rad), 
                 s = Math.sin(A * deg2Rad);

          System.out.println( "C : " + c);
          System.out.println( "S : " + s);

          double x1 = (x + d * c) ;

          double y1 = (y + d * s) ;

          //Convert back to Geopoint
          lat = Math.asin(z / R) * Rad2deg;
          lon = Math.atan2(y1, x1) * Rad2deg;

          array[i] = new Geopoint(lon , lat );
        }

        // return array 
        for ( int i = 0; i < array.length; i++ )
            System.out.println("points," + i + "," + array[i]); 
    }

}

对于上面的代码,我的输出低于输出

For the above code i am getting below output

输出

points,0,{ "lon":130.56759538189806, "lat":20.62976857973366, "geoadress":"null" }
points,1,{ "lon":130.56753333442796, "lat":20.62976857973366, "geoadress":"null" }
points,2,{ "lon":130.56747144031073, "lat":20.62976857973366, "geoadress":"null" }
points,3,{ "lon":130.56740969980146, "lat":20.62976857973366, "geoadress":"null" }
points,4,{ "lon":130.5673481131545, "lat":20.62976857973366, "geoadress":"null" }
points,5,{ "lon":130.5672866806237, "lat":20.62976857973366, "geoadress":"null" }
points,6,{ "lon":130.5672254024622, "lat":20.62976857973366, "geoadress":"null" }
points,7,{ "lon":130.5671642789225, "lat":20.62976857973366, "geoadress":"null" }
points,8,{ "lon":130.5671033102564, "lat":20.62976857973366, "geoadress":"null" }
points,9,{ "lon":130.56704249671517, "lat":20.62976857973366, "geoadress":"null" }

但是此输出是错误的.我不知道我要去哪里错了.

But this output is wrong. I don't know where i am going wrong.

latlon更改为弧度后,这是我的结果.

After changing lat and lon to radians this is my result.

points,0,12.926428,77.677705
points,1,12.926428,77.6917252889466
points,2,12.926428,77.68652371253442
points,3,12.926428,77.68120259629767
points,4,12.926428,77.67583406750569
points,5,12.926428,77.67049090073982
points,6,12.926428,77.6652455243131
points,7,12.926428,77.6601690315512
points,8,12.926428,77.65533021080672
points,9,12.926428,77.65079460778875
points,10,12.926428,77.64662363329005

自从我将这个lat = Math.asin(z / R) * Rad2deg;转换为笛卡尔坐标系以来,我得到的所有经度都是相同的.我不知道该怎么解决.

Since I am dong this lat = Math.asin(z / R) * Rad2deg; to convert from cartesian i am getting all lat same. I don't know how to solve this.

基于iant代码

我已经计算了到弧上每个点的距离btw (lat,lon).它应导致相同的距离. iant检查结果,距离是否有微小变化.

I have computed the distance btw (lat,lon) to every point on the arc. It should result in same distance. iant check the result there is slight variation in the distance.

type,id,lat,lon points,1,12.926428,77.677705 Distance in mtrs : 0.0 points,2,12.92657150782396,77.67778916970093 Distance in mtrs : 9.971162660481445 points,3,12.926578367173896,77.67778862221844 Distance in mtrs : 9.971162660481445 points,4,12.926585180719618,77.67778804926368 Distance in mtrs : 9.971162660481445 points,5,12.926591946385617,77.67778745101116 Distance in mtrs : 9.97070966260917 points,6,12.92659866211097,77.67778682764309 Distance in mtrs : 9.971162660481445 points,7,12.926605325849975,77.6777861793494 Distance in mtrs : 9.971162660481445 points,8,12.926611935572756,77.67778550632754 Distance in mtrs : 9.97070966260917 points,9,12.926618489265902,77.67778480878253 Distance in mtrs : 9.97070966260917 points,10,12.92662498493306,77.67778408692685 Distance in mtrs : 9.971162660481445 points,11,12.926631420595564,77.67778334098041 Distance in mtrs : 9.97070966260917 points,12,12.926637794293018,77.67778257117044 Distance in mtrs : 9.97070966260917 points,13,12.926644104083913,77.67778177773138 Distance in mtrs : 9.97070966260917 points,14,12.9266503480462,77.67778096090498 Distance in mtrs : 9.97070966260917 points,15,12.926656524277885,77.67778012094006 Distance in mtrs : 9.970256644154967 points,16,12.926662630897608,77.67777925809244 Distance in mtrs : 9.970256644154967 points,17,12.926668666045215,77.67777837262499 Distance in mtrs : 9.97070966260917 points,18,12.926674627882324,77.67777746480742 Distance in mtrs : 9.97070966260917 points,19,12.92668051459289,77.67777653491626 Distance in mtrs : 9.970256644154967 points,20,12.926686324383741,77.6777755832348 Distance in mtrs : 9.970256644154967 points,21,12.926692055485155,77.67777461005294 Distance in mtrs : 9.970256644154967 points,22,12.926428,77.677705 Distance in mtrs : 0.0

type,id,lat,lon points,1,12.926428,77.677705 Distance in mtrs : 0.0 points,2,12.92657150782396,77.67778916970093 Distance in mtrs : 9.971162660481445 points,3,12.926578367173896,77.67778862221844 Distance in mtrs : 9.971162660481445 points,4,12.926585180719618,77.67778804926368 Distance in mtrs : 9.971162660481445 points,5,12.926591946385617,77.67778745101116 Distance in mtrs : 9.97070966260917 points,6,12.92659866211097,77.67778682764309 Distance in mtrs : 9.971162660481445 points,7,12.926605325849975,77.6777861793494 Distance in mtrs : 9.971162660481445 points,8,12.926611935572756,77.67778550632754 Distance in mtrs : 9.97070966260917 points,9,12.926618489265902,77.67778480878253 Distance in mtrs : 9.97070966260917 points,10,12.92662498493306,77.67778408692685 Distance in mtrs : 9.971162660481445 points,11,12.926631420595564,77.67778334098041 Distance in mtrs : 9.97070966260917 points,12,12.926637794293018,77.67778257117044 Distance in mtrs : 9.97070966260917 points,13,12.926644104083913,77.67778177773138 Distance in mtrs : 9.97070966260917 points,14,12.9266503480462,77.67778096090498 Distance in mtrs : 9.97070966260917 points,15,12.926656524277885,77.67778012094006 Distance in mtrs : 9.970256644154967 points,16,12.926662630897608,77.67777925809244 Distance in mtrs : 9.970256644154967 points,17,12.926668666045215,77.67777837262499 Distance in mtrs : 9.97070966260917 points,18,12.926674627882324,77.67777746480742 Distance in mtrs : 9.97070966260917 points,19,12.92668051459289,77.67777653491626 Distance in mtrs : 9.970256644154967 points,20,12.926686324383741,77.6777755832348 Distance in mtrs : 9.970256644154967 points,21,12.926692055485155,77.67777461005294 Distance in mtrs : 9.970256644154967 points,22,12.926428,77.677705 Distance in mtrs : 0.0

public static double distanceOf(Geopoint a, Geopoint b) {
    if (a.isValid() && b.isValid()) {
      double distFactor = Math.acos(Math.sin(Math.toRadians(a.getLat())) * Math.sin(Math.toRadians(b.getLat()))
          + Math.cos(Math.toRadians(a.getLat())) * Math.cos(Math.toRadians(b.getLat()))
              * Math.cos(Math.toRadians(b.getLon()) - Math.toRadians(a.getLon())));
      return 6378.388 * distFactor;
    }
    return -1;
  }

推荐答案

我回答了 GeoTools a>提供创建满足这些要求的弧所需的所有工具- GeodeticCalculator 可让您指定起点,方位角和距离,并将返回目标点.使用此方法可以轻松创建任意距离和宽度的弧.

I answered a very similar question earlier this week - GeoTools provides all the tools you need to create an arc which fulfils these requirements - GeodeticCalculator allows you to specify a start point, azimuth and distance and will return you the destination point. Using this it is easy to create an arc of any distance and width.

完整的代码是此处,它解决了另一个问题.您需要根据需要参数化宽度(可能是弧中的步数).

The full code is here that solved the other problem. You would need to parameterize the width (and may be the number of steps in the arc) for your needs.

编辑

这确实会产生弧形:

POLYGON((12.926428 77.677705,12.926571507823445 77.67778916970063,12.926578367173352 77.67778862221815,12.926585180719048 77.67778804926338,12.926591946385022 77.67778745101086,12.926598662110349 77.67778682764279,12.926605325849323 77.6777861793491,12.926611935572092 77.67778550632724,12.926618489265206 77.67778480878223,12.926624984932337 77.67778408692658,12.926631420594818 77.67778334098014,12.926637794292239 77.67778257117014,12.926644104083113 77.67778177773111,12.926650348045378 77.67778096090471,12.926656524277035 77.67778012093977 ,12.926662630896734 77.67777925809216、12.926668666044314 77.67777837262472、12.926674627881402 77.67777746480715、12.926680514591945 77.67777653491602、12.92668632438278 77.67777558323456、12.926692055484166 77.67777461005268、12.926428 77.677705))

POLYGON ((12.926428 77.677705, 12.926571507823445 77.67778916970063, 12.926578367173352 77.67778862221815, 12.926585180719048 77.67778804926338, 12.926591946385022 77.67778745101086, 12.926598662110349 77.67778682764279, 12.926605325849323 77.6777861793491, 12.926611935572092 77.67778550632724, 12.926618489265206 77.67778480878223, 12.926624984932337 77.67778408692658, 12.926631420594818 77.67778334098014, 12.926637794292239 77.67778257117014, 12.926644104083113 77.67778177773111, 12.926650348045378 77.67778096090471, 12.926656524277035 77.67778012093977, 12.926662630896734 77.67777925809216, 12.926668666044314 77.67777837262472, 12.926674627881402 77.67777746480715, 12.926680514591945 77.67777653491602, 12.92668632438278 77.67777558323456, 12.926692055484166 77.67777461005268, 12.926428 77.677705))

这仅取决于您如何看待-由于地球的曲率,偏远的北方(您在斯瓦尔巴特群岛工作?)看起来很奇怪,因此在像Plate Carree(WGS84)这样的平面投影中,它不会看起来像弧线.

It just depends on how you look at it - that far north (you are working in Svalbard?) things look weird due to the curvature of the earth, so in a flat projection like Plate Carree (WGS84) it doesn't look like an arc.

但是在等距投影(旨在使距离看起来正确)中,它是弧形.

But in an equidistant projection (designed to keep distances looking correct) it is an arc.

当然,如果您在印度,那么EPSG:4326看起来还不错.

Of course if you are in India then it looks fine in EPSG:4326.

这篇关于需要一个基于方位,地理位置,距离和角度的扇区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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