如何计算斜边和轴承 [英] How to compute hypotenuse and bearing

查看:202
本文介绍了如何计算斜边和轴承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从@DanS下面code这个链接<一个href="http://stackoverflow.com/questions/7062115/android-how-to-display-a-map-still-image-file-with-a-moving-current-location">how-to-display-a-map-still-image-file-with-a-moving-current-location

I got the below code from @DanS at this link how-to-display-a-map-still-image-file-with-a-moving-current-location

onCurrentPosition(Location current){
    double hypotenuse = upperLeft.distanceTo(current);
    double bearing = upperLeft.bearingTo(current);
    double currentDistanceX = Math.cos(bearing) * hypotenuse;
    //                     "percentage to mark the position"
    double currentPixelX = (currentDistanceX / upperLeft.distanceTo(lowerRight) * Math.cos(upperLeft.bearingTo(lowerRight))) * mapWidth;

    moveIndicatorX(currentPixelX);
}

下面是值:

  • 电流:41.850033,-87.65005229999997
  • upperLeft:41.866514127810355,-87.6720142364502
  • lowerRight:41.83397145565242,-87.62824058532715
  • mapWidth:512×512像素

下面是计算器在线位置,斜边(距离),轴承(方位角)

Here are the calculator online for Location, hypotenuse(Distance), bearing(Azimuths)

  • convert LatLng to Location format(e.g. 41° 51′ 59.45″ N 87° 40′ 19.25″ W)
  • compute distance & azimuths from the given Location

我得到的结果:

  • 斜边= 2581
  • 轴承= 135.21
  • currentDistanceX = -2562
  • currentPixelX = 311.9

想问问你们到:

  1. 以确认如果我的计算结果是正确的。
  2. 如何计算currentPixelY(在1分)?
  1. to confirm if my computed results are correct.
  2. on how to compute the currentPixelY (the another one point)?

顺便说一句,我打算用它来计算给定的现实生活中的位置的经纬度(电流)对我的静止图像地图,保税静止图像转化为现实生活中经纬度的upperLeft和lowerRight角落。

By the way, I am planning to use that to compute the location of a given real life LatLng(current) against with my still image map which bonded the upperLeft and lowerRight corners of the still image into real life LatLng.

如果你想看到的实际和放大器;预期产出,想方便地了解全貌。请参考此链接 - > <一个href="http://stackoverflow.com/questions/7072400/android-how-to-mark-the-current-location-into-a-map-still-image-source-$c$c">How标记当前位置为静止图像地图

If you want to see the actual & expected output and want to easily understand the whole picture. Please refer to this link -> How to mark the current location into a still image map

推荐答案

这是实际的code我用,而不是伪code贴previously:

This is the actual code I'm using, not pseudo code posted previously:

Location upperLeft = new Location("");
upperLeft.setLatitude(41.866514127810355);
upperLeft.setLongitude(-87.6720142364502);
Location lowerRight = new Location("");
lowerRight.setLatitude(41.83397145565242);
lowerRight.setLongitude(-87.62824058532715);
Location current = new Location("");
current.setLatitude(41.850033);
current.setLongitude(-87.65005229999997);
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceX = Math.cos(bearing * Math.PI / 180.0) * hypotenuse;
//                     "percentage to mark the position"
double totalHypotenuse = upperLeft.distanceTo(lowerRight);
double totalDistanceX = totalHypotenuse * Math.cos(upperLeft.bearingTo(lowerRight) * Math.PI / 180.0);
double currentPixelX = currentDistanceX / totalDistanceX * 512;

System.out.println(currentPixelX); // 259.3345493341548

您计算出答案看起来有点假。 为了计算y变为复制所有的X标记的计算和变量使用 Math.sin()而不是 Math.cos()

Your calculated answer looks a bit off. To calculate Y change copy all the X marked calculations and variables to use Math.sin() instead of Math.cos().

这篇关于如何计算斜边和轴承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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