Manhattan distance (Manhattan)

definition

Manhattan distance: the distance between two points in the north-south direction plus the distance in the east-west direction; for a town street with a regular layout of due south and north, due east and west, the distance from one point to another is exactly in north-south The distance traveled in the direction plus the distance traveled in the east-west direction, so the Manhattan distance is also known as the taxi distance. Manhattan distance is not a distance invariant. When the coordinate axis changes, the distance between points will be different.
As shown in the figure below, if you want to drive from one intersection to another intersection in Manhattan, the driving distance is obviously not the straight-line distance between two points. This actual driving distance is the "Manhattan distance". Manhattan distance is also known as "City Block distance". The red line in the figure represents the Manhattan distance, the green represents the Euclidean distance (straight-line distance), and the blue and yellow represent the equivalent Manhattan distance.
insert image description here

Calculation formula

Manhattan distance: the sum of the absolute values ​​of distances in all dimensions

insert image description here
insert image description here

insert image description here
insert image description here

example

Assuming that the space coordinates are two points A ( 1 , 2 , 3 ) and B ( 3 , 5 , 7 ), the Manhattan distance between points A and B is calculated as:
insert image description here

Guess you like

Origin blog.csdn.net/cheche012345/article/details/127714885