Hi,
Is it chance to have by Mapsui methods a solution for the query below?
How to find the closest point of polygon ring to external point?
More precisely:
I try some trigonometry and analytic geometry calculations but without any success for now.
Any ideas?
Best Regards,
艁ukasz


There are many websites for this. Mapsui isn鈥榯 the correct place to find it.
https://en.m.wikipedia.org/wiki/Distance_from_a_point_to_a_line
https://stackoverflow.com/questions/10983872/distance-from-a-point-to-a-polygon
I was hoping the Mapsui would help me, using some methods/algorithms.
But I have the solution already (for the lines). From pattern of point of intersection of two straight lines.
I still have to find the line of the polygon which intersects with the line from the ext-point.
(polygon.InteriorRings ?)

Sorry, but it doesn't give me peace.
It's impossible that Mapsui doesn't have the right methods.
What with Mapsui.Geometries.Utilities.Algorithms and Mapsui.Geometries.Utilities.CGAlgorithms methods?
I already have some kind of solution of the issue.
I can find the closest Vertex of the polygon to the point. :)
double minDist = Double.MaxValue;
Point pointX = null;
Point lastVertex = null;
foreach (var vertex in polygon.ExteriorRing.Vertices)
{
if (lastVertex != null)
{
var dist2L = Mapsui.Geometries.Utilities.CGAlgorithms.DistancePointLine(thePoint, lastVertex, vertex);
//var dist2L = Mapsui.Geometries.Utilities.Algorithms.DistanceToLine(thePoint, new List<Point>(new[] { lastVertex, vertex }));
if (dist2L < minDist)
{
minDist = dist2L;
pointX = Mapsui.Geometries.Utilities.CGAlgorithms.ClosestPoint(thePoint, lastVertex, vertex);
}
}
lastVertex = vertex;
}
if (pointX != null)
{
//!!!!!!!
}

now I've found (using http://mapsui.github.io/Mapsui/api/Mapsui.Geometries.Utilities.Algorithms.html) this method (.NET 4.7.1):
Mapsui.Geometries.Utilities.Algorithms.GetDistanceAndSegmentIndex
and I have:
var distSeg = Mapsui.Geometries.Utilities.Algorithms.GetDistanceAndSegmentIndex(thePoint, polygon.ExteriorRing.Vertices);
var segment = polygon.ExteriorRing.GetSegments()[distSeg.Segment];
var pointX = Mapsui.Geometries.Utilities.CGAlgorithms.ClosestPoint(thePoint, segment.StartPoint, segment.EndPoint);
It is a pity that I wasted so much time.
UPDATE
"I can find the closest Vertex of the polygon to the point."
The closest Point !
GetDistanceAndSegmentIndex + ClosestPoint - works perfectly for me 馃憤 :)
