Menu

Increasing range of Atan Function to all integers

MBB
2020-06-01
2020-06-01
  • MBB

    MBB - 2020-06-01

    In the maths.h include file is the Atan function which is on based on Roman Black's formulae.

    In the comments it says:
    "'Any values of X and Y are usable including negative values provided
    'they are between -1456 and 1456 so the 16bit multiply does not overflow."

    The Function uses this:

    Dim uxvector, uyvector, degree as Integer

    If this is changed to:

    Dim degree as Integer
    Dim uxvector, uyvector As Long

    the range increases from -1456 and 1456 to -32768 and 32767. This would allow the ArcTangent of any integer to be calculated.

    Does anyone see a problem with this?

     
  • Anobium

    Anobium - 2020-06-01

    Sounds reasonable, but, why did the author put that constraint there?

    I do not think it was a variable type issue. Longs were available so this would not have been a constraint.
    The 16bit multiple. Are you sure it cannot overflow?
    Or, was the Word value a constraint in the Roman Black code? and, it was carried forward?

     
  • stan cartwright

    stan cartwright - 2020-06-01

    Quote
    A big benefit of this algorithm is its flexibility, being able to use any X and Y values. If you use a 32bit multiply and divide which is a little slower than the 16bit multiply and divide it is possible to use very large X and Y values. This makes it ideal for robot navigation or CNC machine coordinates where you just give it the XY values from the last move and it returns the direction as a 0-360 degree heading.

    So the author put no constraint on 32 bit math it seems.

     
  • stan cartwright

    stan cartwright - 2020-06-01

    This makes it ideal for robot navigation or CNC machine coordinates where you just give it the XY values from the last move and it returns the direction as a 0-360 degree heading.
    ...does it simplify anything? still got to use sin cos to use heading...but I hate trig

     

Log in to post a comment.