Temple of The Roguelike Forums

Development => Programming => Topic started by: Krice on February 11, 2015, 02:42:48 PM

Title: How to improve math skills?
Post by: Krice on February 11, 2015, 02:42:48 PM
Math is important in some aspects of game programming and I've always found myself less good in math. Is there a good book or books about math I could read over and over again in vague hope that I could improve my math skill, possibly even reach the next skill level.
Title: Re: How to improve math skills?
Post by: Quendus on February 11, 2015, 04:48:47 PM
What kind of maths do you mean? There are many different fields which are more or less relevant to different genres and different aspects of game development.

For traditional roguelikes, I guess the most relevant fields would be probability/statistics, basic set theory, basic graph theory, and computational complexity? I don't know what books I would recommend as introductions to those fields, though.
Title: Re: How to improve math skills?
Post by: mushroom patch on February 11, 2015, 05:30:22 PM
I'd say probability theory and combinatorics, graph theory, algorithms, and computational geometry are most relevant to roguelikes. Although it's not exactly a book about algorithms, SICP is worth reading. Graph theory is sort of a deceptive phrase because it's not like there's a single canonical body of knowledge to look at -- it's extremely diverse and any introductory text primarily reflects the interests of the author rather than what are really the most important things to know for any particular purpose. You at least want to have the basic vocabulary -- graphs, trees, paths, cycles, planarity, multiple connectedness etc. Certain algorithms in graph theory are worth knowing about, e.g. min/max spanning trees, Dijkstra, A-star. Some probabilistic graph theory can provide useful intuition relevant to map generation.

I don't know any good introductory books on probability or combinatorics that are aimed at a general audience. You could probably just go to a used book store near a university campus and pick up something that's used for an introductory course in probability. You can probably find something relatively old and cheap that will serve your purposes.
Title: Re: How to improve math skills?
Post by: Krice on February 12, 2015, 04:43:14 PM
You could probably just go to a used book store near a university campus and pick up something that's used for an introductory course in probability.

You know I live in a middle of nowhere, right? Well, I guess I just browse some interesting looking books and order them. I like books anyway and have a growing library of them.
Title: Re: How to improve math skills?
Post by: jlund3 on February 12, 2015, 05:15:59 PM
You know I live in a middle of nowhere, right?

