应该是一种更简单的方法来获取恒向线段的哪一侧。我已经尝试过半正弦公式等,但是超过 50 米到 10 公里的距离与精度无关,并且输出的是初始方位而不是恒向方位。我还进一步使用了一些数据来获得从 rhumb 段到点的 90 度方位。鉴于我getRhumbBearing
似乎是正确的,这部分代码似乎仍然存在准确性问题。
public class sideFromLine
{
public static double tbearing=0;
public static double getbearing(double lata,double lona,double latb,double lonb,double lat,double lon){
double tbearing =getRhumbLineBearingUtil.getRhumbLineBearing(lata, lona, latb, lonb);
double bearingr=(tbearing + 90);
double bearingl=(tbearing - 90);
// Toast.makeText(this, (Double.toString(tbearing)), Toast.LENGTH_SHORT).show();
// rbearing= Math.round(-bearingl / 360 + 180);
// lbearing=Math.round(-bearingr / 360 + 180);
double rbearing=0;
if (bearingr > 180)
{
rbearing = bearingr - 360;
}
else
{
if (bearingr > -180)
{
rbearing = bearingr;
}
else
{
rbearing = bearingr + 360;
}
}
double lbearing=0;
if (bearingl > 180)
{
lbearing = bearingl - 360;
}
else
{
if (bearingl > -180)
{
lbearing = bearingl;
}
else
{
lbearing = bearingl + 360;
}
}
double gbearing=targetside(lat,lon);
double sbear=0;
if (gbearing < .5)
{
sbear = lbearing;
}
else
{
sbear = rbearing;
}
return sbear;
}
private static double targetside(double lat, double lon)
{
double tabbearing;
//tbearing=getRhumbLineBearingUtil.getRhumbLineBearing(lata, lona, latb, lonb);
// lona to target point
double atbearing = getRhumbLineBearingUtil.getRhumbLineBearing(lata, lona, lat, lon);
double recipbearing = getRhumbLineBearingUtil.getRhumbLineBearing(latb, lonb, lata, lona);
//0.0000 stop 0 probs do no change...... //Change to positive for maths
if (atbearing > 0.000000001)
{
}
else
{
atbearing = atbearing + 360;
}
if (tbearing > 0.000000000001)
{
tabbearing = tbearing;
}
else
{
tabbearing = tbearing + 360;
}
if (recipbearing > 0.000000000001)
{}
else
{
recipbearing = recipbearing + 360;
}
//if at is one 360 &at the other trouble
//||atbearing<recipbearing
if (atbearing > tabbearing && atbearing < recipbearing)
{
double side=1;
/*
//Getting reference to speed
TextView spea = (TextView)findViewById(R.id.textView6);
//set speed
spea.setText("sidealata" +(precision00.format(side)));
*/
return(side);
}
else
{
double side=0;
/*
//Getting reference to
TextView spea = (TextView)findViewById(R.id.textView6);
//set
spea.setText("sidealata" +(precision00.format(side)));
*/
return(side);
}
}