Cameleon - 7 months ago 14

PHP Question

I got many tables which need to be checked for specific values

I will need to input specific numbers and then I need a function to check if the square block is found in the particular region, if so, what number that region got (70 or 75).

Values are:

0.00 till -12.00 (left vertical metter)

0.00 till +4.00 (upper horizontal metter)

Numbers 75 or 70 are just numbers wich are set for the whole block.

Each blue square block is 0.25 in both metters.

For example, if I input -11.00 and +2.00 square found with number 70, another example, when I put -5.00 and 2.25 square found with 75, when input -11.00 and +1.00 no go.

Anyone got idea how to do it ?

I started to write function but i ended to a point where i just don't know how to do it.

Answer

You have the right idea. From the picture it looks like the functions are liner in the region you specified so you can use y = mx + b to get the equation for each line (I see at least 4). This page http://www.purplemath.com/modules/slopgrph.htm explains how to compute the line equations you need.

Once you have the formulas for the lines, given an point(X,Y) you can use the X value of your point to compute the y values for each of your lines, and then compare your point's Y against each of your y's in order:

```
if (Point_Y < y_first){
// in region 1
} else if(Point_Y >= y_first && Point_Y < y_second){
// region 2
} else if(Point_Y >= y_second && Point_Y < y_third){
// in region 3
} .... etc
```

You should probably also check that the point is in the range given by the graph you have as you don't know for certain what the graph looks like out of the range. This is easier to do:

```
if(Point_Y <= y_max && Point_Y >= y_min
&& Point_X <= x_max && Point_X >= x_min){
// in range
}
```