# Geometry Library • ### Question

• Hi

Is there ,NET  library with the following capablity:

1) Calculate minimum distance between
Point and polygon.
Line and polygon.

2)Calculate minimum distance between 2 polygons?

pop

Saturday, February 21, 2015 9:19 PM

• Hello Orent,

I think you can do this simple task yourself, because an external Library would be a big overhead, because they also have a lot of other stuff.

This tasks are simple, because the Point is a Point, the Line contains two Points and the polygon N Points.

You can simply iterrate through this Points to see which is the nearest!

Example:

```//c# Code

//Get Distance
double CalcDistance(Point a, Point b) {
//pythagorean theorem: c^2 = a^2 + b^2
//thus c = square_root(a^2 + b^2)
double a = (double)(b.X - a.X);
double b = (double)(b.Y - a.Y);
return Math.Sqrt(a * a + b * b);
}

//A simple but not effective implementation - do not use frequently (60 times per second or so :D ) with big Polygons!

Point GetNearestPointFromPolygon(Point a, Point[] polygon /* A Polygon is a List of Points */) {
double dis = double.MaxValue;
Point polyPoint; //The nearest Point
foreach(Point p in polygon) {
double num1 = CalcDistance(a, p);
if(num1 < dis) { //New, nearer Point found!
dis = num1;
polyPoint = p;
}
}
return polyPoint;
}```