# Imaginary Numbers

120 replies to this topic

### #1 kibblesbob

kibblesbob

"Xarrot Studios"

• GMC Member
• 210 posts
• Version:GM:Studio

Posted 10 March 2011 - 06:02 PM

Well I was working on a quadratic equation calculator, and everything works fine except when you have a negative discriminant. Now we all know that when you try to take the square root of a negative number ( EX - sqrt(-24) ) , game maker will give you an error saying "Cannot apply sqrt to negative number". But why? my graphing calculators can, and so can most of the other quadratic calculators on any given site. So why doesn't GM have a value for 'i'? I don't need an explanation of the mathematics, I already covered that. I want to know why GM doesn't have this feature for imaginary numbers.
• 0

### #2 FakeKraid

FakeKraid

Total Fraud

• GMC Member
• 53 posts
• Version:GM8

Posted 10 March 2011 - 06:07 PM

Well, aside from a program devoted to solving equations, what purpose would it serve? You can only plot real numbers on a 2D graph, and in the end, that's essentially all Game Maker is supposed to do. I can't think of any conceivable purpose 'i' would have in an ordinary game. Perhaps I'm just narrow-minded?
• 1

### #3 kibblesbob

kibblesbob

"Xarrot Studios"

• GMC Member
• 210 posts
• Version:GM:Studio

Posted 10 March 2011 - 06:14 PM

the only imaginary number I would plan on using more than once is 'i' which is equal to sqrt(-1), and from that i^2 is equal to -1. the only reason i would need them though is to make my life MUCH easier when doing things with parabolas and other quadratic functions. Its not a big deal though, it just means i have to work around it
• 0

### #4 Erik Leppen

Erik Leppen

GMC Member

• GMC Member
• 2038 posts
• Version:GM:Studio

Posted 10 March 2011 - 06:17 PM

What were you planning to use it for?

Also I don't know of any programming languate that natively supports complex numbers. Real, string, float, double, boole are default data types, I have never seen "complex" as a data type. This is to be expected, since a complex number is essentially a vector with two coordinates (the real and the imaginary part), following a few special rules of arithmetic (the multiplication rule in particular). So to emulate complex numbers all you have to do is work with vectors of size two, and define the multiplication rule and the and nth power root rule for those.

In GM this can be done with lists. I don't see exactly what's wrong with writing your own algorithms for complex numbers that work on lists of size two.

Edited by Erik Leppen, 10 March 2011 - 06:18 PM.

• 0

### #5 Artaex Media

Artaex Media

Artaex Media

• GMC Member
• 1528 posts
• Version:GM8

Posted 10 March 2011 - 06:31 PM

I don't see why you want to calculate a negative square root.
I mean, sqrt(9) results in 3. (Because 3 x 3 = 9)
But, sqrt(-9) also results in 3, that's because -3 x -3 = 9.

Anaway, complex numbers indeed work a different way...
Maybe check out Wikipedia for that, maybe there's an alternative way of calculating it
EDIT: Typo...

-RefluxLtd

Edited by Reflux Entertainment, 10 March 2011 - 06:34 PM.

• -1

### #6 kalzme

kalzme

GMC Member

• GMC Member
• 327 posts
• Version:GM:Studio

Posted 10 March 2011 - 06:41 PM

• 0

### #7 paul23

paul23

GMC Member

• Global Moderators
• 3367 posts
• Version:GM8

Posted 10 March 2011 - 09:23 PM

What were you planning to use it for?

Also I don't know of any programming languate that natively supports complex numbers. Real, string, float, double, boole are default data types, I have never seen "complex" as a data type. This is to be expected, since a complex number is essentially a vector with two coordinates (the real and the imaginary part), following a few special rules of arithmetic (the multiplication rule in particular). So to emulate complex numbers all you have to do is work with vectors of size two, and define the multiplication rule and the and nth power root rule for those.

In GM this can be done with lists. I don't see exactly what's wrong with writing your own algorithms for complex numbers that work on lists of size two.

Matlab does, as does G/labview. However an imaginary number can actually be considered a simple vector with 2 components. Hence it is already in the suggestion/update list. (Adding the ability to create structures would enable this). Now only if we could overload functions (and operators) complex numbers would be as easy to use as real numbers. - The suggestion to use lists is pretty bad, it works but is very annoying to use (heck one can't even add lists and expect a simple vector addition). And because it is difficult to use it's error prone.
However for the calculations complex numbers DO help, and they should be considered a datatype just like "integers" and "floats" and "strings" are different datatypes.

@RE: you're wrong $\sqrt{-9}$ isn't defined in the natural space, because -3 rimes -3 results to 9.
$\sqrt{-9} = \sqrt{-1} * \sqrt{9}$ and by definition $\sqrt{-1} = i$
• 1

### #8 Rusky

Rusky

GMC Member

• New Member
• 2450 posts

Posted 11 March 2011 - 01:24 AM

Besides Python, Fortran and Common Lisp have native complex types and C, C++, C#, Perl, Ruby, OCaml and Haskell all have complex types in their standard libraries. Complex numbers can be used for a few things that might be useful in games or other programs you might want to write with GM- polar coordinates, fractals, etc. They wouldn't always be the best choice and it's understandable why they're not supported, but it would be nice to support at least the extensions to the language needed to add them.
• 0

### #9 xshortguy

xshortguy

GMC Member

• Global Moderators
• 4186 posts
• Version:GM:Studio

Posted 11 March 2011 - 02:54 AM

Well, aside from a program devoted to solving equations, what purpose would it serve? You can only plot real numbers on a 2D graph, and in the end, that's essentially all Game Maker is supposed to do. I can't think of any conceivable purpose 'i' would have in an ordinary game. Perhaps I'm just narrow-minded?

Compare the following:

$\begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{pmatrix} \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} a \cos \theta - b \sin \theta \\ a \sin \theta + b \cos \theta \end{pmatrix} \\ \exp(i\theta) (a + b i) = (\cos \theta + i \sin \theta)(a + b i) = a \cos \theta - b \sin \theta + (a \sin \theta + b \cos \theta) i$

