根据地图上的坐标构造三角形

发布于 2024-09-04 02:34:36 字数 2093 浏览 1 评论 0原文

我正在构建一个基于地理定位的应用程序,并且我正在尝试找出一种方法,让我的应用程序在用户面向给定位置的方向(特定的长/纬度坐标)时实现。我已经计算好了数学,我只需构建三角形即可。

//更新

所以我已经弄清楚了这一点...

下面是一种方法,它接受长/纬度值并尝试计算一个三角形,找到 700 米外的一个点以及其左侧和右侧的一个点。然后它会使用这些来构造三角形。它计算出正确的经度,但纬度最终位于东非海岸附近的某个地方。 (我在爱尔兰!)。

public void drawtri(double currlng,double currlat, double bearing){

    bearing = (bearing < 0 ? -bearing : bearing);

    System.out.println("RUNNING THE DRAW TRIANGLE METHOD!!!!!");
    System.out.println("CURRENT LNG" + currlng);
    System.out.println("CURRENT LAT" + currlat);
    System.out.println("CURRENT BEARING" + bearing);

    //Find point X(x,y)
    double distance = 0.7; //700 meters.
    double R = 6371.0; //The radius of the earth.
    //Finding X's y value.

    Math.toRadians(currlng);
    Math.toRadians(currlat);
    Math.toRadians(bearing);

    distance = distance/R;
    Global.Alat = Math.asin(Math.sin(currlat)*Math.cos(distance)+ 
            Math.cos(currlat)*Math.sin(distance)*Math.cos(bearing));
    System.out.println("CURRENT ALAT!!: " + Global.Alat);
    //Finding X's x value.
    Global.Alng = currlng + Math.atan2(Math.sin(bearing)*Math.sin(distance)
            *Math.cos(currlat), Math.cos(distance)-Math.sin(currlat)*Math.sin(Global.Alat));
    Math.toDegrees(Global.Alat);
    Math.toDegrees(Global.Alng);


    //Co-ord of Point B(x,y)
    // Note: Lng = X axis, Lat = Y axis.
    Global.Blat = Global.Alat+ 00.007931;
    Global.Blng = Global.Alng;

    //Co-ord of Point C(x,y)
    Global.Clat = Global.Alat  - 00.007931;
    Global.Clng = Global.Alng;

    }

通过调试,我确定问题出在此处完成的纬度计算上。

 Global.Alat = Math.asin(Math.sin(currlat)*Math.cos(distance)+ 
        Math.cos(currlat)*Math.sin(distance)*Math.cos(bearing));

但我不知道为什么,也不知道如何解决它。我从这个网站得到了公式..

http://www.movable-type .co.uk/scripts/latlong.html

它看起来是正确的,我已经测试了多种东西...

我尝试转换为弧度然后将计算返回到度数等。

任何人都知道如何修复此方法,以便它将在我面向的方向上绘制距我当前位置仅 700 米的三角形?

谢谢,

I'm constructing a geolocation based application and I'm trying to figure out a way to make my application realise when a user is facing the direction of the given location (a particular long / lat co-ord). I've got the math figured, I just have the triangle to construct.

//UPDATE

So I've figured out a good bit of this...

Below is a method which takes in a long / lat value and attempts to compute a triangle finding a point 700 meters away and one to its left + right. It'd then use these to construct the triangle. It computes the correct longitude but the latitude ends up somewhere off the coast of east Africa. (I'm in Ireland!).

public void drawtri(double currlng,double currlat, double bearing){

    bearing = (bearing < 0 ? -bearing : bearing);

    System.out.println("RUNNING THE DRAW TRIANGLE METHOD!!!!!");
    System.out.println("CURRENT LNG" + currlng);
    System.out.println("CURRENT LAT" + currlat);
    System.out.println("CURRENT BEARING" + bearing);

    //Find point X(x,y)
    double distance = 0.7; //700 meters.
    double R = 6371.0; //The radius of the earth.
    //Finding X's y value.

    Math.toRadians(currlng);
    Math.toRadians(currlat);
    Math.toRadians(bearing);

    distance = distance/R;
    Global.Alat = Math.asin(Math.sin(currlat)*Math.cos(distance)+ 
            Math.cos(currlat)*Math.sin(distance)*Math.cos(bearing));
    System.out.println("CURRENT ALAT!!: " + Global.Alat);
    //Finding X's x value.
    Global.Alng = currlng + Math.atan2(Math.sin(bearing)*Math.sin(distance)
            *Math.cos(currlat), Math.cos(distance)-Math.sin(currlat)*Math.sin(Global.Alat));
    Math.toDegrees(Global.Alat);
    Math.toDegrees(Global.Alng);


    //Co-ord of Point B(x,y)
    // Note: Lng = X axis, Lat = Y axis.
    Global.Blat = Global.Alat+ 00.007931;
    Global.Blng = Global.Alng;

    //Co-ord of Point C(x,y)
    Global.Clat = Global.Alat  - 00.007931;
    Global.Clng = Global.Alng;

    }

From debugging I've determined the problem lies with the computation of the latitude done here..

 Global.Alat = Math.asin(Math.sin(currlat)*Math.cos(distance)+ 
        Math.cos(currlat)*Math.sin(distance)*Math.cos(bearing));

I have no idea why though and don't know how to fix it. I got the formula from this site..

http://www.movable-type.co.uk/scripts/latlong.html

It appears correct and I've tested multiple things...

I've tried converting to Radians then post computations back to degrees, etc. etc.

Anyone got any ideas how to fix this method so that it will map the triangle ONLY 700 meters in from my current location in the direction that I am facing?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

嘿咻 2024-09-11 02:34:36

对于长途: http://www.dtcenter.org/met/用户/docs/write_ups/gc_simple.pdf
但对于短距离,您可以尝试使用简单的二维数学来模拟“经典”指南针: http:// en.wikipedia.org/wiki/Compass#Using_a_compass。例如,您可以从 A 点和 B 点获取像素坐标,并找到连接这些点的线与垂直线之间的角度。

另外您可能应该考虑磁偏角:http://www.ngdc.noaa.gov/ geomagmodels/Declination.jsp

//编辑:

我试图给出直观的解决方案。然而,从长/纬度计算屏幕坐标并不容易,因此您可能应该使用链接中提供的公式。

for long distance: http://www.dtcenter.org/met/users/docs/write_ups/gc_simple.pdf
but for short distance You can try simple 2d math to simulate "classic" compass using: http://en.wikipedia.org/wiki/Compass#Using_a_compass. For example you can get pixel coordinates from points A and B and find angle between line connecting those points and vertical line.

also You probably should consider magnetic declination: http://www.ngdc.noaa.gov/geomagmodels/Declination.jsp

//edit:

I was trying to give intuitive solution. However calculating screen coordinates from long/lat wouldn't be easy so You probably should use formulas provided in links.

抹茶夏天i‖ 2024-09-11 02:34:36

也许是因为我不懂 javascript,但是您是否必须执行类似

currlat = Math.toRadians(currlat); 的操作

才能实际将 currlat 值更改为弧度。

Maybe its because I don't know javascript, but don't you have to do something like

currlat = Math.toRadians(currlat);

to actually change the currlat value to be radians.

画尸师 2024-09-11 02:34:36

问题是无论我在java中通过管道传输什么都会以弧度输出,技巧是将所有内容更改为弧度,然后以弧度输出,转换为度数。

Problem was no matter what I piped in java would output in Radians, Trick was to change everything to Radians and then output came in radians, convert to degrees.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文