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 ...
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 ...
In your 0-45 example is: 0 - 45 degrees x / y < 1 and x > 0, y > 0, the explanation
and: angle = arctan( x / y ) × 57.3, the calculation?
Or are they both the in calculation?
I have never come across a compass that gives Radians.
I'm guessing you have three quantities in the X,Y and Z directions.
To convert two of these quantities to an angle can be done in various ways. I like Roman Blacks method. If you take the time to understand the maths then you will be much wiser.
Mike.
P.S. how can 0-360 ever represent anything in 3 dimensions?
I have never come across a compass that gives Radians.
I'm guessing you have three quantities in the X,Y and Z directions.
To convert two of these quantities to an angle can be done in various ways. I like Roman Blacks method. If you take the time to understand the maths then you will be much wiser.
Mike.
P.S. how can 0-360 ever represent anything in 3 dimensions?
Hi,
This is mighty complicated, but I get a sense of déjà vu, as I've been through this before, and almost forgotten it.
Thanks for the information. Between that and the attached file, I'll try to work through it all, for Oshonsoft calculation.
C.
Here is RBs code modified slightly to calculate an angle of 0-255 from two signed words x & y - I needed this for another project - I think it's almost useable in basic. Although it looks long it's very fast.
Mike.
Code:
sx=sign(x)
ux=abs(x)
sy=sign(y)
uy=abs(y)
if ux>uy then
degrees=uy*32/ux
oct=1
else
degrees=ux*32/uy
oct=0
endif
bodge=0
if degrees>16
if degrees<32
bodge=bodge+1
endif
if degrees<28
bodge=bodge+1
endif
if degrees<24
bodge=bodge+1
endif
else
if degrees>0
bodge=bodge+1
endif
if degrees>3
bodge=bodge+1
endif
if degrees>8
bodge=bodge+1
endif
endif
degrees=degrees+bodge
if oct>0
degrees=64-degrees
endif
if sy>0
if sx>0
degrees=128+degrees
else
degrees=128-degrees
endif
else
if sx>0
degrees=-degrees
endif
endif
Here is RBs code modified slightly to calculate an angle of 0-255 from two signed words x & y - I needed this for another project - I think it's almost useable in basic. Although it looks long it's very fast.
That's why I wrote the message #12
It was an example, how to get absolute value of a variable.
You can make your own ABS function which is missing in Oshonsoft.
Function ABS ( arg as single ) as single
If arg < 0 then
ABS = -1 * arg
Else
ABS = arg
End function
That's why I wrote the message #12
It was an example, how to get absolute value of a variable.
You can make your own ABS function which is missing in Oshonsoft.
Function ABS ( arg as single ) as single
If arg < 0 then
ABS = -1 * arg
Else
ABS = arg
End function
Hi J,
For me this is really complicated!
This and the #12 reply, use the word ABS. If I type ABS into an Oshonsoft program, then it is rejected, so as I understand it, another way must be used.
C.
Hi M,
I almost understand your example.
Is this correct: Where 'x' is the number being worked on. Use 'sx' and 'ux' as a tempory substitute. If the result 'sx' is a negative, then 'x' [now called either 'sx' or 'ux'] needs this calculation for the result?
P.S. I can hardly understand my explanation. I'll try this method, and post it, thanks.
C.
Hi J,
For me this is really complicated!
This and the #12 reply, use the word ABS. If I type ABS into an Oshonsoft program, then it is rejected, so as I understand it, another way must be used.
C.