Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invert Number in C#

Tags:

c#

math

xna

Is there an easy way to invert a number in C# with a function? I'm using XNA and i'd like to tell my program that if my 'variable' gets beyond a certain number it has to invert it's value. The whole point is to give a rebound effect.

     if (ballPosition.X >= screenWidth)
                {
                    // Invert the ball Direction Vector.X
                }
like image 298
phadaphunk Avatar asked Mar 19 '12 05:03

phadaphunk


People also ask

How do you invert a number?

The inverse of a number A is 1/A since A * 1/A = 1 (e.g. the inverse of 5 is 1/5) All real numbers other than 0 have an inverse. Multiplying a number by the inverse of A is equivalent to dividing by A (e.g. 10/5 is the same as 10* 1/5)

What is logic of reverse number in C?

Reversing number in C means printing the given number back to the front. For example, the given number is 123, then the reverse of this number is 321.


2 Answers

Just whack a - sign in front of it:

direction.X = -direction.X;
like image 168
Andrew Cooper Avatar answered Oct 28 '22 23:10

Andrew Cooper


or you can try using Vector.X * -1

like image 36
Anon Avatar answered Oct 29 '22 00:10

Anon