![]() |
More of a math question...
1 Attachment(s)
Okay, say I have a number of directions, in this example, 16.
I have a set dir1, 6. And I also have dir2, 1. How would I get the 'distance', or in this case, the number of directions dir1 is from dir2? I know in the example I posted with it, it's 2 directions away, but what would be the formula to do this? The problem arises since, like in the example, dir1 is 15, and dir2 is 1, so abs(dir2-dir1)=14. If any of this makes sense, any advice? |
Quote:
dist = abs(dir2 - dir1); if (dist > 8) dist = 16 - dist; |
Thanks, that worked great. :)
Though I ended up doing: dist=abs(dir2-dir1)>8?16-abs(dir2-dir1):abs(dir2-dir1); |
Quote:
I just have an OCD think about repeating the same math formula over and over again :P |
Oh I know, I thought the same thing at first... but meh, dunno, keeps it to one line so I like it.
|
Quote:
Then do something like.... PHP Code:
|
All times are GMT +2. The time now is 03:32 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.