I need someone’s help to get me through this.
I am working on a project which evaluates a baseball pitch. In the program there is a grid represented by numbers 1 – 25 indicating the areas of a strike zone. as follows:
/*------------------------*
| 1 | 2 | 3 | 4 | 5 |
| 6 | *7 | *8 | *9 | 10 |
| 11 |*12 |*13 |*14 | 15 |
| 16 |*17 |*18 |*19 | 20 |
| 21 | 22 | 23 | 24 | 25 |
*------------------------*/
As I have it 7,8,9,12,13,14,17,18,18 are strikes and 1,2,3,4,5,6,10,11,15,16,20,21,22,23,24,25 are balls. etc.
I need to evaluate two numbers, the intended cell and the actual cell and return the number of cells apart the intention was from the execution.
IE: pitch intended for cell 12 actually floats into cell 15 would return a 3 because on the grid 15 is 3 cells away from 12. Further examples, 7 intended and 6 actual would return 1 as 6 is only 1 cell from 7. 1 intended and 25 actual would return 4 as it is 4 cells away etc.
I am doing this as a self exercise to expand my java knowledge and I just can’t manage it on my own. I need a method that evaluates the two parameters cellIntended and cellActual, consults this matrix and returns the number of cells apart.
I’m sorry if this is the wrong location to ask etc but I figured I’d throw it out there. Many thanks to any who attempt or consult on a solution. You guys are all awesome for just reading this far. Thank you.
Try something like this:
That’s the Euclidean distance there, you could use something else (like Manhattan distance).