Math in programming

Pages: 12
Sep 25, 2010 at 3:49pm
Wrong part of the forum? I don't know. I couldn't find a better place. Maybe a mod can?

Question:
What kind of math is needed in programming? Is it hard math in every area of programming or are there programming areas that are less math-based? Is 3D graphics programming as hard as they say?

I just want to know because I'm not really a math genius and would like to know if I should just forget about a career in programming (newbie right now, but it's really fun!). Of course game programming is what I would like to do the most but I know that there is alot of competition in that area, so that may blow it but if you don't count that and only count in the math itself. Is it hard?

Just be honest. I've seen alot of people asking questions before (not here, though, nor about this) where people get these cuddly answers that don't say it as it is that are just to make them feel better. I'm not after cuddly answers that say that it's not hard just to make me feel better. Say it as it is.

Thanks.
Last edited on Sep 25, 2010 at 3:49pm
Sep 25, 2010 at 3:54pm
Required math in programming: Arithmetic. Algebra is useful, though, because it teaches problem-solving.

Is it hard math in every area?: Nope. The mathematics increases when you start getting more advanced but at a newer level I don't think learning discrete mathematics is really necessary. You could still benefit from it, though.

Is 3D graphics programming as hard as some say?: No, if you have the right library. Irrlicht for example makes it really easy, but pure OpenGL can be difficult if you're a sane programmer.
http://irrlicht.sourceforge.net/
Basic requirements to use Irrlicht: knowledge of how to use functions, classes, and enumerations, and the actual library. IIRC.

P.S.- There are no mods on this forum. There are a few members of staff who turn up once in a blue moon that have admin powers, though.

-Albatross
Last edited on Sep 25, 2010 at 3:58pm
Sep 25, 2010 at 4:12pm
Ok, isn't Irrlicht already an engine? Isn't that kind of cheating?

Ok, so it's that kind of math that is necessary. What is discrete math, though? Never really understood that, altough I've heard of it before.

Ok, no mods. Noted til' next time. :P
Last edited on Sep 25, 2010 at 7:06pm
Sep 25, 2010 at 4:51pm
closed account (Lv0f92yv)
http://en.wikipedia.org/wiki/Discrete_mathematics

In general discrete math is good for your problem solving abilities - it helps develop them.
Sep 25, 2010 at 7:07pm
Oh, ok, I think i get it. Thanks.
Sep 25, 2010 at 7:18pm
Ok, isn't Irrlicht already an engine? Isn't that kind of cheating?
C++ is a 3rd level language, Isn't that kind of cheating? You should write in binary.
Lol, see what i mean? Nothing you're doing with C++ isn't 'cheating' in some way. What do you think OpenGL is? Its a graphics library, just lower level.


Anyway: Nah, its not always so easy, if you get into big projects. Especially towards games, then trigonometry is useful; though, you could always find a solution on Google for the really hard things, because the odds are, someones done it before.
Sep 25, 2010 at 7:27pm
And another question. I've seen some "behind the scenes" of game developement, from when I've bought a collectors's edition. And there, they make characters and such in some kind of program where they draw them in 3D (something like CAD?). Do they import them such as sprites in 2D developement? Then why would you need math for 3D programming? I have some theories, like maybe they need to program the 3D "space" of the game. Or have I misunderstood something?
Sep 25, 2010 at 7:45pm
closed account (Lv0f92yv)
Anyone here play Valve games? Valve's source engine was one (if not the) first physics engine.

I don't work for valve, but if I had to guess, they probably had some very high level mathematics involved in their game engine to model physics in a virtual world.

If you get into game engine design or low level graphics programming, I hear mathemaics becomes very important.

Another field where mathematics is highly utilized is encryption. At that point, it is almost more of a mathematical application than a programming application.
Sep 25, 2010 at 7:52pm
Game programming is nothing but math. You have to manage player position (x, y, z), rotating a 3D object requires a trig function. AI requires a ridiculous amount of trig (rotating to face another object).
Games also need physics:
Mass
Time
Position
Velocity - V = ds/dt (change in position, over change in time)
Acceleration - A = dv/dt (change in velocity, over change in time)
Force - F = m*a
Collisions - Angle of incidence = angle of reflection (on a flat surface)
Gravity - F = (G*m1*m2)/r^2 (where m1 and m2 are any two objects with mass, G is the gravitational constant, and r is the distance between two objects
Friction - Ff = m*g*us

.. i could probably go on
Sep 25, 2010 at 8:19pm
closed account (Lv0f92yv)
Not to mention that efficient AI path finding is very mathematical.

Basically, the answer to OP's question lies in what the OP ants to pursue down the road. More math won't hurt.
Sep 25, 2010 at 9:14pm
I'll have to disagree with Albatross on this. Knowledge of Discrete Math is one of the most useful, essential skills any computer programmer can have. I am only a beginner myself and use many concepts I learned in a freshman level college discrete mathematics course. Good thing though, in general it is not hard, just different. Though no two discrete maths courses are the same, in general they cover such topics as number theory, cryptography, mathematical proofs, mathematical induction and what I consider to be one of the most important functions that I use in nearly every program that I have ever wrote, is modulous, i.e. simply finding the remainder of a division operation.

I have yet to encounter a problem where I would have needed knowledge of calculus to solve however.
Sep 25, 2010 at 9:19pm
closed account (Lv0f92yv)
wtf brings up a good point - I remember when I had some basic number theory and probability in HS, I remember liking it more than other types of mathematics because I could relate it to programming.
Sep 25, 2010 at 10:42pm
Did you read my post, wtf? Hmm? I only stated that Discrete Mathematics was not necessary at a lower level, but the OP could still benefit from it. Maybe I should have stated more precisely how much one could benefit from it (a lot). ;)

