On Wed, May 16, 2018 at 04:45:54PM +0200, Evaristo Quiroga via Therion wrote:
> I think the problem is the average calculation formula in "thdb1d.cxx"
> 
> >// check backwards compass reading
> >            if ((lei->data_type == TT_DATATYPE_NORMAL) ||
> >                (lei->data_type == TT_DATATYPE_DIVING) ||
> >                (lei->data_type == TT_DATATYPE_CYLPOLAR)) {
> >                if (!thisnan(lei->backbearing)) {
> >                if (thisnan(lei->bearing)) {
> >                  lei->backbearing -= 180.0;
> >                  if (lei->backbearing < 0)
> >                    lei->backbearing += 360.0;
> >                  lei->bearing = lei->backbearing;
> >                }
> >                else {
> >                  lei->backbearing -= 180.0;
> >                  if (lei->backbearing < 0)
> >                    lei->backbearing += 360.0;
> >                                    // calculate average of two angles
> >                  //lei->bearing += lei->backbearing;
> >                  //lei->bearing = lei->bearing / 2.0;
> >                                    double sumx, sumy;
> >                                    sumx = cos((90.0 -
> >lei->bearing)/180.0*THPI) + cos((90.0 - lei->backbearing)/180.0*THPI);
> >                                    sumy = sin((90.0 -
> >lei->bearing)/180.0*THPI) + sin((90.0 - lei->backbearing)/180.0*THPI);
> >                                    lei->bearing = 90.0 - (atan2(sumy,
> >sumx) / THPI * 180.0);
> >                  if (lei->bearing < 0.0)
> >                    lei->bearing += 360.0;
> >                }
> >              }
> >            }
> 
> I think the formula is too complicated. I purpose a simpler formula, like:
>             If bearing <=180
>                       AverageBearing =  (bearing + (backbearing -180))/2
>                 else
>                       AverageBearing = (bearing + (backbearing +180))/2

Your proposed formula gives wrong answers in some cases - consider:

bearing = 80, backbearing = 0

These give AverageBearing = (80 + 0 - 180) / 2 = -50 (equivalent to
310), but this should be 130 (average of 80 and 180).

The therion formula is attempting to average the angles by trigonometry,
which seems a reasonable approach (though probably slower than trying to
average more directly like you're suggesting).  It looks essentially
correct to me, though it's a bit oddly written since cos(90 - x) is
sin(x), sin(90 - x) is -cos(x), 90 - atan2(y,x) is atan2(x,y) (possibly
+/- a multiple of 360).  But if I work it out with a calculator for
236.8 and 56.8 then I do get 236.8.

If it's still not working with the declination set to zero, perhaps
you should show us a complete small example we can process to see
what is going on?

Cheers,
    Olly
_______________________________________________
Therion mailing list
Therion@speleo.sk
https://mailman.speleo.sk/listinfo/therion

Reply via email to