我正在嘗試從更大的正方形中獲取固定大小的正方形陣列。例如:
我有一個正方形的坐標:
$x1 = 1;
$x2 = 100;
$y1 = 1;
$y2 = 100;
$smallerSquareSide = 10;
我期望的結果:
$res = [[1,10,1,10],[11,20,1,10],[21,30,1,10],…]
但我不知道如何正確地做到這一點。
PS 邊框周圍可能有空格,因為數字可能不匹配
uj5u.com熱心網友回復:
這應該可以作業(輸出格式:res=[square1, square2, square3, ...], squareN=[x1, x2, y1, y2])
$x1 = 1;
$x2 = 100;
$y1 = 1;
$y2 = 100;
$smallerSquareSide = 10;
$res = [];
for($i=$y1; $i ($smallerSquareSide-1)<=$y2; $i =$smallerSquareSide){ // loop y
for($j=$x1; $j ($smallerSquareSide-1)<=$x2; $j =$smallerSquareSide){ // loop x
// add next square coords -> [$j, $j ($smallerSquareSide-1), $i, $i ($smallerSquareSide-1)]
array_push($res, [$j, $j ($smallerSquareSide-1), $i, $i ($smallerSquareSide-1)]);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/464883.html
上一篇:如何在圓周上找到一定距離的點?
下一篇:如何繪制相對于零的時間序列?
