Project

General

Profile

Actions

Mathematics

Math can be fun and we can do some cool stuff with math but it can be difficult to figure out how to come up with formulas that make sense and work with the game environment.

Linear Functions

y = mx + b

where m is the slope of the line (rise/run) and b is the y-intercept (y == 0).

Distance between two points

d = sqrt(pow((x 1 +x 2 /2), 2) + pow((y 1 +y 2 /2), 2));

Midpoint of a line segment

(x,y) = ((x 1 +x 2 )/2, (y 1 +y 2 )/2)

Lines that are parallel have the same slope but different y-intercepts.

m 1 == m 2
b 1 != b 2

Lines that are perpendicular have slopes that are the negative reciprocal of each other.

m 1 * m 2 = -1
m 1 = -1/m 2

A line that bisects another is perpendicular to that line going through the midpoint of that line.

midpoint = ((x 1 + x 2 )/2, (y 1 + y 2 ) / 2);
y 2 = (-1/m 1 )

Exponential Functions

Exponential equations are non-linear equations of the form y = ab^x + c. These are really useful functions where you want x to increase more and more for each value of y. The constant a is used to set the initial value. This is a wonderful formula to use for determining how much experience is required for each level or the value of a diamond.

Let's say that we want to increase the amount of experience required to advance a level by 1.5x for each level and that the first level advancement requires 500xp. We could use the following formula:

experience = 500 * 1.5^(level-1)

Level Experience Req'd Total Exp
1 500 500
2 750 1250
3 1,250 2500
4 1,688 4188
5 2,531 6719
10 19,222

If you want prettier numbers then you need to stick with whole numbers but then the results will increase really, really fast.

The constant value a plays an important role and can do some really interesting things. Let's find a formula to set the value of a pearl. We are going to due this by first setting a base value for an average pearl at 10gp. We'll define an average pearl as having a size of 7.0mm. All other characteristics of the pearl are going to be ignored for this example. We want to adjust the base value up and down based upon the size of the pearl. We'll do this by multiplying the base value, 30gp, by a ValueFactor. We know that we want a 7.0mm pearl to have a ValueFactor of 1.0. Each mm of size difference will double or halve the value of the pearl. We can use the information to determine the value of the constant a to be used in our ValueFactor formula:

1.0 = a2^7.0
a = 1.0 / 2^7.0
a = 0.0078

Let's see how we did:

factor = 0.0078 * 2^7.0
factor = 1.0

Perfect. The value of a pearl can now be calculated as 10gp * 0.0078 * 2^size:

Size Value
6.0 5gp
6.5 7gp
7.0 10gp
7.5 14gp
8.0 20gp
10.0 80gp
12.0 320gp

By playing around with the values of a and b you can come up with some pretty nifty ways to calculate non-linear values. Adjusting a and c allows you to manipulate the result while b allows you to increase or decrease the rate of change.

Updated by Hilapdatus about 4 years ago · 2 revisions