Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Oh no - another ATANFULL() question - decreasing from 90

Author
Message
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 4th Nov 2010 14:04
I have read through the forums, but there must be something I am missing as I still don't understand the definitive output from the ATANFULL() command.

The manual says 0 to 360; some forum entries say -180 to 180; but when I am running it and following a point in a clockwise direction, when it reaches 90 degrees, it then starts decreasing.

0
.
.. 45
...
.... 90
...
.. 45
.
0

Hope the drawing makes sense... (acos will only return a range from -90 to 90), so does anyone have the definitive work on what atanfull() returns and how to get that 0 -> 360 degree range?

Thanks,
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 4th Nov 2010 14:44
Hello bodmcn,

Here's something to visualize what atanfull does:


On my pc the range is (-180,180).

If you would like more help on why you get only 0-90 degrees, I think it would be best by posting your code.

Good luck!
Sven B

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2010 14:48 Edited at: 4th Nov 2010 14:50
It's actually -180 to 180.

Try this and compare the output with the image.





Hope I got it right - it certainly wasn't what I expected either.

Edit SvenB beat me to it.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Nov 2010 15:23
-180 to 180 is quite easy to convert to 0-360 - but I'm not sure that you need to, really. If you are using this to compare angles for example - like the aiming angle of an enemy and the position of the player, then keeping to -180 to 180 ranges makes more sense, because you can use it to decide if you need to turn left, or right. There is no difference between using -90, or 270 - except that by using -90, you instantly know that's 90 degrees left, you can work with that.

So to convert an angle into a 0-360, use WRAPVALUE(), anything inside those brackets will be limited, wrapped into 0 to 360 degrees.

If you need to check the difference between angles, then just use the straight ATANFULL value, and the object value - deduct 1 angle from the other, then do this:

Ang#=angle1#-angle2#
While ang#>180 : dec ang#,360.0 : endwhile
While ang#<-180 : inc ang#,360.0 : endwhile

So that will make ang# a value from -180 to 180, so very easy to use when deciding which way an enemy should turn, or if it should see the player, all of that stuff.

Health, Ammo, and bacon and eggs!
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 4th Nov 2010 20:48
Quote: "The manual says 0 to 360; some forum entries say -180 to 180; but when I am running it and following a point in a clockwise direction, when it reaches 90 degrees, it then starts decreasing."

this sounds more like a problem in coding to me.

Can you post some code?

bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 5th Nov 2010 00:30
Thanks for all the replies. Will post the code when I get home; should have done it already d'oh.
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 5th Nov 2010 11:50
Here is the function for getting the angle from the two points:




It is utilised to get the angle of the sprite from the centre of the screen:




It gives the following log:

Ball x:406 y:63 deg:1 atan deg:1
Ball x:410 y:72 deg:2 atan deg:2
Ball x:413 y:80 deg:3 atan deg:3
.
.
.
Ball x:491 y:272 deg:73 atan deg:72
Ball x:494 y:280 deg:78 atan deg:77
Ball x:497 y:288 deg:90 atan deg:82
Ball x:501 y:297 deg:90 atan deg:88
Ball x:504 y:305 deg:90 atan deg:87
Ball x:507 y:314 deg:90 atan deg:82
Ball x:511 y:322 deg:79 atan deg:78
Ball x:514 y:330 deg:76 atan deg:75
.
.
.
Ball x:571 y:472 deg:44 atan deg:44
Ball x:575 y:480 deg:44 atan deg:44
Ball x:578 y:489 deg:43 atan deg:43


The deg:n values are from an acos() comparative calculation.

Given the above, why is the atanfull() decreasing after reaching the value of 90?

Thanks again,
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 5th Nov 2010 11:52
Forgot to add that originX is 400 and originY is 300 (centre of an 800x600 window).
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Nov 2010 12:32
Why did you do this?



That guarantees the results you are seeing - look at the image I posted a couple of posts back.
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 5th Nov 2010 12:41
OMG

I have no idea where that came into it and it makes no sense now I look at it... oh dear me I am suitably embarrassed.

My apologies for wasting peoples' time.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Nov 2010 12:44
It will decrease because your only looking at the absolute values - don't use ABS and it should give real results. If you consider that your only actually checking within a 90 degree tolerance when you ban negative values, it's no surprise that it starts to decrease when it goes past 90 - there's nothing more that it can do.

In the old days, the long long ago - we'd use ATAN and stuff like that, but we'd always have to check the differences, like if XB is greater than XA then ang#=90.0-ang#... the 2 coordinates would be checked, and the resulting angle would be adjusted to suit this. ATANFULL is designed to avoid this complexity, and it does work! - it just relies on un-raped values .

Health, Ammo, and bacon and eggs!
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 5th Nov 2010 12:58
It does - took 2 seconds to fix and get working. I am not sure I will be able to hold up my head in respectable geek company ever again...
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Nov 2010 15:25
Usually we just blame the manual at times like this .

It's good to experiment with the commands, try and break them even, it's the only way to get familiar with them - ATANFULL will be like an old friend the next time you use it .

Health, Ammo, and bacon and eggs!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Nov 2010 16:24
Quote: "I am not sure I will be able to hold up my head in respectable geek company ever again"


Doesn't matter - we don't claim to be respectable here.

Quote: "Usually we just blame the manual at times like this"


Often with good reason.

Login to post a reply

Server time is: 2026-07-26 05:03:47
Your offset time is: 2026-07-26 05:03:47