If you're looking at an array of pixels, in either 0,1,2,3, or even N dimensions, it's easy to tell if a certain pixel falls on a square or rectangular grid line within it by using an indicator function like so (I'll use imperative pseudocode to make what I'm talking about clear but I'm really only interested in the constraints and the conditionals in the indicator functions for the more general types of grids):
/* define the array of pixels in however many dimensions you want */
//define the dimensions of the array
int x-dimension-length = <some positive integer>;
int y-dimension-length = <some positive integer>;
int z-dimension-length = <some positive integer>;
[...] //you could keep gong for even higher dimensions
/* define CONSTRAINTS (for the square or rectangular case) */
//define the height and width of the grid boxes within the grid (contstraints on a square/rectangular grid)
int horizontalSpacingBetweenGridlines = <non-negative integer>;
int verticalSpacingBetweenGridlines = <non-negative integer>;
/* end definition of CONSTRAINTS */
/* define the arrays to draw the grids on */
// -- assumes that the arrays here are intialised to contain all zeros:
//0-dimensional (degenerate) example:
int point = 0;
//1d example:
int [] OneDimensionalArray = int[x-dimension-length];
//(2d example)
int [] TwoDimensionalArray = int[x-dimension-length][y-dimension-length];
//(3d example)
int [] ThreeDimensionalArray = int[x-dimension-length][y-dimension-length][z-dimension-length];
/* Indicator functions */
/* zero-dimensional (degenerate) case */
//if a point falls on a gridline, degenerate example
boolean doesAPointFallOnAGridLine0D() {
if (point % horizontalSpacingBetweenGridlines == 0) {
return true;
}
/* one-dimensional case */
//decide if a point in the 1D array at index <x-coordinateFrom1DArray> falls on a gridline
boolean doesAPointFallOnAGridLine1D(int x-coordinateFrom1DArray) {
if (x-coordinate % horizontalSpacingBetweenGridlines == 0) {
return true;
}
}
/* two-dimensional case */
//decide if a point in the 2D array at index <x-coordinateFrom2DArray>,<y-coordinateFrom2DArray> falls on a gridline
boolean doesAPointFallOnAGridLine2D(int x-coordinateFrom2DArray, int y-coordinateFrom2DArray) {
if((x-coordinateFrom2DArray % horizontalSpacingBetweenGridlines == 0) && (y-coordinateFrom2DArray % verticalSpacingBetweenGridlines == 0)) {
return true;
}
}
/* [and so on for higher-and-higher-dimensional spaces...] */
My question is, in general what do the indicator function and constraints look like for the different types of non-square and non-rectangular-grids (e.g., triangular, hexagonal, octagonal, whatever), and is there a canonical reference work that talks about constructing that sort of indicator function and the constraints it requires for the different shapes of grid?
Knuth seems out on this one.
This is a very general mathematical problem so it probably has a name/canonical solution.
As an aside, I'm most interested in hexagonal grids in n-dimensions, but I don't want to write a kludgy one-off implementation that only works for those using linear algebra instead of a proper boolean indicator function, and would rather like to know how to solve these problems in general the right way.