In other words, planar rotations can be thought of as multiplication of complex numbers. In particular, if a complex number has a magnitude of one, then it corresponds strictly to a rotation in the complex plane.
• 1

### #10 NakedPaulToast

NakedPaulToast

GM Studio/Mac/Win

• GMC Member
• 7203 posts
• Version:GM:Studio

Posted 11 March 2011 - 08:52 PM

GM likely doesn't handle imainary numbers with the sqrt() function because all it really does is wrap Delphi's sqrt function.

In order to impliment it, Mark would have had to recreate that function. Given that imaginary numbers is not in large demand for a game creation tool, then it wasn't worth it.

The same can't be said for your calculator, where the ability to use imaginary numbers is in demand.
• 1

### #11 MasterOfKings

MasterOfKings

The True Master

• GMC Member
• 4888 posts
• Version:GM8

Posted 20 March 2011 - 02:01 AM

GM understands strings and reals. Imaginary numbers don't properly exist; as any two numbers of the same type (positive or negative) will never be negative. 'i' was introduced as to allow mathematicians overcome this.

But, ask yourself; in GM, a program designed and built to make simple 2D games, why would it need to understand the square root of -1? How many games would need it?

-MoK
• 0

### #12 GameGeisha

GameGeisha

GameGeisha

• GMC Member
• 2748 posts
• Version:GM:Studio

Posted 20 March 2011 - 02:56 AM

But, ask yourself; in GM, a program designed and built to make simple 2D games, why would it need to understand the square root of -1? How many games would need it?

If put into common practice, 2D games can benefit from complex numbers.

Complex numbers have applications in 2D geometry. Both the distance between two points and the angle from one point to another have elegant representations if the points are given as complex numbers. And as xshortguy has demonstrated, rotations work well with complex numbers.

You can also treat this as coupling x and y into one variable, allowing for easy storage in variables and use in various functions. Instead of putting in the coordinates as two arguments in a function, we can have the x coordinate as the real component and the y coordinate as the imaginary part, taking up one argument space. Now, search through the manual for functions that take coordinate values as arguments --- you can see that some of the arguments take up a lot of room.

If complex numbers are to be implemented into GM, I expect quaternions to be too --- they function in similar ways compared to complex numbers (except with two more components, j and k, whereas i^2 = j^2 = k^2 = ijk = -1). They greatly simplify coordinates used in 3D, especially with regard to rotations. And let's not forget how many argument spaces it would save for d3d_*() functions.

GameGeisha
• 0

### #13 Yourself

Yourself

The Ultimate Pronoun

• Retired Staff
• 7341 posts
• Version:Unknown

Posted 20 March 2011 - 07:37 AM

GM understands strings and reals. Imaginary numbers don't properly exist; as any two numbers of the same type (positive or negative) will never be negative. 'i' was introduced as to allow mathematicians overcome this.

What? Imaginary numbers exist just as much as any other type of number. They come up because real numbers aren't "complete" in the sense that a polynomial with real coefficients may not have any real roots. With complex numbers this is not the case. A polynomial with complex coefficients always has at least one complex root (and, in fact, counting multiplicity there are exactly n roots for an order n polynomial). They have a number of other useful properties which help them unify a lot of methods in mathematics. As others have mentioned they do serve some use for geometrical operations among other things.

That said, I don't really think they serve enough of a purpose to include them as a specialized type.
• 0

### #14 paul23

paul23

GMC Member

• Global Moderators
• 3367 posts
• Version:GM8

Posted 21 March 2011 - 02:00 PM

GM understands strings and reals. Imaginary numbers don't properly exist; as any two numbers of the same type (positive or negative) will never be negative. 'i' was introduced as to allow mathematicians overcome this.

What? Imaginary numbers exist just as much as any other type of number. They come up because real numbers aren't "complete" in the sense that a polynomial with real coefficients may not have any real roots. With complex numbers this is not the case. A polynomial with complex coefficients always has at least one complex root (and, in fact, counting multiplicity there are exactly n roots for an order n polynomial). They have a number of other useful properties which help them unify a lot of methods in mathematics. As others have mentioned they do serve some use for geometrical operations among other things.

