Hi,
I've been given an equasion by JJW, and would like to try it in Oshonsoft:
'##############################################################################
You calculate angle in radians from x, y coordinates.
Angle in degrees = radians × 180 / Pi
~ radians × 57.3
Oshonsoft has arctan function for y / x < 1
You have to calculate in eight octants ( 45 degrees )
Octants can be found from signs of x and y and from
value of y / x if it is less or greater than one.
For example, if North is 0 degrees and clockwise direction:
0 - 45 degrees x / y < 1 and x > 0, y > 0
angle = arctan( x / y ) × 57.3
45 - 90 degrees x/y > 1 x >0 y>0
angle = 90 - arctan( y / x ) × 57.3
etc ...
Angle, x and y are floating point variables
'#################################################################################
Is this correct?
Between 0° to 45°
If x/y < 1 then
If x >0 then
If y > 0 then
angle = arctan( x / y ) × 57.3
ENDIF
ENDIF
ENDIF
It is not correct.
Between 0-45 , x < y
Follow the example I gave.
The arctan function in Oshonsoft is not accurate.
The error is over 4 degrees near arctan(1)
You can use the approximation which was used in the thread 1 - 1.5 year ago:
Atn(x/y) = x/y / (1+0.285125(x/y)^2)
when x/y <= 1
Accuracy is better than 0.3 degrees
It is not correct.
Between 0-45 , x < y
Follow the example I gave.
The arctan function in Oshonsoft is not accurate.
The error is over 4 degrees near arctan(1)
You can use the approximation which was used in the thread 1 - 1.5 year ago:
Atn(x/y) = x/y / (1+0.285125(x/y)^2)
when x/y <= 1
Accuracy is better than 0.3 degrees
Hi J,
When you say "Follow the example I gave" I presume you mean the one in #1, is this correct?
If so, then that was my attempt to write the first line of it. I don't understand the language your example is written in.
You say I can use the approximation from 1.5 years ago, but it has ATN, will it work in Oshonsoft?
Hi J,
When you say "Follow the example I gave" I presume you mean the one in #1, is this correct?
If so, then that was my attempt to write the first line of it. I don't understand the language your example is written in.
You say I can use the approximation from 1.5 years ago, but it has ATN, will it work in Oshonsoft?
ATN is just a name for the approximation function, which is defined in your program.
You can use any name which is not a reserved word in Oshonsoft.
For example arcustanget or whatever.
Hi J,
Can this section be used independantly?
I tried it and it complies ok, but only gives '0'
I presume the section shown as 2'S COMPLIMENT CALC IS NEEDED?
Note: I've just seen your later comment below, so another reply on it's way.
C.
I haven't been able to add 57.3 into the program, so I tried 'picalc' = 57.3. It didn't work! EDIT: ERROR!! LONG is a mistake SINGLE should be used in some of the cases.
C.
I don't see any arctan function in the program?
x and y as arguments to the function should be singles unless you will calculate with longs or words and handle all scaling back and forth.
You have defined x_raw, y_raw as single, but use x_raw.hb x_raw.lb ??
Use x_raw ... as word, x as single and after reading x_raw and making 2's complement x = x_raw
same for y and then calculate arctan
Hi J,
Firstly (following #2 and#5) do I use 'arctn' which is my none Oshonsoft reserved word, or Arctan which is an Oshonsoft function?
This does compile: azi = Arctan(x_raw / y_raw) * picalc '180/pi
This doesn't compile: azi = arctn(x_raw / y_raw) * picalc '180/pi
The x and y_raw HB and LB are used because the Compass module is READ in 6x BYTEs, also I use them to show the BYTEs as they change on the screen.
EDITED.