Getting an angle

Blitz3D Forums/Blitz3D Programming/Getting an angle

JBR(Posted 2005) [#1]
Hi,

Have variable angle% which can be -ve or +ve and any size.
What i want is to return the correct angle between 0 to 359.

angle% = angle% mod 360 works fine for +ve angles.

angle% = (360 + (angle% mod 360)) mod 360 works for all.

Is there a better way (avoiding mod)?

Thanks
Marg


Mr Snidesmin(Posted 2005) [#2]
try this:


function angle#(ang#)
while ang >= 360
ang = ang - 360
wend
while ang < 0
ang = ang + 360
wend
return ang
end function


octothorpe(Posted 2005) [#3]
What's wrong with mod?


Jams(Posted 2005) [#4]
As a side note, generally with angles it's better to work from -180 to +180.... makes things alot easier when using > and <


Hotcakes(Posted 2005) [#5]
It depends how you want to code. Obviously -180 is not a valid angle technically speaking.


Mr Snidesmin(Posted 2005) [#6]
personally I don't ususally bother converting angles. They rarely get 'way out of scale' and as long as the maths is sound there should be no problems. I would only convert if I actually needed to display the angle for some reason.


boomboommax(Posted 2005) [#7]
well you could just add 180 to the angle...


nawi(Posted 2005) [#8]
-180 is a valid angle.


Hotcakes(Posted 2005) [#9]
About as much as 101% is a valid percentage.


Mr Snidesmin(Posted 2005) [#10]
Any angle -infinity to +infinity as a measurement of rotation is valid mathematically.


Mr Snidesmin(Posted 2005) [#11]
oh and also, 101% is a completely valid percentage. A percentage is just another way of expressing a fraction, similar to decimal representation. 101% is the same as 1.01


Hujiklo(Posted 2005) [#12]
So what's 140% of -768 degrees then smarty pants? - ho ho ;D

Great sig by the way.


Mr Snidesmin(Posted 2005) [#13]
Easy: -1075.2
duh! :O)


Mr Snidesmin(Posted 2005) [#14]
ps. thanks for the remark - took me at least a day to come up with it :O)


Dreamora(Posted 2005) [#15]
angle% = (360 + (angle% mod 360)) mod 360

can be shortened to

angle% = (360 + angle%) mod 360


This will remove one mod operation and make it faster.


octothorpe(Posted 2005) [#16]
Dreamora, that'll return negative numbers for angles < -360