Table of Contents

Method ManhattanDistance

Namespace
LMKit.Graphics.Geometry
Assembly
LM-Kit.NET.dll

ManhattanDistance(Point, Point)

Calculates the Manhattan distance (L1 norm) between two points.

public static double ManhattanDistance(Point p1, Point p2)

Parameters

p1 Point

The first point.

p2 Point

The second point.

Returns

double

The Manhattan distance |p1.X - p2.X| + |p1.Y - p2.Y|.

Remarks

The Manhattan metric (also known as taxicab distance) is often used in grid-based geometry and when movement is constrained to horizontal and vertical directions.

ManhattanDistance(IPoint, IPoint)

Calculates the Manhattan distance (L1 norm) between two points provided via IPoint.

public static double ManhattanDistance(IPoint p1, IPoint p2)

Parameters

p1 IPoint

The first point.

p2 IPoint

The second point.

Returns

double

The Manhattan distance |p1.X - p2.X| + |p1.Y - p2.Y|.

Remarks

Use this overload when working with interfaces or other types that implement IPoint.

ManhattanDistance(double, double, double, double)

Calculates the Manhattan distance (L1 norm) between two 2D points provided as raw coordinate pairs.

public static double ManhattanDistance(double x1, double y1, double x2, double y2)

Parameters

x1 double

The X-coordinate of the first point.

y1 double

The Y-coordinate of the first point.

x2 double

The X-coordinate of the second point.

y2 double

The Y-coordinate of the second point.

Returns

double

The Manhattan distance |x1 - x2| + |y1 - y2|.

Examples

double d = Point.ManhattanDistance(0, 0, 3, 4); // 7

Remarks

Use this overload to avoid allocating Point instances when you already have raw coordinates.

See Also