Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Last active April 10, 2020 20:40
Show Gist options
  • Save PJZ9n/2c2b52bd1d7a5388c3755e846d2ef9ca to your computer and use it in GitHub Desktop.
Save PJZ9n/2c2b52bd1d7a5388c3755e846d2ef9ca to your computer and use it in GitHub Desktop.
二つの座標からその中の全座標を取得する
<?php
use pocketmine\math\Vector3;
/**
* 二つの座標からその中の全座標を取得する
*
* @param Vector3 $start
* @param Vector3 $end
* @param int $space 取得する間隔(細かさ)
*
* @return Vector3[]
*/
public static function getPositions(Vector3 $start, Vector3 $end, int $space = 1): array
{
$positions = [];
$startX = min($start->x, $end->x);
$endX = max($start->x, $end->x);
$startY = min($start->y, $end->y);
$endY = max($start->y, $end->y);
$startZ = min($start->z, $end->z);
$endZ = max($start->z, $end->z);
for ($x = $startX; $x <= $endX; $x += $space) {
for ($y = $startY; $y <= $endY; $y += $space) {
for ($z = $startZ; $z <= $endZ; $z += $space) {
$positions[] = new Vector3($x, $y, $z);
}
}
}
return $positions;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment