Page MenuHomeDevCentral

GeoOctocube
ActivePublic

Authored by dereckson on Mar 26 2015, 19:57.
Tags
Referenced Files
F1480: GeoOctocube
Mar 29 2015, 17:01
F1454: Masterwork_From_Distant_Lands
Mar 26 2015, 19:57
Subscribers
None
/**
* Geo octocube class
*
* An octocube is a cube divided in 8 parts (sliced in two in x, y and z)
*
* Its coordinate (0, 0, 0) is the octocube center.
*/
class GeoOctocube {
/**
* Gets the sector from the (x, y, z) specified coordinates
*
* Sector will be:
* <code>
* // _____ _____
* // / 5 / 6 /|
* // /- - -/- - -/ |
* // /_____/____ /| |
* // | | | |/|
* // | 7 | 8 | / | 2
* // |_____|_____|/| |
* // | | | |/
* // | 3 | 4 | /
* // |_____|_____|/
* </code>
*
* @param int $x the x coordinate
* @param int $y the y coordinate
* @param int $z the z coordinate
* @return int the number of the sector (0 if x = y = z 0 ; otherwise, 1 to 8)
*/
static function get_sector ($x, $y, $z) {
//Cube center
if ($x == 0 && $y == 0 && $z == 0) return 0;
//One of the 8 cubes
$sector = 1;
if ($x >= 0) $sector++; //we're at right
if ($y < 0) $sector += 2; //we're in front
if ($z >= 0) $sector += 4; //we're on the top layer
return $sector;
}
/**
* Gets the sector from the (x, y, z) specified coordinates
* @see get_sector
*
* @param GeoPoint3D $pt the x, y, z coordinates
* @return int the number of the sector (0 if x = y = z 0 ; otherwise, 1 to 8)
*/
static function get_sector_from_point3D ($pt) {
return get_sector($pt->x, $pt->y, $pt->z);
}
}

Event Timeline

dereckson changed the title of this paste from untitled to Masterwork From Distant Lands.
dereckson updated the paste's language from autodetect to autodetect.
dereckson changed the title of this paste from Masterwork From Distant Lands to GeoOctocube.
dereckson updated the paste's language from autodetect to php.
dereckson added a project: Zed.