Or are you implying that it is necessary? If so I disagree. I started my programming career with no knowledge of Discrete Mathematics (at all) and yet I was still able to write some pretty nice and well-optimized programs even though I may not have understood the mathematics behind them. Admittedly, my programming improved since I took a college course, but it is not necessary IMO.

-Albatross
Last edited on Sep 25, 2010 at 10:45pm
Sep 26, 2010 at 1:12pm
Thumper: OpenGL is more "from scratch" from what I've heard, but sure it is "cheating", too. I just meant that Irrlicht have already done pretty much of the work. Or am I wrong?
And to be honest, I would think it would be way more cool to write in binary :P. Scr*w the inventor of compilers ;).

Thumper again: That doesn't seem like very hard math, though. Is it? I mean, you don't have to come up with the formulas yourself, you just have to remember them. Or is there more math that is harder? Or is it harder than it looks?

We have an optional course in discrete mathematics at my school. I should maybe consider it.
It seems like a pretty fun course, since - as Desh said - I can probably relate to programming.

Well, I have other options of careers. I can always keep programming at a hobbyist level if my knowledge in maths would be insufficient for a career.

Is there anyone here who didn't consider themselves very good at math when they were younger and can share their experience? Hobbyist as professional, doesn't matter. Programming at all is enough.

Thanks for all of the answers.
Last edited on Sep 26, 2010 at 1:19pm
Sep 26, 2010 at 1:23pm
There's a lot of things that go unspoken; collision is one of the harder topics (along with AI, which is a LOT more difficult) that can (and has) a dozen of books written about just the basics. The problem you're having is that you deal with 3 dimensions, meaning that things can turn over any angle in a real-world simulating engine.

Desh wrote:
Valve's source engine was one (if not the) first physics engine.
The Source engine is not a physics engine. The Source engine is a package of AI, a lot of basic entities, a bsp-reader (that's the map extension file), rendering engine and more. If I recall correctly, the sound and physics engines are not made by Valve. (I could be wrong, though)
The physics engine is Havok, and I don't recall the sound engine.
In the end, the Source Engine is "just" a re-write of the Unreal Engine.
Sep 26, 2010 at 2:28pm
Calsong wrote:
That doesn't seem like very hard math, though. Is it? I mean, you don't have to come up with the formulas yourself, you just have to remember them. Or is there more math that is harder? Or is it harder than it looks?
I'm not a genius in this but yes it is harder than it looks.
Sep 26, 2010 at 2:30pm
@Calsong
Lol, you're like me. I hate working off of things other people made; it's like a never ending quest to figure out how it all works. The thing is, at some point you just learn to suck it up and accept what you have. If there's no need to make something harder on yourself, then why do it? Irrlicht is a good library; may as well put it to good use.

It's not exactly hard. Implementing it is the harder thing. There is more more math. Lets face it, behind the circuits, computers are purely math.
i'll give what I'm currently working on as an example
velocity_x += thrust * sin(rotation*pi/180); << blew my mind.
Some of the simplest actions (in this case, calculating how fast i'm moving (its from an asteroids game)) require odd math.

and the AI code i use to make enemy's rotate toward a point
1
2
3
4
5
		float deltax = player.GetPosition().x - spr.GetPosition().x;
		float deltay = player.GetPosition().y - spr.GetPosition().y;
		float rotate = (atan2(deltay, deltax));
		rotate = rotate * (180/M_PI);
		spr.SetRotation(-(rotate));

Lotsa math.
Sep 26, 2010 at 3:03pm
There is no hard math in programing. There are mostly linear equations, sometimes trigonometry. If you get into low level 3d programing, there are lots of matrices, but if you use some engine, you don't really need to understand them. You could probably find an area where hard math is needed, bet really you don't have to.
Also, if something looks difficult now, bear in mind that you won't be 16 forever. After a couple of years it will all look trivial.
Sep 26, 2010 at 3:26pm
closed account (Lv0f92yv)
The physics engine is Havok, and I don't recall the sound engine.


I stand corrected, I forgot about Havok.

There is no hard math in programing

I suppose this depends on what 'hard' means to certain people, but I disagree. I wouldn't bother trying to create my own encryption algorithm without an extensive math background. These days, strong encryption schemes are almost entirely based on relatively complex mathematical theorems, not to mention proving their security involves almost pure mathematics.
Last edited on Sep 26, 2010 at 3:30pm
Sep 26, 2010 at 6:02pm
Hamsterman is right, in general...

Most math in practical programming is not that difficult. For example, most 3D calculations are just matrix transforms. The trig is really not that hard (HS level). However, in pure computer science, some of the discrete math can get very abstract, quickly. Even practical encryption and randomness theory can get into some very deep number theory (what is a good random number?).

That is not to say that there is no hard math. (Desh is also right!)

If you check out statistical programs like R or Matlab, there are hundreds of packages written by mathematicians/statisticians that have huge scope and depth. There are standard college-level engineering ODE, PDE, SDE solvers or matrix operators. But there are also plenty of very obscure transforms and theories on why you should use X and not Y. You can get as specialized as you like - I was reading about Sobol sequences used for Monte Carlo simulations the other day. Surprisingly, there are practical engineering applications for many of these seemingly obscure math concepts.

Ultimately, the amount and kind of math depends on the domain that you pick in programming.
But in general, it's safe to say: it never hurts to know more math.

A computer is basically a very sophisticated calculator.
So how hard the math is depends on what problem you are trying to solve.
Last edited on Sep 26, 2010 at 6:48pm
Pages: 12