Maths and Programming Revision – 15/04/21

Data Structures

Data Structures are something that we have briefly covered in maths and programming. There are many different Data Structures but some of the most common ones are:

Arrays: An Array is a collection of variables of the same type. They are sequential which means they can be accessed quickly.

Linked List: A linked list a sequential data structure that consists of sequential data that is linked to each other.

Stack: A Stack is a first in last out data structure, like a stack of plates, individually moving the plates from that stack to another will change the order.

Queues: A Queue is a first in first out data structure, like a real world queue for the latest game release, the first into the store, is the first out of the store.

Selection Statements

A selection statement is a fancy term for conditional statements. These statements come in many forms such as if, for and while.

If Statement: If this condition is currently true, run this code.

For Statement: For every time this condition is hit, run this code.

While Statement: While this condition is true, run this code.

Cross Products

Cross Products have a simple but forgetful solution. The solution is to write out both sets of coordinates and then to plant X, Y and Z in the middle of the numbers, then multiply the values together and subtract them to get the new value. A cross product results in a third vector.

Magnitude

Magnitude comes down to Pythagoras Theorem. X² + Y² = Z². Find the SqRt of Z².

Triangular Sprites

To find the area of a triangular sprite, you square the length and height and then divide it by 2. Length² + Height² = Area. Area / 2 = Triangle Area.

Speed

Speed = Distance divided by time. In this instance it would be 750 divided by 3 which equals 250.

Pythagoras Theorem

To work out the distance between the two characters here, we need to use Pythagoras. We would get Player X² and subtract that from Enemy X², and then do the same for Player Y² and Enemy Y². We would then add the two values together and find the square root.

Finding Angles

In order to work this one out, it would probably be best to try and visualise the situation. In this instance, a triangle is the best shape to visualise what is happening here and where triangles are involved we need to use Trigonometry. Trigonometry has 3 calculations which are sin, cos and tan.

Sin, Which can be found by dividing the Opposite Side by the Hypotenuse Side. (Adjacent)
Cos, Which can be found by dividing the Adjacent Side by the Hypotenuse Side. (Opposite)
Tan, Which can be found by dividing the Opposite Side by the Adjacent Side. (Hypotenuse)

In this instance we want to work out the Hypotenuse as that is the angle between the two values. So we would use Tan0 = Height divided by Distance. Then we would use Tan to the power of -1, 0.2. This gives an answer of 11.31.

Leave a comment