That said, I don't really think they serve enough of a purpose to include them as a specialized type.

Also if "structures" would be possible in gamemaker, we can start to effectivelly extend the number of "datatypes".
• 0

### #15 Yourself

Yourself

The Ultimate Pronoun

• Retired Staff
• 7341 posts
• Version:Unknown

Posted 21 March 2011 - 06:48 PM

Also if "structures" would be possible in gamemaker, we can start to effectivelly extend the number of "datatypes".

• 0

### #16 xshortguy

xshortguy

GMC Member

• Global Moderators
• 4186 posts
• Version:GM:Studio

Posted 22 March 2011 - 05:28 AM

If Mike and Russell added operator overloading to Game Maker, I would build a statue of them out of mashed potatoes.
• 5

### #17 sabriath

sabriath

12013

• GMC Member
• 3147 posts

Posted 22 March 2011 - 08:01 AM

Instead of putting in the coordinates as two arguments in a function, we can have the x coordinate as the real component and the y coordinate as the imaginary part

Wait, what? So instead of using 2 variables (x and y) to denote position in cardinal space...you want to use...2 variables (real and imaginary) to denote position in an off-the-wall space. How is that any more efficient? I especially ask this because last I checked, the monitor can only take x/y cardinal position...so you would still have to convert whatever formula you had through an algorithm to get it.

xshortguy shows us a rotation using imaginary math...but you would still have to convert it into and out of the imaginary space. How is THAT efficient over using the normal dot products and such?

I'm sorry if I sound daft when it comes to the 'i' world...but wtf is it needed for exactly in game making (that other more efficient forms of keeping it in realistic space can provide)? I can see this being used to possibly show mandelbrot sets (or the like), but I don't see how that relates to gaming (unless you are doing a "where's waldo" for the mini-bulb game -- yeah, that'll be popular among the kids).

If complex numbers are to be implemented into GM, I expect quaternions to be too

Awesome, so instead of 3 variables (x, y, z), you want 4 (r, i, j, k) or possibly more?

Imaginary numbers exist just as much as any other type of number

Only in the minds of those willing to believe they can square root a negative number. I think MoK was stating it more in a realistic sense, that imaginary numbers are not actually "tangable" but a way to reduce other forms of math by going through a somewhat wormhole (imaginary space). As far as I know, 'i' is not an integral part of any microprocessor, so any methods you want will have to be done in software anyway...TI may make it a point to do extensive software on advanced trig/calc/wtfever concepts for their calculator (because their target audience are those in need of them), but I seriously doubt YYG will put that much effort into a game making engine (which doesn't target the heavy math community directly).

I mean, it made sense to me...but what do I know, I'm only a simpleton.
• 0

### #18 chance

chance

GMC Member

• Reviewer
• 5771 posts
• Version:GM:Studio

Posted 22 March 2011 - 12:35 PM

Imaginary numbers exist just as much as any other type of number

Only in the minds of those willing to believe they can square root a negative number.

In other words, in the minds of most educated people. Complex numbers are fundamental to every field of science and mathematics.

As far as I know, 'i' is not an integral part of any microprocessor

Nor is pi, e, or the square root of 2. So what does that have to do with it?

I'm not saying you're wrong about imaginary numbers not being critical for game making. But for god sakes, come up with some better arguments.

.

Edited by chance, 22 March 2011 - 12:36 PM.

• 0

### #19 MasterOfKings

MasterOfKings

The True Master

• GMC Member
• 4888 posts
• Version:GM8

Posted 22 March 2011 - 01:34 PM

@chance: Well, the square root of -1 didn't exist in earlier mathematics. They didn't just sit down and go "Oh my, what shall we do now?"; they made 'i'. Just because I said they don't properly exist; doesn't mean I think they're a waste of time. To a computer, trying to actual square root a negative number is impossible. We know otherwise.

And, um.. no one knows the final digit of pi (or e), so how do you expect someone to pre-program it into a micro-processor.

Regardless, I'm not saying complex numbers shouldn't be included; but as most of people that use GM are kids who have never even heard of them; is it reasonable for YYG to include them?

-MoK
• 0

### #20 paul23

paul23

GMC Member

• Global Moderators
• 3367 posts
• Version:GM8

Posted 22 March 2011 - 01:37 PM

@chance: Well, the square root of -1 didn't exist in earlier mathematics. They didn't just sit down and go "Oh my, what shall we do now?"; they made 'i'. Just because I said they don't properly exist; doesn't mean I think they're a waste of time. To a computer, trying to actual square root a negative number is impossible. We know otherwise.

And, um.. no one knows the final digit of pi (or e), so how do you expect someone to pre-program it into a micro-processor.

Regardless, I'm not saying complex numbers shouldn't be included; but as most of people that use GM are kids who have never even heard of them; is it reasonable for YYG to include them?

-MoK

"0" didn't exist in mathematics neither, or negative number at all for that matter..
• 1

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users