Method DistanceSquared
DistanceSquared(Point, Point)
Calculates the squared distance between two points. Faster than Euclidean distance since no square root is taken.
public static double DistanceSquared(Point p1, Point p2)
Parameters
Returns
- double
The squared Euclidean distance between
p1andp2.
DistanceSquared(IPoint, IPoint)
Calculates the squared distance between two points provided via IPoint.
public static double DistanceSquared(IPoint p1, IPoint p2)
Parameters
Returns
- double
The squared Euclidean distance between the two points.
DistanceSquared(double, double, double, double)
Calculates the squared Euclidean distance between two 2D points provided as raw coordinate pairs.
public static double DistanceSquared(double x1, double y1, double x2, double y2)
Parameters
x1doubleThe X-coordinate of the first point.
y1doubleThe Y-coordinate of the first point.
x2doubleThe X-coordinate of the second point.
y2doubleThe Y-coordinate of the second point.
Returns
- double
The squared Euclidean distance between
x1,y1andx2,y2.
Examples
double d2 = Point.DistanceSquared(0, 0, 3, 4); // 25
Remarks
This overload avoids allocating Point instances and is typically faster than Distance(double, double, double, double) since it does not compute a square root. Prefer this method when only relative distances are required.
- See Also