If there is no good library near you, there are quite a few good books and other useful resources online as well. For example, Algorithms by Dasgupta et al is provided by the authors as free pdf (http://beust.com/algorithms.pdf (http://beust.com/algorithms.pdf)). This book is used in various CS courses as the first exposure to complexity analysis, and basic algorithms like sorting and graph stuff. If you have an interest more specific than just "maths", I suspect better recommendations could be made.
Title: Re: How to improve math skills?
Post by: Krice on February 12, 2015, 06:43:24 PM
How can I know what I want if I don't know anything about math.
Title: Re: How to improve math skills?
Post by: jlund3 on February 12, 2015, 07:22:55 PM
How can I know what I want if I don't know anything about math.

If you really are Jon Snow when it comes to math, then I suggest that you start with Principia Mathematica. It attempts to describe all the basics of mathematics, and should serve as a foundation for all the other useful maths you might need for your roguelike endeavors. Volume I can be found at the internet archive here: https://archive.org/details/PrincipiaMathematicaVolumeI (https://archive.org/details/PrincipiaMathematicaVolumeI)
Title: Re: How to improve math skills?
Post by: mushroom patch on February 12, 2015, 08:04:29 PM
lol
Title: Re: How to improve math skills?
Post by: Omnivore on February 12, 2015, 11:21:05 PM
Try http://www.zweigmedia.com/tuts/index.html?lang=en (http://www.zweigmedia.com/tuts/index.html?lang=en), online tutorials, looks decent.  Also look for discrete mathematics (aka one definition of Finite mathematics).
Title: Re: How to improve math skills?
Post by: Krice on February 13, 2015, 02:54:20 PM
It would be great to read about math in form of explanations: why something is used in math and how it's used to solve something. I think that online tutorial is an example of reverse situation which assumes you understand and read "math".
Title: Re: How to improve math skills?
Post by: mushroom patch on February 13, 2015, 05:03:28 PM
It's hard to tell what you're asking. I mean if you're really talking basic math, you could, maybe even should, try taking a night course somewhere. If you want to learn stuff that's actually specific to programming roguelikes and helps one with the sorts of ideas people throw around in some places (unfortunately not often enough here) in connection with game design and algorithms, then I don't think you're going to find a lot of books that follow the format you suggest. At a certain stage, you have to be able to assume the reader is competent and imaginative enough to be able to make do with a terse and technical discussion to get anywhere.

I've seen books aimed at arts/design students that survey topics in probability, combinatorics, and so-called "finite mathematics," but I can't think of a reference off the top of my head. At least one that I recall covers things like minimal spanning tree algorithms. This might be close to what you want, but there might be a lot of bullshit to wade through to pick out the stuff that you're after.
Title: Re: How to improve math skills?
Post by: Krice on February 13, 2015, 05:34:19 PM
I'm thinking about the stuff I need in Brick Atelier, like that improved ellipse routine which is symmetric and don't look like ass in small sizes. I have some kind of ideas how to do that, but there are other image manipulation stuff I want to know better like anti-aliasing and rotation in context of pixel editor which gives better results when rotation etc. is non-destructive as possible (not aliasing/smudging the result too much).

I guess also fov/lighting routines in roguelikes and better random number generation.
Title: Re: How to improve math skills?
Post by: mushroom patch on February 13, 2015, 06:55:05 PM
Okay. These are more engineering oriented subjects. You could check out an introductory book on image processing and computer graphics that covers topics like interpolation and antialiasing. This material might also provide some insight into FOV algorithms, but "your milage may vary," as they say.

Random number generation is not something you're going to want to get into, I think. It's a well-developed, fairly technical subject where a hobbyist is not going to improve on the state of the art, even as it existed twenty years ago (or even be likely to understand what an improvement would look like and why anyone would care). It's also a subject where widely available software (e.g. stuff in standard libraries for essentially any programming language/OS environment) is perfectly good and probably even overkill for the purpose of any kind of game programming. If you're not writing software that's supposed to encrypt diplomatic communications or something of comparable sensitivity, you don't need to worry about the details of random number generation.

If you're really after more basic mechanics, e.g. answers to questions like "what's the deal with seeds and why does brogue use them?" That kind of question can be answered by skimming some wikipedia articles. I would recommend against spending a significant amount of time learning much beyond the broad outlines of how pseudorandom number generation works, though.
Title: Re: How to improve math skills?
Post by: Krice on February 16, 2015, 11:42:56 AM
The problem in ellipse (also in fov) routines is the aliasing from "perfect" mathematic equation to pixelated extremely small size. I've reached far using trigonometric functions for outer edge and mathematical ellipse equation for inner (fill), but the edges have "double" pixels, you know. That's why bresenham routine was invented for line and also ellipse, but sadly the routine I copied from internet has a bug. If the x or y (don't remember which one) radius is 1 (one line width) then it draws one pixel, even if the other radius is more (should draw a line). I can't fix that in a thousand years, because I don't know how the bresenham routine works. I bet the bug is in all similar routines, because that bresenham implementation has just been copied all over the place as is usual in internet.
Title: Re: How to improve math skills?
Post by: TheCreator on February 16, 2015, 12:45:27 PM
Wouldn't it be easier to find a good implementation of the algorithm?
Title: Re: How to improve math skills?
Post by: Krice on February 16, 2015, 01:03:26 PM
Wouldn't it be easier to find a good implementation of the algorithm?

Well, it looks like I did found one that is working properly. What do you know! And I even got the filled version working by using a trick where first the fill was done and then outlines, because there is some kind of logic problem in filling routine which is always destroying x coordinate edges.
Title: Re: How to improve math skills?
Post by: Krice on March 04, 2015, 12:36:23 PM
I'm reading "A History of Mathematics" third edition by Merzbach and Boyer. I like history and even math history seems to be interesting. I'm sure this is not the best way to actually learn math, but I guess some concepts may become somewhat clearer. The book is nice 600+ pages of text mainly, with readable old school book font.
Title: Re: How to improve math skills?
Post by: Pickledtezcat on March 07, 2015, 12:49:56 PM
I know where Krice is coming from with this.

I last studied math properly in high school (secondary school, I'm from the UK) and we dealt with trig and algebra and other stuff, but most of the time I was thinking "I'm never going to use any of this in real life" so I didn't bother to remember any of it beyond the final exams.

Now I sometimes find myself having to deal with things like vectors, matrix transformations and other things which I have no formal education in.
Usually if I go through a couple of code examples which show the concept in action, I can understand it through code, but I can't understand it through "math".

Dot Product (http://en.wikipedia.org/wiki/Dot_product)

As a layman trying to understand that wiki page just gives me a headache, so I end up resorting to pages with titles like "math is fun!" (http://www.mathsisfun.com/algebra/vectors-dot-product.html) Which I can actually understand pretty quickly.

Is there anywhere I can find a guide to the kind of notation I frequently run in to when looking up a complicated math concept? I'm not an idiot but I studied Fine Art in University, not Mathematics.

Or do I really need to understand the maths notation at all? When trying to write a convex hull algorithm in python I first checked the wiki page about convex hulls (http://en.wikipedia.org/wiki/Convex_hull) and got this equation (http://en.wikipedia.org/wiki/Convex_hull#Convex_hull_of_a_finite_point_set) which just made my eyes bleed.

But when I started reading more and got in to the algorithms I had no trouble following the steps of the pseudo code to write my own python implementation. I guess if I really knew what was going on it might help me if I made a mistake in the coding, or if I wanted to optimize my algorithm, but mainly it doesn't seem that hard to get something that works. And I don't expect I'm going to invent a better algorithm all on my own.
 
Title: Re: How to improve math skills?
Post by: Krice on March 07, 2015, 06:37:53 PM
The way I understand it is that notation is like the language syntax of a programming language, which is used to describe underlying concepts (like inheritance or private data in programming). You need to learn both, of course. The modern notation of math is "short" as in Lisp so I think it's not that easy to read, but it's equally important to understand the concepts. Some people can understand those concepts easier, while others have more difficulties with them. I don't know if there is a direct relationship to intelligence, because even I have difficulties with math I don't think I'm less intelligent in other ways. In a way math can be too simple to understand for highly creative people like myself, whereas many of those who are good at math are far less creative.
Title: Re: How to improve math skills?
Post by: Eudoxus on March 07, 2015, 07:59:24 PM
and got this equation (http://en.wikipedia.org/wiki/Convex_hull#Convex_hull_of_a_finite_point_set) which just made my eyes bleed.

Believe it or not, that equation is actually not bad once you know what the symbols mean.  Krice is correct,  math language/symbols tend to be very dense and you have to read it a bit slower.

Have you ever used list comprehensions in python?   Python comprehensions are very similar to the notion being used in that equation.  The convex hull equation is just saying "take all linear combinations of S with this certain property".  Where the property is "the coefficients are all non-negative and they sum to 1".  The big symbol, the capital sigma, is just saying to add things up (ie the linear combinations).
Title: Re: How to improve math skills?
Post by: mushroom patch on March 07, 2015, 09:17:25 PM
re: the offending formula on wikipedia:

That's indefensibly badly written, especially for a general audience. Use of that carrot notation for "and" is not widespread even in the mathematics literature. It just shouldn't be there. Unfortunately, wikipedia articles on mathematical topics that can be easily grasped by people outside of the research community are plagued with this kind of garbage. It gives the half-educated a sense of accomplishment to write expressions like that.
Title: Re: How to improve math skills?
Post by: Krice on March 08, 2015, 12:41:51 PM
Or maybe creative people are stupid and creativity is simply a by-product of their attempts to find out how things work.
Title: Re: How to improve math skills?
Post by: mushroom patch on March 09, 2015, 01:12:37 PM
No, I don't think so.
Title: Re: How to improve math skills?
Post by: Krice on March 21, 2015, 04:23:38 PM
Still 300 pages to read from History Of Mathematics. I was surprised to learn the relationship between geometry and numbers, or at least that it seems to have been an important part of maths. Also, I'm now interested to know why it was (and is?) important to find normalized values for series of numbers that in normal logic has infinite value. Even the concept of series is kind of hazy. Why they are important in the first place?
Title: Re: How to improve math skills?
Post by: Themace on March 23, 2015, 02:49:38 AM
I'm not sure what your current level or where the gaps are. If you might brush up on what is taught is US elementary and high school you could consider going through the Common Core resources at Khan Academy:

https://www.khanacademy.org/commoncore

From there the more advanced resources at Khan Academy or MIT OpenCourseWare

http://ocw.mit.edu/courses/find-by-topic/#cat=mathematics

might work for you. Also wikipedia has a decent starting glossary of math symbols:

http://en.wikipedia.org/wiki/List_of_mathematical_symbols

if you run across equations with unfamiliar symbols. Beyond that if you post specific questions I'll try to help. Or if you and/or others want to talk about specific math issues over Mumble we can setup a time to meet on my server.
Title: Re: How to improve math skills?
Post by: Krice on March 23, 2015, 01:17:32 PM
Calm down. My method for learning math is read anything I can and try to pick up pieces, but not take it too seriously. So it's much like my way of learning how to play drums.
Title: Re: How to improve math skills?
Post by: Soulmask on April 13, 2015, 11:28:07 PM
I don't think reading math books will improve your programming skills.

This is something I found true of a lot of developers. Unless they use the most complicated math or physics, they think their game will be bad. Other developers who are good at math focus on making complicated maths and then when their game is done no one sees the math going on and the actual game sucks(while nobody cares about their I'm good at math look at my shiny maths rants). Focus on simulating realistic gameplay instead of trying to do real physics simulation. There is no difference between a direction, speed and acceleration variable together and a mathematical vector. A matrix is not much different then an excel chart. A lot of people reading this will think I'm saying this because I suck at math but in fact I don't. Math comes naturally to me. Complicated math doesn't belong in a game, the player won't notice any difference between realistic simulation vs real physics simulation and like in dwarf fortress the physics even if based in reality will end up making weird game play like whips being lightsabers, some blunt weapons being super bad, and naked+4 adamantine cloaks being the best armor.

If you need to focus on math, you should try to think a lot about "financial" type math, ie exponential functions(x=x+x*0.1 recursive loops), if you want RNG, look for mersenne twister and int normal distribution libraries and real normal disbution, if you're in c++ then there's random in the STL which is FAR better than rand from c.

For reference charts I mostly use excel and do a beta chart, and then when I finished the design of the chart(every basic thing as a value) I look for formulas that could automate the charts. Once, the tab I came up with was too complicated to ever find a formula without wasting ridiculous amounts of time, so I just made a function that took an int and then returned an int. This started with my "Building" skill, I wanted to get a quality modifier depending on building skill of a character to randomize building quality. I'll attach the chart I finalized.

So maybe this can help you so I'll describe the process that I used to come up with this chart, at first I was trying for formulas to automatically get % for quality types, but I never came close to get a beginning of formula. If anything I'd have to get 10 different and huge formulas to make a chart resembling this I think(I might be wrong). In the end I chose to do the whole chart by hand, but even this needed some work. I started from the terrible quality at 100% odds. then it decreases rapidly, and for every other quality except the 2 last ones the "peak" is 30% so I chose my numbers depending on that and sometimes approximately approaching a normal distribution and sometimes a "thinner" distribution.

So you cant see the terrible at 100% and masterwork at 100% that ended up in the code, but it's very simple really, I just took 5% from terrible at every step(for 100% terrible you need negative skill which you can only have with debuffs) until it reached 0 and gave the 5 percent somewhat randomly and to get at masterwork 100%, I took back 4% of the last quality past skill lvl 50 and gave them to exquisite and masterwork(if the quality has <4% then i take it all and the rest from the next), then when exquisite and masterwork were 50-50, i gave 5 percent from exquisite to masterwork until it goes to 100%. The "hardest" thing was to know how to add percents between 0 and 50 skill, and once I went with "every quality has a peak of 30% except the first and 2 last ones" then I built around from there. The end result is not perfect, but it's charming, at least to me, and I think I ended up with a good solution.

edit: also the normal skill cap is 50 and you can only get to 100% masterwork with a lot of skill buffs.

I'll never use overly complicated maths like integrals in the code, this is a game after all and not a scientific simulation software. I'm not bad at math, if anything I'm good at it, but I have the principle to use the simplest method until I'm forced to use a more complicated one.

Heres the link to excel file
http://www.filedropper.com/buildingqualityhiroguetemple

I hope you read my whole post and deduce that reading math books is not the best option for you :D
Title: Re: How to improve math skills?
Post by: Soulmask on April 13, 2015, 11:57:25 PM
If you only need to understand one thing from my post it is this, determine how you want the basic numbers to look like, and determine how they should behave. What does strength stat represent? Will having twice has much STR mean that I'm twice as strong or every 10 points of STR means that you are twice as strong? Do I want a normal distribution for attribute randomization? How high does the new game attributes need to be in order to represent correctly the attributes of a character VS a mob? Focus on what every variable means exactly and try to make them not be too broad, for example agility in my game represents quickness of muscles(str of muscle relative to body weight) and hand-eye coordination, while perception means acuity of the senses(mostly sight and smell). Also the detection and stealth skill represent training and experience(not game XP but real life experience). By that sense, a blind monk would have low perception but high detection skill. Once you know what every variable means exactly, its much easier to know how to give values to the numbers and build formulas for them.
Title: Re: How to improve math skills?
Post by: Soulmask on April 14, 2015, 12:25:58 AM
Ok I think there's a lot of mathematical elitism in here so I changed this post.

Math is a tool. It is as good as you can use it. If you make a bad game with huge level math, you've haven't achieved anything. Einstein thought that creativity came with intelligence, but I think he was mixing the two kinds of real intelligence(not talking about g here). There's technical intelligence and then there's divergent thinking. Technical helps you understand math. Divergent thinking helps you being creative. A person who has both, like Einstein, can be a genius and invent new concepts that are actually true. Meanwhile, the people who have the best IQ might be living calculators but they will not achieve anything significant apart from being good in their day job.

There's a ton of technically good programmers, but a lot of them are code hermits. They focus on making the best code, the best physics engine and high level maths. Meanwhile, their game sucks. On the other spectrum, only "better than average" IQ people with divergent thinking make unique fun creative games. Then there's the high technical intelligence AND divergent thinking people who are good at both.

Finally, if you think programming is about mathematics, you are wrong. It's about abstraction. If there's 2 games, and in both you have a dwarf smashing a rock with his warhammer in 2, but in one game it uses complex physics and the other uses simple abstractions, the most efficient game is the latter one. We're not making scientific simulation software. To the player, both games will be the same, but it will have taken a lot less time for the latter game to be made, allowing more time to complete the game and focus on other things. The more realistic the physics you try to make into the game, the more you'll break your teeth on the code and the more likely weird stuff will happen in the game afterwards because it's too complicated(dwarf fortress).

Unfortunately, both technical intelligence and divergent thinking can't be thought, but the more you focus on mathematics and the less you focus on the actual GAME. What's the point of making a game if all you do i think about maths and physics and you never think about the fun stuff?
Title: Re: How to improve math skills?
Post by: Soulmask on April 14, 2015, 03:19:44 AM
re: the offending formula on wikipedia:

That's indefensibly badly written, especially for a general audience. Use of that carrot notation for "and" is not widespread even in the mathematics literature. It just shouldn't be there. Unfortunately, wikipedia articles on mathematical topics that can be easily grasped by people outside of the research community are plagued with this kind of garbage. It gives the half-educated a sense of accomplishment to write expressions like that.

I was planning to be subtle but the way you insult people while saying incorrect statements is just too much. You imply that the notation for carrot AND is not widespread. Not only it doesn't matter at all, but discreet mathematics use it. Arguing about correct notations is like arguing over the best color. You refer to people outside the math research community has half-educated and laymen while calling a notation garbage. It is you who is trying to give yourself a sense of superiority over futile things, and not only that you're insulting everybody else in the meantime. You are criticizing the method rather than the concrete content. Especially in programming, many different ways can achieve the same thing.
Title: Re: How to improve math skills?
Post by: Krice on April 14, 2015, 08:37:06 AM
Finally, if you think programming is about mathematics, you are wrong. It's about abstraction.

This thread is about how to improve math skills, so it's a specific topic only for mathematics. While some things you say is true you should calm down and put your opinions in another thread. And you should probably not forget to take your medication.
Title: Re: How to improve math skills?
Post by: Soulmask on April 14, 2015, 06:55:20 PM
The thread might be on mathematics, but this subforum is about programming. You said you wanted to improve maths because you needed it for programming. I was exactly answering that. I'm the second person that tries to help you you tell to calm down in a very short span of time. You should probably go on a math forum, and hopefully after reading 20 math books you'll realize you ain't better at programming.
Title: Re: How to improve math skills?
Post by: mushroom patch on April 14, 2015, 08:21:12 PM
re: the offending formula on wikipedia:

That's indefensibly badly written, especially for a general audience. Use of that carrot notation for "and" is not widespread even in the mathematics literature. It just shouldn't be there. Unfortunately, wikipedia articles on mathematical topics that can be easily grasped by people outside of the research community are plagued with this kind of garbage. It gives the half-educated a sense of accomplishment to write expressions like that.

I was planning to be subtle but the way you insult people while saying incorrect statements is just too much. You imply that the notation for carrot AND is not widespread. Not only it doesn't matter at all, but discreet mathematics use it. Arguing about correct notations is like arguing over the best color. You refer to people outside the math research community has half-educated and laymen while calling a notation garbage. It is you who is trying to give yourself a sense of superiority over futile things, and not only that you're insulting everybody else in the meantime. You are criticizing the method rather than the concrete content. Especially in programming, many different ways can achieve the same thing.

I was planning not to read your posts, but I noticed you quoted me. It's not incorrect to say that actually writing the word "and" is better than "^" in that formula. Wikipedia targets a general audience and the page in question is one that deals with an accessible topic of general interest. It should use transparent notation where it can and in this instance, it obviously can. The purpose of notation is to communicate. Using a notation that is seldom used outside of certain subfields of mathematics the reader most likely isn't familiar with is bad practice when a plain English alternative is available.

I assure you, it gives me no satisfaction to compare myself favorably to random people on the internet. I do not refer to people outside of the mathematics community as half-educated, I refer to the person who chose that notation that way. I could be wrong, but I doubt it. As far as my characterization of wikipedia editors, obviously many of them do good work on mathematics articles, but those who do almost uniformly hold or are working on advanced degrees in mathematics. Unfortunately, many people with a programming background, perhaps yourself included, consider themselves experts on mathematics (and a surprising number of other areas as well) and cry "elitism" when anyone tells them otherwise. Their sheer numbers in "geek" communities tend to drown out other perspectives, but on wikipedia in particular, this dynamic tends to dominate articles that a nonspecialist is likely to understand and approach, to the detriment of the project as a whole.
Title: Re: How to improve math skills?
Post by: Soulmask on April 14, 2015, 09:16:52 PM
Oh I don't consider myself an expert in math, merely half-educated, as I only had basic engineering math and statistic classes. I'm glad that your last post is much more reasonable than the one I quoted, seems like you're a reasonable person after all. Indeed, discreet mathematics could be called a sub-field, but's it's also one of the fields of mathematics that influenced computer science the most, especially in the early days of computing theory. It uses many symbols, and cluttering formulas with 3-letter notations like AND would make already big formulas too big in the end. Indeed the more "pure" mathematical circles might not use that notation, but in their own subfield they use it exclusively, and would find the use of and in their formulas as otherworldly as you do ^. In my opinion, the use of one character that is included in the default 255 ascii character table and doesn't mean anything else than and is the correct way to to write it, especially for computer science subjects since discreet mathematics is useful for "computer algorithms, programming languages, cryptography, automated theorem proving, and software development."(from wikipedia)
Title: Re: How to improve math skills?
Post by: mushroom patch on April 14, 2015, 09:25:29 PM
The formula I criticized was not complicated enough to need specialized notation. There may be contexts where using notation denser than "and" to mean "and" is warranted, but this was not one.
Title: Re: How to improve math skills?
Post by: Krice on April 14, 2015, 10:01:38 PM
You should probably go on a math forum, and hopefully after reading 20 math books you'll realize you ain't better at programming

Well if you want to go that way I will explain you that being quite bad at math myself has made me a worse programmer. It's really simple actually. Even if you try to think programming as "not math" you still need to implement various types of algorithms.. which.. as a word may sound familiar in math context, because it is. My opinion can go as far as to claim that everything in programming is math, most people just don't think it that way. Whatever the case I know for sure that the more I know about math the better I am as a programmer, because it's probably the only area of programming where I need to be better.
Title: Re: How to improve math skills?
Post by: Eudoxus on April 15, 2015, 12:54:48 AM
maybe "&" would have been a good middle ground between "AND" and "^", and it's perfectly fine in research papers (I've seen all three in many different branches of math).  then again, I think it's cool and helpful that the logical-and and the logical-or symbols look similar to the union and intersection symbols...
Title: Re: How to improve math skills?
Post by: mushroom patch on April 15, 2015, 02:49:35 AM
. . .
Title: Re: How to improve math skills?
Post by: Krice on May 08, 2015, 08:29:08 AM
For example I have linear falloff (or is it just an interpolation?) for light sources, but I think it would be better to have more "unrealistic" falloff where the brightest light covers more tiles at the beginning and then drops fast to darkness. I think it's something like cubic falloff (or inverse cubic?). However my lack of math skills makes it quite difficult to understand how to change the linear falloff (in interpolation) to what I need. I've tried to search the internet, but every subject related to falloffs seems to cover only 3D rendering software light falloff settings.
Title: Re: How to improve math skills?
Post by: reaver on May 08, 2015, 12:44:35 PM
Let's say the light intensity at the light tile is I. Let's say you use linear falloff: for a distance "x", the light reached is I - kx (k is some factor you decide). Of course that's quite intuitive, but the results are un-great.
A much better formula which you can try at your heart's leisure is this:
1/(1 + a*abs(x) + b*x*x)
( Interactive link here -> https://www.desmos.com/calculator/nmnaud1hrw )
where x is your distance, and factors a and b you decide to get the shape right. What it calculates is the attenuation of the light, so you multiply that to "I". This formula approaches the "physically correct" way of calculating light falloff with distance, but it's very tweakable and practically better. Go wild and light the world on fire now.
Title: Re: How to improve math skills?
Post by: Krice on May 09, 2015, 11:58:29 AM
This formula approaches the "physically correct" way of calculating light falloff with distance

I don't want that. I want the opposite! I know light intensity decreases by the square of the distance, but it's not practical in a tile based lighting routine.
Title: Re: How to improve math skills?
Post by: reaver on May 09, 2015, 06:00:15 PM
You do want that. You don't want the light intensity to increase with distance, right? Now stop whining and use the bloody formula, and tune it to your heart's desire to make it as unrealistic or realistic as you want. Seriously.
Title: Re: How to improve math skills?
Post by: Krice on May 09, 2015, 06:42:23 PM
It doesn't work. What you want is the light intensity at a certain area stays the same, otherwise it looks bad if only the light source tile itself has the brightest value which then drops to whatever rate right after that.
Title: Re: How to improve math skills?
Post by: reaver on May 09, 2015, 07:22:28 PM
Here's a pro-tip: use the same function form, multiply by a value HIGHER than 1 and clamp it to 1 (link below). Voila, you can have the same maximum light on several tiles. There are several ways to do what you want, you are presented with one but you refuse to use a brain cell to see how that works for you and how you can use it to your advantage.

Look here and feel the magic of clamping: https://www.desmos.com/calculator/lopuoqdpms
Title: Re: How to improve math skills?
Post by: reaver on May 09, 2015, 08:49:20 PM
You can also use this:

https://www.desmos.com/calculator/v3hs2592pp

This is pretty much the smootherstep function (http://en.wikipedia.org/wiki/Smoothstep). It's a typical, nice function to get smoothly from 0 to 1, by determining two edge points ("a" and "b" variables in the graph in the link above). Again, if none of these cover you, I'm at a loss.
Title: Re: How to improve math skills?
Post by: Krice on May 10, 2015, 08:42:32 AM
http://koti.mbnet.fi/paulkp/temp/falloffs.png

Let's look at this properly with an illustrative image (link above).
Inverse square (=realistic light falloff) (roughly pictured at left) falloff makes the first tile bright, then following tiles are really dark. Linear falloff is easy and it can be used in the interpolation easily by calculating the dimming value for the length of the line (I'm using line drawing in light routine to shoot rays of light).
(Note: when using only an equation with line's loop value the result is a rectangular light area!)
The right side falloff is what I want. First tiles are bright, then drops quite fast to darkness, giving somewhat smooth edges from light to dark.
But I don't know how to calculate that kind of falloff curve inside the line drawing with "loop" value as the distance. (Note: the distance in circular form is different than the raw loop value. Hence when using simple equation the result is a rectangle.)
Title: Re: How to improve math skills?
Post by: reaver on May 10, 2015, 11:29:50 AM
Use this then

https://www.desmos.com/calculator/29oyym8myd

The shape that you see is for 1-x^4, you can play around with the "b" parameter to get the shape that you want
You can multiply the function by the maximum distance, as in the graph that I gave you always goes to zero at x=1.
Title: Re: How to improve math skills?
Post by: Krice on June 17, 2015, 01:47:39 PM
Well, finally I was able to do something about this. I was using a fractional value to increase X to get smoother (non-square) falloff for the area, but it's still kind of square-ish (ix and add_x variables). Also, I noticed that using 4.0 for power was way too much (I ended up using 1.2), because there just aren't enough tiles to show the falloff! Instead I was using a condition to start increase X after one run of loop to get the block around the player in full light. But I guess it's the reason the light is more rectangle shaped that I hoped.

Code: [Select]
double ix=0.0;
const double add_x=(float)1.0f/(loop-1);

for (int t=0; t<loop; t++)
{
r.x=Function::round(x);
r.y=Function::round(y);

int i=Get_Index(r);
if (i==-1) break;

double tx=pow(ix, 1.2);
int iv=(int)(light_value*(1.0-(tx*tx)));

tilemap[i].Set_Light_Value(iv);
if (t>0 && tilemap[i].Determine_Los_Value()!=fovVisible) break;

x+=x_inc;
y+=y_inc;

if (t>0) ix+=add_x;
}
Title: Re: How to improve math skills?
Post by: Krice on June 18, 2015, 07:34:29 AM
I think this could also be done entirely without math by creating precalculated paths for the lighting routine and also the data for intensity of light, because lights spots in this game are small and there is a maximum size for light spots.