Manifold Community Site: Closest point on a linehttp://95.79.92.2:8080/forum/t162282Manifold Community Site threadhttp://95.79.92.2:8080/forum/images/img-logo.pngManifold Community Site: Closest point on a linehttp://95.79.92.2:8080/forum/t162282RE: Closest point on a linehttp://95.79.92.2:8080/forum/t162282#162283<P>Hi all,</P><P>In M9, I have a drawing with points and another with lines. For each point, I want to find the the closest point on the line. In other words, I'd like to snap the points to the lines. The GeomDistance tells me the distance to the closest line but does not return the point. I read somewhere in this forum (https://georeference.org/forum/t160399.6#160419) that we could normalize both layers at the same time, but then either the point or the line might be moved, which is problematic to me, since I only want to change points position.</P><P>Our approach was then to draw a circle with the distance from GeomDistance as the radius and get the intersection between the line and the circle. The problem is that circles in manifold are not exact circles and sometimes the intesection returns nothing. We then added a tolerance of 1/1000 of the distance to make sure that the circle does indeed cross the line. However, we are left with two intersecting points. For our application, any of the two points is sufficiently accurate and we only consider the first point. A more accurate approach would be to calculate the middle point between the two points of the intersection.</P><P>This technique does take some time when applied to hundreds of thousands of points, whereas GeomDistance itself is very fast. Is there a faster approach to get the point geometry we are looking for? It seems to me that the geometry of the nearest point should be calculated (as temporary result) when calling the GeomDistance function. Would it be possible (and would it make sense) to have a function similar to GeomDistance that would return the geometry of the nearest point?</P><P>Any thoughts on the problem is welcome.</P>sgahttp://95.79.92.2:8080/forum/t162282#162283http://95.79.92.2:8080/forum/t162282#162283Tue, 28 Mar 2023 09:47:11 GMTRE: Closest point on a linehttp://95.79.92.2:8080/forum/t162282#162284<P>In case it helps, there has been a discussion for M8.</P><P>https://georeference.org/forum/t133743.14#133744</P>geozaphttp://95.79.92.2:8080/forum/t162282#162284http://95.79.92.2:8080/forum/t162282#162284Tue, 28 Mar 2023 13:37:54 GMTRE: Closest point on a linehttp://95.79.92.2:8080/forum/t162282#162288<P>Thank you very much geozap!</P><P>I actually was aware of this technique, yet the circle solution, while beeing less accurate, is more rapid. Even though, I'd like to speed it up a little if possible</P>sgahttp://95.79.92.2:8080/forum/t162282#162288http://95.79.92.2:8080/forum/t162282#162288Wed, 29 Mar 2023 06:10:35 GMTRE: Closest point on a linehttp://95.79.92.2:8080/forum/t162282#162297<P>Hi sga,</P><P>I have developed an add-in for these kind of tasks.</P><P>I took 23 seconds to snap 25k points to 6k lines (or 28k if splitted into segments).</P><P>See the images below. If you are interested, send me an email. (info at mppng dot nl)</P><P>Before:</P><P><IMG class='cons' id='i162297x0_elt' onclick="showhideImageElt('i162297x0_elt')" SRC='bRjkvMTYyMjk3L2JlZm9yZS5wbmc_'></P><P>After:</P><P><IMG class='cons' id='i162297x1_elt' onclick="showhideImageElt('i162297x1_elt')" SRC='bRjkvMTYyMjk3L2FmdGVyLnBuZw__'></P><p class='file'><b>Attachments:</b><br><a href='bRjkvMTYyMjk3L2FmdGVyLnBuZw__'><img src='images/dwn-ftp.gif' align='absmiddle'></a> <a href='bRjkvMTYyMjk3L2FmdGVyLnBuZw__'>after.png</a><br><a href='bRjkvMTYyMjk3L2JlZm9yZS5wbmc_'><img src='images/dwn-ftp.gif' align='absmiddle'></a> <a href='bRjkvMTYyMjk3L2JlZm9yZS5wbmc_'>before.png</a><br></p>Slootshttp://95.79.92.2:8080/forum/t162282#162297http://95.79.92.2:8080/forum/t162282#162297Thu, 30 Mar 2023 13:09:19 GMT