Q:

Check if point lies between two sets of co-ordinates

I am creating a tower defence game and want to prevent the user placing towers on the path. The path is stored as an array of objects with properties x and y. I'll do a quick example to explain. Many "levels" (aka paths) are stored inside an array. Inside this array (so Array[0], for example) is multiple objects, each detailing a point on the map that are then joined up to create a path:
levels = [
          [{x: 0, y: 0},         // When plotted:
           {x: 0, y: 50}],       // 0,0 to 0,50 creates a vertical line
           {x: 50, y: 100}],     // 0,50 to 50,100 creates a diagonal
          [{}] // more levels                                  
         ];

Due to the relative simplicity of the maths behind working out if a point is on a path where only one x/y value changes, I have a working version (which you can find here).
Using the above path examples, you can test my fiddle to ensure you are following. Try the co-ordinates 0,35 which (should) return true. This is because x doesn't change, so we merely check if y is within the first and second point's y value, which it is. Working as intended :)
However, my problem is trying to find out if the tower is on a diagonal path. Both values change, so I need to figure out the maths to account for a "diagonal" of sorts. Using the second and third path points, a diagonal from x:0, y:50 to x:50, y:100 is formed, we can imagine a square around this diagonal. My (incorrect) function currently prevents any point in that square from being a tower, whereas it should only be the diagonal that can't be used.
Essentially, my current, incorrect function does this, with a being the start of the diagonal, and b the end point:
if(x is between a.x and b.x AND y is between a.y and b.y){
   build the tower
}

Sorry about all the words and lack of code, but the jsFiddle is a really stripped down version that should help understand. I'm primarily looking for the maths to achieve the functionality, I can write the code myself if you can help with the pseudo.

A:

Did you consider the line equation: y = a * x + b
You can find a and b with two points.
Using the first point: (0,50)
50 = 0 + b

Therefore: 
b = 50

Using the second point: (50, 100)
100 = 50 * a + 50

Therefore: 
a = 1;

So the equation that determines if a point is on that line is:
y = 1 * x + 50

Examples:
point 1: (10, 60)
y = 1 * 10 + 50 = 60

This point is on the line. 
point 2: (60, 110)
y = 1 * 60 + 50 = 110

This point is on the line but outside the boundaries of the two points. So you have to add checks for that.
I could go on with more points to check. But I hope the above will get you going.

