一个点能否走到另一个点java_java – 如何在两个其他点之间找到地理点

您可以通过以下步骤解决您的问题.

>计算A点和B点的距离(使用Haversine formula,这在这里足够好,或者更复杂的Vincenty formula).要使用

公式正确,Android的microdegrees,这就是getLatitude

和getLongitude返回,必须转换为弧度,

使用这样的公式:

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

>从A点和B点计算轴承(方向)(使用公式

在同一页上).这与毕达哥拉斯公式不同,因为

地球是圆的,不是平的.

>然后你可以选择一个新的距离并计算给定的X点

A点和上一步中找到的轴承(参见同一页面上的“目标点给定距离和起点承载”或Vincenty’s

direct formula).

>使用以下公式将生成点的弧度转换为微度:

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

总而言之,我们有以下功能,我将其置于公共领域:

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

while(xlon>180000000)xlon-=360000000;

while(xlon<=-180000000)xlon+=360000000;

return new int[]{xlat,xlon};

}

以下是它的使用方法:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值