Mapsui: the nearest point to the polygon from the point (the tangent point of the lines)

Created on 26 Sep 2018  路  5Comments  路  Source: Mapsui/Mapsui

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:

  • there is a polygon, where the ring of it is some line with start and end points
  • there is a point (X,Y) "green"
  • from the point to the line is some distance, the shortest one, the distance's line is perpendicular to the polygon ring's line
  • the place where the distance's line comes into contact with the r-line is the closest point "red"
    how to find coordinates (X,Y) of the point?

I try some trigonometry and analytic geometry calculations but without any success for now.

Any ideas?

Best Regards,
艁ukasz

obraz

obraz

question

All 5 comments

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 ?)

obraz

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)
{
    //!!!!!!!
}

obraz

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 馃憤 :)

obraz

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pauldendulk picture pauldendulk  路  7Comments

othmaniav picture othmaniav  路  7Comments

lukaszpitulski picture lukaszpitulski  路  11Comments

charlenni picture charlenni  路  3Comments

lukaszpitulski picture lukaszpitulski  路  3Comments