Should be a easier way to get which side rhumb line segment

68 Views Asked by At

Should be a easier way to get which side of a rhumb line segment. I have tried haversine formulas etc. but over 50 metres to 10kms it is accuracy irrelevant and outputs a initall bearing rather than a rhumb bearing. I also use some data further to get 90 degree bearing from rhumb segment to point. I still seem to be having accuracy problems with this section of code given that my getRhumbBearing seems to be correct.

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);
            }
      }
0

There are 0 best solutions below