I'm using GCBASIC 0.99.01 2022-01-27 (Windows 64 bit) : Build 1073 with the 18F4550 chip.
I'm trying to use this : byte_variable = atan (x_vector,y_vector) which is in #include <maths.h></maths.h>
First a question:
There are at least 2 coordinate systems. The Cartesian Coordinates where 0 degrees is the +X axis, 90 degrees is the +Y axis, 180 is -X axis and 270 is -Y axis. (Counter clockwise rotation from 0 degrees)
The other is the Compass coordinate system where 0 degrees is the +Y axis, 90 degrees is the +X axis, 180 is the -Y axis and 270 is the -X axis. (Clockwise rotation from 0 degrees)
The Help file doesn't mention it but It appears that this function uses the Compass coordinate system. Is that correct?
Now the error in the function.
If X is negative and Y is positive, GCB gives the wrong answer.
For example: If X = -25 and Y = 45, Degrees = Atan (Y/X) = Atan (-25/45) = -29 degrees.
With -X, +Y, the Compass coordinate system would give 119 degrees.
The Compass coordinate system would give 330 degrees.
But GCB gives 75 degrees.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@William Roth "ATan returns a WORD value, not a byte as in the main description. A few lines down it says it returns a WORD. So confusing a bit."
true
Byte_Result = ATan(-25,45)
Word_Result = ATan(-25,45)
negative numbers not as expected.
Suppose I don't understand signed integers :)
I've never used ATan so looking it up. I've tried the sin cos using Trig.h which is useful for glcd dials... or maybe missile command or 2 us rangefinders for robots.
I'll see what ATan can be useful for.
'This version takes any +/- XY vector and returns degrees 0-360
'v1.01
Function ATan ( xvector as integer, yvector as integer ) as word
'Fast XY vector to integer degree algorithm - Jan 2011 www.RomanBlack.com
'See http://www.romanblack.com/integer_degree.htm
'Converts any XY values including 0 to a degree value that should be
'within +/- 1 degree of the accurate value without needing
'large slow trig functions like ArcTan() or ArcCos().
'NOTE! at least one of the X or Y values must be non-zero!
'This is the full version, for all 4 quadrants and will generate
'the angle in integer degrees from 0-360.
'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.
;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It appears that the Help is also confusing/misleading for Sine, Cosine & Tangent.
From the Help:
Trigonometry Sine, Cosine and Tangent
Syntax:
byte_variable = sin( word_variable )
byte_variable = cos( word_variable )
byte_variable = tan( word_variable )
Explanation:
Great Cow BASIC supports Three Primary Trigonometric Functions
Great Cow BASIC supports the following functions, sin(x), cos(x), tan(x), where x is a
signed integer representing an angle measured in a whole number of degrees. The
output values are also integers, represented as fixed point decimal fractions.
The "syntax" seems to be incorrect. Both "byte_variable" and "word_variable" should instead be integer variables.
Someone please correct me if I am wrong (before I edit the Help)
William
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I had to learn trig as part of passing maths in school but never used it in any jobs.
I've used trig 2 places. h ok. works like a compass /clock and sin, cos work fast on a glcd.
A circle using trig looks different to the circle command.
Google ATan gives little relevant to gcb ... stuff with pi. Whatever it does it's probably fast as it's a math function but it's not easy to find a use for it explained.
I'm using GCBASIC 0.99.01 2022-01-27 (Windows 64 bit) : Build 1073 with the 18F4550 chip.
I'm trying to use this : byte_variable = atan (x_vector,y_vector) which is in #include <maths.h></maths.h>
First a question:
There are at least 2 coordinate systems. The Cartesian Coordinates where 0 degrees is the +X axis, 90 degrees is the +Y axis, 180 is -X axis and 270 is -Y axis. (Counter clockwise rotation from 0 degrees)
The other is the Compass coordinate system where 0 degrees is the +Y axis, 90 degrees is the +X axis, 180 is the -Y axis and 270 is the -X axis. (Clockwise rotation from 0 degrees)
The Help file doesn't mention it but It appears that this function uses the Compass coordinate system. Is that correct?
Now the error in the function.
If X is negative and Y is positive, GCB gives the wrong answer.
For example: If X = -25 and Y = 45, Degrees = Atan (Y/X) = Atan (-25/45) = -29 degrees.
With -X, +Y, the Compass coordinate system would give 119 degrees.
The Compass coordinate system would give 330 degrees.
But GCB gives 75 degrees.
ATan returns a WORD value, not a byte as in the main description. A few lines down it says it returns a WORD. So confusing a bit.
When I use a BYTE I get 75.
When I use a WORD I get 331.
Last edit: William Roth 2022-06-15
An update to the documentation needed? The Help source is here - https://github.com/GreatCowBASIC/Help/blob/main/source/trigonometryatan.adoc
Thanks William that solved it.
Anobium,
The Help file doesn't mention it but It appears that this function uses the Compass coordinate system. Is that correct?
I would suggest the Help file specify if this function outputs degrees based on the Cartesian Coordinate system or the Compass coordinate system.
To me, it looks like the Compass coordinate system.
@William Roth "ATan returns a WORD value, not a byte as in the main description. A few lines down it says it returns a WORD. So confusing a bit."
true
Byte_Result = ATan(-25,45)
Word_Result = ATan(-25,45)
negative numbers not as expected.
Suppose I don't understand signed integers :)
I've never used ATan so looking it up. I've tried the sin cos using Trig.h which is useful for glcd dials... or maybe missile command or 2 us rangefinders for robots.
I'll see what ATan can be useful for.
'This version takes any +/- XY vector and returns degrees 0-360
'v1.01
Function ATan ( xvector as integer, yvector as integer ) as word
'Fast XY vector to integer degree algorithm - Jan 2011 www.RomanBlack.com
'See http://www.romanblack.com/integer_degree.htm
'Converts any XY values including 0 to a degree value that should be
'within +/- 1 degree of the accurate value without needing
'large slow trig functions like ArcTan() or ArcCos().
'NOTE! at least one of the X or Y values must be non-zero!
'This is the full version, for all 4 quadrants and will generate
'the angle in integer degrees from 0-360.
'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.
;
It appears that the Help is also confusing/misleading for Sine, Cosine & Tangent.
From the Help:
The "syntax" seems to be incorrect. Both "byte_variable" and "word_variable" should instead be integer variables.
Someone please correct me if I am wrong (before I edit the Help)
William
If the methods in the library are Word ( in ) and returns an Integer then you are correct and the Help is incorrect.
If the methods in the library are Word ( in ) and returns an Integer then you are correct and the Help is incorrect.
From the Library(s)
So looks like integer in and returns integer in all cases
Looks correct from your analysis.
I had to learn trig as part of passing maths in school but never used it in any jobs.
I've used trig 2 places. h ok. works like a compass /clock and sin, cos work fast on a glcd.
A circle using trig looks different to the circle command.
Google ATan gives little relevant to gcb ... stuff with pi. Whatever it does it's probably fast as it's a math function but it's not easy to find a use for it explained.
I tried a glcd clock but it's the hand sub that does it all and so simple
https://www.youtube.com/watch?v=Uxxo2zDLM-o
Last edit: stan cartwright 2022-06-17
I have updated the Help to correct to integer variables.
I have updated and corrected the following :
See https://github.com/GreatCowBASIC/Help/tree/main/source for the latest source files. The next update (GCStudio) will contain these updates.