0、1、2、3、または N 次元のピクセルの配列を見ている場合、次のようなインジケーター関数を使用して、特定のピクセルがその中の正方形または長方形のグリッド線上にあるかどうかを簡単に判断できます。そのため(私が話していることを明確にするために命令型の擬似コードを使用しますが、実際には、より一般的なタイプのグリッドのインジケーター関数の制約と条件のみに関心があります):
/* 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...] */
私の質問は、一般に、さまざまなタイプの非正方形グリッドと非長方形グリッド(たとえば、三角形、六角形、八角形など)のインジケーター関数と制約がどのように見えるかということです。そのようなインジケータ関数の構築と、グリッドのさまざまな形状に必要な制約について?
Knuthはこれに取り組んでいるようです。
これは非常に一般的な数学的問題であるため、おそらく名前/標準的な解決策があります。
余談ですが、私はn次元の六角形グリッドに最も興味がありますが、適切なブール指標関数の代わりに線形代数を使用している場合にのみ機能する、厄介な1回限りの実装を書きたくありません。これらの問題を一般的に正しい方法で解決する方法を知りたいです。