[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Negative number positive



What I ment with "-x" was " a negative number" while x is a number. Using ABS() on a positive number is nonesense... Thats why I added the "-". Probably mathematically not correct written. Sorry for this.


Am 28.12.2006 um 00:34 schrieb Luke Paireepinart:

Farai Aschwanden wrote:
I can tell you why. I need it for mirroring. Imagine a 3D environment you are watching in ego perspective (Dungeon Master like). There is a walk way for NPCs from left to right in steps of 5 positions (0-4, each position represents a coordinate pair on which the NPC is painted). So, position 0 is the most left while position 4 is the most right on the screen.
There is now a NPC passing the way from 0 to 1 and waiting there (quite on the left border of the screen). Now you pass him crosswise, turn by 180 degrees and watch him again. Ooops he is still standing on the left side on the screen but by mirroring he should now stand on position 3 (on the right side).
I was looking for a easy way how to calculate the new position when mirroring happens. Based on my example: How do I come from 1 to 3? I use 0 are mirror and subtract 4 from 1 = -3. The negavite value is not a valid position so..... abs()
Based on my example it works for all values
0 <-> 4
1 <-> 3
2 <-> 2
3 <-> 1
4 <-> 0


Thats all about. If there is a better way, please let me know.
Farai
No, see in your response you said the function you found was abs(- x). because x is not a number,
it is implied that x is a variable that you declared before,
such as this:
x = -5


abs(-x) #is then the incorrect thing to do.
abs(x) #is the correct thing to do.

Do you see what I mean?

HTH,
-Luke