Taxicab distance



Taxicab distance, also known as rectilinear distance, city block distance, Manhattan distance, and other names, is a metric in taxicab geometry for measuring distance, as an alternative to Euclidean distance (straight-line, or "as the crow flies"). Minecraft uses taxicab distance as an efficient range measurement in several elements of the game.

Calculation
Minecraft measures the distance between two points in three-dimensional space in one of two ways, Euclidean distance or taxicab distance, depending on whether geometric accuracy or calculation efficiency is required.

Given two points in 3-D space $$(x_1, y_1, z_1)$$ and $$(x_2, y_2, z_2)$$, the straight-line distance (Euclidean distance) between them is:
 * Euclidean distance
 * $$d = \sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2 + (z_1 - z_2)^2}$$

Minecraft uses Euclidean distance calculations in cases that are relatively infrequent or when accuracy is required. This is geometrically the most accurate calculation. However, the square root calculation is processor intensive, particularly on mobile devices that may have slow processors. Too many processor-intensive operations performed during a game tick can introduce lag in the game.

The taxicab distance is a less accurate but faster calculation that can be done many times during a game tick. It eliminates the square root and squaring operations by simply calculating the absolute value (positive value) of the difference between each coordinate value:
 * Taxicab distance
 * $$d = |x_1 - x_2| + |y_1 - y_2| + |z_1 - z_2|$$

In Minecraft, the most obvious consequence of this calculation is that a taxicab "circle" drawn with a constant taxicab radius appears as a diamond (such as torch illumination), in which the taxicab radius equals the Euclidean radius only in the four cardinal directions (north, south, east, west), and the radius is shorter in all other directions. Similarly, in three dimensions, a taxicab "sphere" appears as an octahedron.

Taxicab
Minecraft makes use of taxicab distance in various situations:
 * Light from light sources such as torches, campfires, lanterns, glowstone, etc. illuminate surfaces according to taxicab distance.
 * Torches also melt snow layers within 2 blocks and ice within 3 blocks taxicab distance. Several other light-emitting blocks also melt snow in a taxicab radius; see.
 * Heat blocks melt snow layers and ice within 2 blocks taxicab distance, but do not emit light.
 * Liquid (water or lava) flowing horizontally on a flat surface flows from the source in taxicab distance. For example, if flowing water is forced into a 1-block-wide stream and turns corners, it travels 7 blocks. If it is allowed to flow freely on a surface, it also travels 7 blocks taxicab distance.
 * In Bedrock Edition, simulation distance is the distance from the player at which blocks get tick updates (such as lightning strikes), and beyond which mobs despawn; this also uses taxicab distance.
 * In Bedrock Edition, a spawner spawns mobs within a 4-block taxicab horizontal range from the spawner.
 * A sponge absorbs water up to 7 blocks away in taxicab distance (an octahedral volume centered on the sponge).
 * Phantoms in Java Edition spawn 20–34 blocks above the player, and off to the side by a taxicab distance of up to 10 blocks.
 * Using bone meal on sea pickles that are on coral blocks creates more sea pickles on nearby coral blocks out to a horizontal taxicab distance of 2.
 * A block of copper is oxidized according to a taxicab distance search for unwaxed copper blocks within 4 blocks of the block being considered for oxidation.
 * Shulkers can move along only one of the three grid axes at a time and on integer steps, meaning that they move according to taxicab geometry.
 * Some redstone components produce block updates up to two blocks away by taxicab distance, including up and down.

Euclidean
Situations in which Minecraft calculates Euclidean distance:
 * Mob despawning range in Java Edition.
 * Disks in rivers and lakes generate as blocks within a Euclidean distance from a central block.
 * Effects of explosions.
 * Lightning rods redirect lightning within a Euclidean spherical volume centered on the rod, having a radius of 128 blocks in Java Edition and 64 blocks in Bedrock Edition.
 * The command.
 * Nether portal searches for destination portals.
 * Splash potions affect mobs inside a 4-block radius Euclidean sphere.
 * Target selectors used in commands use Euclidean distances.
 * A zombie siege is started based on Euclidean distance between a player and the village center.
 * Finally, a splash text displays the misspelled word "Euclidian!"