Jump to content


Photo

Imaginary Numbers


  • Please log in to reply
120 replies to this topic

#41 chance

chance

    GMC Member

  • Reviewer
  • 5837 posts
  • Version:GM:Studio

Posted 23 March 2011 - 06:46 PM

Why are programmers who are experienced and sophisticated enough to be working with planar rotations and complex data structures bothering with GM, with all its limitations, when they could be making their own engines in a more modern and efficient language?

Plenty of members here are capable of that. If they truly need something better, they can build it. But if GM does what they want, why spend time/effort developing something else?

Tailors don't necessarily make all their own clothes. Not every carpenter builds his own home. ;)


...including imaginary/complex number functionality into GM seems like it would be a lot of trouble on the developers' part to add something that would only be useful to people who, if they really MUST have it, would be perfectly capable of going elsewhere to get it...

Or they can build their own complex number system within GM. Either way, nobody here is saying GM really needs complex numbers, although a few have suggested some applications. I think we all agree on that.
  • 0

#42 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 23 March 2011 - 06:49 PM

Or, to put that question in a positive way, so as to seem less confrontational, what exactly does GM have to offer a programmer of that level?

Speed of development? GM is flexible enough and good enough to allow any 2d game or application to be made. I actually create more programs in GM than games. I have some experience with C++ and OpenGL and I just don't want to waste 2 days just to make the very basics of the program. In GM I can have a working prototype 3 days after beginning of the development and ready program about a week later. That is why people who have experience in other languages use GM a lot. Now when GM can run on many platforms it is almost stupid to make games in any other development tool.
  • 0

#43 FakeKraid

FakeKraid

    Total Fraud

  • GMC Member
  • 57 posts
  • Version:GM8

Posted 23 March 2011 - 09:59 PM

Speed of development? GM is flexible enough and good enough to allow any 2d game or application to be made. I actually create more programs in GM than games. I have some experience with C++ and OpenGL and I just don't want to waste 2 days just to make the very basics of the program. In GM I can have a working prototype 3 days after beginning of the development and ready program about a week later. That is why people who have experience in other languages use GM a lot. Now when GM can run on many platforms it is almost stupid to make games in any other development tool.


