Programming: Arrays and Lists
Arrays are a set of numbers/objects that follow a specific pattern. It’s considered a way of orderly arrangement of the numbers, usually in rows or columns. The best way to think of it is the array list is made up of cubby-holes in a row or column, with each element in the array a box that goes into a hole.
Wikipedia tells me that “in coding theory, a standard array is an array that lists all elements of a particular vector space.” Following that, “vector space (also called a linear space) is a collection of objects called vectors, which may be added together and multiplied (“scaled”) by numbers, called scalars in this context.” I’m not sure if this is relevant to what we’ll be looking into, but I thought it better to include it in case it helps in the long run.
The difference I found between arrays and lists is that arrays contain only one kind of data type, while lists can contain multiple types of data – otherwise, they’re very much the same thing.
Another example I found online was this: we have a scoreboard that contains 10 scores. Instead of listing the variables/elements individually, we could create an array.
We would write the array as score(10) – by using this method, all 10 scores can be stored in one place with easier access. Arrays are named like variables, with the number in the bracket the amount of items that can be stored in the array. As shown above, it’s important to remember that computers start counting at  rather than , so the first element in a list or array will be .
I really liked what I found on BBC Bitesize as to why we might want to use arrays. I won’t bother paraphrasing it, since I think it’s good to keep in mind in its whole:
A variable holds a single item of data. There may be a situation where lots of variables are needed to hold similar and related data. In this situation, using an array can simplify a program by storing all related data under one name. This means that a program can be written to search through an array of data much more quickly than having to write a new line of code for every variable. This reduces the complexity and length of the program which makes it easier to find and debug errors.
Maths: Pythagoras’ Theorem and Vector Normalisation
The simplest way of describing the need of Pythagoras’ Theorem is it’s a way to find the length of any side of a triangle, when you have the lengths of the other two sides. In right-angled triangles, I’ll always remember learning that a² = b² + c², or the square of the hypotenuse is equal to the sum of the squares on the other two sides. Much like SOHCAHTOA, it’s something that stays with you even so many years after doing secondary maths.
It’s interesting to know that you can also use the theorem to find the distance between two points, if you have the (x, y) coordinates of the points. I’m going to wager this is going to be the most important reason to know the theorem in our situation.
I was a bit confused about vector normalisation, however, but I’ll write/quote about what I read in my research and hope it makes sense when we’re introduced to the subject in class next week.
The process of normalising, from what I’ve read, is self-explanatory in name: it’s the way to make something standard or normal. However, when talking about vectors, to normalise one is to take a vector of any length and, while it’s still pointing in the same direction, change its length to one – this is how you turn it into what’s called a unit vector.
To actually normalise the vector, you need to “divide each component by its magnitude”. The example I found went as such: if a vector has a length of 5, then 5 divided by 5 is 1. We know that the hypotenuse is the longest length on a right-angled triangle. If the hypotenuse is at 5 and we need to get it to 1, we scale it and all the other sides down by dividing by 5.
That’s about as far as I made it through looking into vector normalisation until I reached a point where examples and explanations weren’t making sense to me. However, at least now I can guess how these topics will factor into our game-making process, even if the calculations are done for us in the background.