Ah, I see. I had no idea GM was that generally useful. I mean, it's certainly been a great help to me, but I didn't realize it was that good. That makes me feel better about using it. (:

Plenty of members here are capable of that. If they truly need something better, they can build it. But if GM does what they want, why spend time/effort developing something else?

Tailors don't necessarily make all their own clothes. Not every carpenter builds his own home.


I sort of had a feeling that might be the case, but I wanted to ask anyway.

Edited by FakeKraid, 23 March 2011 - 10:05 PM.

  • 0

#44 Gamer3D

Gamer3D

    Human* me = this;

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

Posted 24 March 2011 - 06:34 AM

Ah, I see. I had no idea GM was that generally useful. I mean, it's certainly been a great help to me, but I didn't realize it was that good. That makes me feel better about using it. (:

It's not that it's that good. It uses a slow interpreter, has important parts of it programmed naively, and doesn't have many advanced language features.

I use it because it doesn't need much effort. If I want to create something that works fast, I'll do it in C++.

Anyway, back to the topic at hand:
  • Pros of implementing complex numbers: Easier computation of roots of cubic/quartic equations, some other computations.
  • Cons: Adding the proper constant i would break scripts that use that to increment (I use i as a temporary variable every so often) and would break many extensions, specifically the ones that use GMAPI and my priority queues, which would then be receiving a different input for the same variables. Ambiguities would also occur. For example, is (2 - i > 1)? Extra checks before functions such as graphics would slow GM (though not significantly, because all GM function calls are already slow) as would the additional calculations every time a variable is multiplied/added/subtracted/divided/square-rooted/exponentiated/sined/cosined/tangented/etc.

In short, the disadvantages, especially the ambiguity problem, make this not worth putting into Game Maker and in fact make it worthwhile to avoid adding this.

[sarcasm]Also, if we add complex numbers, why stop there? Quaternions would be nice. Same disadvantages as before (and more), but could simplify those 8 calculations where they are used.[/sarcasm]
  • 0

#45 xshortguy

xshortguy

    GMC Member

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

Posted 24 March 2011 - 08:57 AM

Ambiguities would also occur. For example, is (2 - i > 1)?


There's no ambiguity there. The complex numbers don't have that partial ordering relationship.

One can use the capital letter I for imaginary numbers, or even a delimiter such as ~. A + ~B = A + BI. However, it would make more sense to simply add a struct to do this.

Also, if we add complex numbers, why stop there? Quaternions would be nice. Same disadvantages as before (and more), but could simplify those 8 calculations where they are used.


I wish there would be native support functions for both matrices and quaternions, because they are very useful. They won't be inline such as a + b*i + c*j + d*k, but rather like classes in C++.
  • 1

#46 Yourself

Yourself

    The Ultimate Pronoun

  • Retired Staff
  • 7343 posts
  • Version:Unknown

Posted 24 March 2011 - 09:03 AM

Ambiguities would also occur. For example, is (2 - i > 1)?


That's no more ambiguous than "cat" > 4. The complex numbers are not an ordered field, so it's meaningless to try to compare them.

Extra checks before functions such as graphics would slow GM (though not significantly, because all GM function calls are already slow)


You mean the same checks that GM already performs to make sure you're not passing in a string?

as would the additional calculations every time a variable is multiplied/added/subtracted/divided/square-rooted/exponentiated/ sined/cosined/tangented/etc.


How is this relevant? The data type is more computationally expensive, yes, but that doesn't matter since we're not using it instead of existing data types. We'd be using it in situations that the real numbers simply can't handle period. The fact that complex numbers would be slower in cases where you wouldn't use complex numbers is a non-sequitur.

Also, if we add complex numbers, why stop there? Quaternions would be nice. Same disadvantages as before (and more), but could simplify those 8 calculations where they are used.


Oh look, another person who's never tried to handle rotations in 3D and especially never tried to handle integrating the equations of motion of a rigid body in 3D (which is really about the simplest rotation model you can get). Quaternions are computationally less expensive, take up less space, and are more numerically stable than representing rotations in matrix form. Oh, and remember off the top of your head how to construct a rotation matrix based on an axis and an angle? Probably not, since it's non-trivial. Fortunately that's another thing quaternions happen to be really good at. Hell, they even make it easy to smoothly rotate from one orientation to another without hitting any of the nasty singularities you get from other representations (which also cause that whole nasty gimbal lock issue).
  • 2

#47 sabriath

sabriath

    12013

  • GMC Member
  • 3149 posts

Posted 24 March 2011 - 12:50 PM

Oh look, another person who's never tried to handle rotations in 3D and especially never tried to handle integrating the equations of motion of a rigid body in 3D (which is really about the simplest rotation model you can get). Quaternions are computationally less expensive, take up less space, and are more numerically stable than representing rotations in matrix form. Oh, and remember off the top of your head how to construct a rotation matrix based on an axis and an angle? Probably not, since it's non-trivial. Fortunately that's another thing quaternions happen to be really good at. Hell, they even make it easy to smoothly rotate from one orientation to another without hitting any of the nasty singularities you get from other representations (which also cause that whole nasty gimbal lock issue).


Given a quaternion formula of z=a+bi+cj+dk, where |z|=1, the normal representation of that rotation matrix in real math would be:

[[a^+b^-c^-d^, 2bc-2ad,     2bd+2ac    ]
 [2bc+2ad,     a^-b^+c^-d^, 2cd-2ab    ]
 [2bd-2ac,     2cd+2ab,     a^-b^-c^+d^]]

where '^' means squared

I will agree that it takes less space in a rotational form....but how would you calculate z=a+bi+cj+dk on a computer so that you move a rigid body to its next destination? By...using the matrix above? So you save variable space for all of a microsecond just to put it through the above calculation anyway?

Besides that, the above calculation was just to turn quaternion into orthogonal space....a rotation inside that space first without going the quaternion route doesn't yield as much complexity, it's simply:

rotation around x

[[ 1,      0,      0     ]
 [ 0,      cos(a), sin(a)]
 [ 0,     -sin(a), cos(a)]]

rotation around y

[[ cos(a), 0,     -sin(a)]
 [ 0,      1,      0     ]
 [ sin(a), 0,      cos(a)]]

rotation around z

[[ cos(a), sin(a), 0     ]
 [-sin(a), cos(a), 0     ]
 [0,       0,      1     ]]

Rotating around an arbitrary line, you simply normalize the vector (another matrix) and apply as such. You already get the answer right away, rather than having to use the previous transformation JUST to get out of quaternion calculations in order for the computer to get a physical x/y location to draw to.

This all seems moot anyway since d3d can do transformations for you, orthogonally, can't it? Or did I just imagine d3d_transform_set_rotation_* functions? *shrugs* oh well, I'm stupid!


edit: and about gimbal lock, who cares? If a rigid body is hit on its side to rotate around its x-axis, then gets hit again to move about the y-axis...and a third time to move around the z-axis, then it would properly rotate as per physics rules without violation of any laws, even if it "seems" to lock on a plane for 2 rotations at a time every 10 or so. That's normal for all I care, not seeing a downside here.

Edited by sabriath, 24 March 2011 - 12:59 PM.

  • 0

#48 Yourself

Yourself

    The Ultimate Pronoun

  • Retired Staff
  • 7343 posts
  • Version:Unknown

Posted 24 March 2011 - 07:54 PM

will agree that it takes less space in a rotational form....but how would you calculate z=a+bi+cj+dk on a computer so that you move a rigid body to its next destination?


To rotate about an axis <u, v, w> by angle a, the quaternion is given by <cos(a/2), sin(a/2) u, sin(a/2) v, sin(a/2) w>. I don't know how you managed to look up conversion to a rotation matrix without also looking up this formula. And if you don't want to resort to converting to a rotation matrix (and instead use quaternions all the way through), you represent a vector as a quaternion, v, with 0 real part and then perform the rotation this way:

v' = q v q-1

Where q is the quaternion representing the rotation. Converting to a matrix, especially if you have to transform a lot of points (for example in the case of a rigid body) would be cheaper.

You're also ignoring a large number of the advantages I mentioned. For example, numerical stability. Because of rounding errors matrix multiplication can result in a transformation matrix that is no longer orthogonal and it's not trivial to orthogonalize a matrix so that it still represents an appropriate rotation. Quaternions don't suffer from this problem since they can be trivially normalized and unit quaternions *always* represent a valid rotation.

You also didn't give a rotation matrix representing a rotation about an arbitrary axis.

You also seem to think that you'd use quaternions to represent a single simple rotation and that's not what you'd do. Like I said, they simplify the representation of an object's orientation which is useful when it's time varying (as in the case of rigid bodies or cameras that need to rotate smoothly from one orientation to another).

a rotation inside that space first without going the quaternion route doesn't yield as much complexity, it's simply:


Which is an Euler angle representation which suffers from gimbal lock since it doesn't represent a unique rotation.

That's normal for all I care, not seeing a downside here.


That's because you don't know what you're talking about. Gimbal lock wouldn't be a problem provided you integrated the rotational equations of motion in such a way that it wasn't.
  • 2

#49 sabriath

sabriath

    12013

  • GMC Member
  • 3149 posts

Posted 24 March 2011 - 09:42 PM

@Yourself: You provided the methods on which to rotate in the u,v,w space, which is not known to the computer....you still have rounding errors not only in that space, but when converting to the x,y,z so that the computer can actually display it on a monitor. Rounding errors will always be apparent in any system because it is just not feasable to be storing an infinite amount of decimal places, so why bring that up?

As for the matrix, you are calculating it ahead of time, once all the transformations have been completed, you only have 1 matrix with 1 set of values finished (until a new transformation must be applied). In quaternion, whenever you actually finish with all those calculations, you still have to apply the first complex matrix to the equation in order to switch it into x,y,z space....for every point.

Don't understand what I mean? Ok...let's say that there is a camera in 3D at the origin pointing toward (0,0,1), and there is a point located at (1,1,15). Find the matrix that would apply a rotation around the line that passes through points (0,0,0) and (1,2,3) as well as the quaternion representation, this will represent the "space" taken up by the system. I have already agreed that quaternion does take up less space.

Now show the algorithms to actually apply the above calculations in order to display this to the "camera" (screen) that has a 800x600 display and a 4 foot viewing distance. I'm willing to bet that the matrix will beat the quaternion in efficiency here, but since the only thing I have to go on is that first complex matrix I showed, I have no reason to think otherwise....until someone shows me (as I have stated from the beginning).

That's because you don't know what you're talking about

Then why don't you actually provide something to show how I'm wrong, rather than just stating I'm wrong? I've provided formulas at least, and the only other formulas provided were in an imaginary space. Last time I checked, a graphics card can't display imaginary space unless you transform it....or did ATI come up with a way to open a rift in spacetime?
  • 0

#50 chance

chance

    GMC Member

  • Reviewer
  • 5837 posts
  • Version:GM:Studio

Posted 24 March 2011 - 11:04 PM

That's because you don't know what you're talking about

Then why don't you actually provide something to show how I'm wrong, rather than just stating I'm wrong?

Because he'd be wasting his time. You're arguing against something that's proven and widely accepted by mathematicians and CG programmers for decades.

It's like you're demanding proof that Earth is round. :D Why should anyone bother?
  • 1

#51 sabriath

sabriath

    12013

  • GMC Member
  • 3149 posts

Posted 25 March 2011 - 12:12 AM

Because he'd be wasting his time. You're arguing against something that's proven and widely accepted by mathematicians and CG programmers for decades.

It's like you're demanding proof that Earth is round. Why should anyone bother?

No I'm not....because I use to work with 3D math all the time, and NEVER used quaternions. I didn't even know about them being viable until this topic even existed, and I am _seriously_ curious as to how it would be even possible. I want to see it in action, so that I can better judge its efficiency on a system.

I have not been provided with it, so I will continue to assume that matrices are better. I would have thought that if quaternions were better, that graphics cards would contain them? Or am I wrong there too...because I sure can't find any API directly connecting them to the system (then again, there are thousands of functions to sift through, so I may have overlooked them). Feel free to speak up, because again, I'm curious.
  • 0

#52 Rusky

Rusky

    GMC Member

  • New Member
  • 2450 posts

Posted 25 March 2011 - 03:50 PM

You do realize a complex number would be represented in the machine exactly the same way as an x/y pair, right?
  • 0

#53 chance

chance

    GMC Member

  • Reviewer
  • 5837 posts
  • Version:GM:Studio

Posted 25 March 2011 - 04:42 PM

I am _seriously_ curious as to how it would be even possible. I want to see it in action, so that I can better judge its efficiency on a system.

I assumed you were dismissing the usefulness of quaternion rotations, just as you dismissed the usefulness of complex numbers earlier in this topic.

But if you're serious about wanting to understand them, there's tons of sites that explain how to use them. Just Google "quaternion rotation". If you already understand the mathematics of general rotation matrices, you won't have any trouble understanding quaternion rotation.
  • 0

#54 Smiley Showdown

Smiley Showdown

    GMC Member

  • New Member
  • 10 posts

Posted 03 April 2011 - 05:38 PM

I understand that this debate is fun and all, but what i want to know is what this will be used for and what implications it has for programming, NOT a debate about the viability/importance of imaginary numbers. These forums are intended to be used for GM discussions, not math debates. :angry: :angry: :angry:
  • 0

#55 Yourself

Yourself

    The Ultimate Pronoun

  • Retired Staff
  • 7343 posts
  • Version:Unknown

Posted 03 April 2011 - 06:35 PM

but what i want to know is what this will be used for and what implications it has for programming


Then read the topic. Their applications have been adequately described already. The topic's also been dead for over a week.
  • 0

#56 DerrenFreeman

DerrenFreeman

    GMC Member

  • New Member
  • 16 posts

Posted 01 May 2011 - 06:21 PM

I am not here to comment on the usefulness or validity of complex numbers or quaternions, (although I do believe they are both valid and useful), and I am just here to state the following quote.

Neither Complex Numbers or Quaternions would be useful to the average GML user, however, if one is educated, and curious enough, to want or use them, then they are educated and curious enough to be able to implement such ideas into Game Maker by themself. Because of this, I contend it would be a waste of time, and (arguably) processing power, to natively input them into Game Maker.

-Derren Freeman


Yes, I am quoting myself, and please feel free to quote it again.
  • 0

#57 Gamer3D

Gamer3D

    Human* me = this;

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

Posted 01 May 2011 - 08:59 PM

Ambiguities would also occur. For example, is (2 - i > 1)?


That's no more ambiguous than "cat" > 4. The complex numbers are not an ordered field, so it's meaningless to try to compare them.

So I used the wrong term. You noticed. Congratulations.

I guess I've been assuming that complex numbers would replace the current variables. At some point, some noob is bound to try to compare 2 complex numbers.

Extra checks before functions such as graphics would slow GM (though not significantly, because all GM function calls are already slow)

You mean the same checks that GM already performs to make sure you're not passing in a string?

Fair enough. Doesn't invalidate what I said though.

How is this relevant? The data type is more computationally expensive, yes, but that doesn't matter since we're not using it instead of existing data types. We'd be using it in situations that the real numbers simply can't handle period. The fact that complex numbers would be slower in cases where you wouldn't use complex numbers is a non-sequitur.

With the problem here being that 2% of Game Maker games would actually benefit from this...
This goes along with my assumption that to add complex numbers, YoYo would just add another double to the current variable scheme and change some functions.

Also, if we add complex numbers, why stop there? Quaternions would be nice. Same disadvantages as before (and more), but could simplify those 8 calculations where they are used.


Oh look, another person who's never tried to handle rotations in 3D and especially never tried to handle integrating the equations of motion of a rigid body in 3D (which is really about the simplest rotation model you can get). Quaternions are computationally less expensive, take up less space, and are more numerically stable than representing rotations in matrix form. Oh, and remember off the top of your head how to construct a rotation matrix based on an axis and an angle? Probably not, since it's non-trivial. Fortunately that's another thing quaternions happen to be really good at. Hell, they even make it easy to smoothly rotate from one orientation to another without hitting any of the nasty singularities you get from other representations (which also cause that whole nasty gimbal lock issue).


Actually, I have used quaternions. Often. They take up less space than the corresponding 3x3 matrix, can be normalized more easily, and their multiplication has fewer operations than a corresponding 3x3 matrix multiplication. They do take more operations to rotate a vector though.

I was trying to raise the question of how much should be implemented as a permanent feature of GM. Complex numbers are infinitely useful, but probably won't be needed often enough in the 2D platformers that GM caters to.

I should have use octonians as my example of something that Game Maker doesn't need.




No I'm not....because I use to work with 3D math all the time, and NEVER used quaternions. I didn't even know about them being viable until this topic even existed, and I am _seriously_ curious as to how it would be even possible. I want to see it in action, so that I can better judge its efficiency on a system.

I have not been provided with it, so I will continue to assume that matrices are better. I would have thought that if quaternions were better, that graphics cards would contain them? Or am I wrong there too...because I sure can't find any API directly connecting them to the system (then again, there are thousands of functions to sift through, so I may have overlooked them). Feel free to speak up, because again, I'm curious.


Matrices have their place. As do quaternions. When it comes to rotating vectors (for example, the vertices in a mesh), then matrices are more efficient. If you want to make sure that your spatial representation doesn't gradually stop being a rotation due to round-off error, then quaternions are a good way to go. If you need both, a hybrid approach is often most useful (use quaternions, then create a matrix when multiple point rotations are needed).

You don't NEED to work with quaternions. It's just more efficient in many cases.


Also, I know this was on page 2, but

Yes, I can. Irrational numbers might have some precision issues, but they are tangable enough to make an effort at hitting the mark...for example, asking me to present the square-root of 2 from a piece of paper, I can cut out an area roughly equal to it (you cannot do that with 'i'). As for negative numbers, that's simply borrowing, if you say "draw me negative 2 circles," then I would turn to you and say "draw me 2 circles"....now they are negative by reverse....how about that 'i'...nope, still can't do that.

Draw me a square of area -1. The sides are now i, because forming a square with those sides will yield an area of -1.
  • 0

#58 sabriath

sabriath

    12013

  • GMC Member
  • 3149 posts

Posted 01 May 2011 - 09:43 PM

Draw me a square of area -1

And how am I suppose to do that? "-1" in hypothetical terms is the same as "borrowing," so if I borrow 1 piece of paper from you, than you have '-1' pieces of paper. If the paper were square, then one edge would still be '1', not 'i' because it's like -sqrt(1) in the same hypothetical sense. There's no actual way to "draw" or come up with a way to physically show sqrt(-1).

This is all moot now, Yourself and others have put forth their all-knowing opinions on the situation. Although I do not agree (because I still haven't been shown, nor found any documentation on how it simplifies anything since no computer monitor takes in quaternion calculations as an input to derive a pixel position), it really doesn't matter because they know more than me in the mathematics area.
  • 0

#59 xshortguy

xshortguy

    GMC Member

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

Posted 01 May 2011 - 09:55 PM

A square of area -1 is the same as a square of area 1, except the "orientation" is different. (Areas can have a sense of orientation.)
  • 0

#60 Gamer3D

Gamer3D

    Human* me = this;

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

Posted 01 May 2011 - 11:34 PM

Draw me a square of area -1

And how am I suppose to do that? "-1" in hypothetical terms is the same as "borrowing," so if I borrow 1 piece of paper from you, than you have '-1' pieces of paper. If the paper were square, then one edge would still be '1', not 'i' because it's like -sqrt(1) in the same hypothetical sense. There's no actual way to "draw" or come up with a way to physically show sqrt(-1).

So your "negative circles" argument is invalid. If you ever get a chance, take a course in abstract algebra. Near the end, you will encounter a proof that the complex numbers are algebraically closed (I.E. every polynomial with complex coefficients has complex roots).

This is all moot now, Yourself and others have put forth their all-knowing opinions on the situation. Although I do not agree (because I still haven't been shown, nor found any documentation on how it simplifies anything since no computer monitor takes in quaternion calculations as an input to derive a pixel position), it really doesn't matter because they know more than me in the mathematics area.

It simplifies:
  • Memory. Quaternion takes 4 times what a scalar takes, equivalent matrix takes 9.
  • Multiplication: Quaternion multiplication is 28 scalar operations. Matrix is 45.
  • Normalization. Quaternion takes 1 sqrt, 4 divisions. Matrix takes more, with the exact number depending on the method.
So basically it's a good way to handle rotations of an object. Once you want to rotate multiple vectors though, it's best to get a matrix from it and use that.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users