Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Closest point on a segment to a given point (2D)

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Closest point on a segment to a given point (2D)


Chronological Thread 
  • From: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] Closest point on a segment to a given point (2D)
  • Date: Fri, 10 Mar 2017 08:43:28 +0100
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:5ZDDpRc7UjgrUwX/Cw0EtD6mlGMj4u6mDksu8pMizoh2WeGdxcSyZB7h7PlgxGXEQZ/co6odzbGH7ua8BidZuMrJmUtBWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYdFRrlKAV6OPn+FJLMgMSrzeCy/IDYbxlViDanb75/KBW7oR/eu8QUjoduN7s9xxTUqXZUZupawn9lK0iOlBjm/Mew+5Bj8yVUu/0/8sNLTLv3caclQ7FGFToqK2866tHluhnFVguP+2ATUn4KnRpSAgjK9w/1U5HsuSbnrOV92S2aPcrrTbAoXDmp8qlmRAP0hCoBKjU2933ah8Jyga9VuR6tuxNyyJPQbIyVKPZye6XQds4YS2VcRMZcTzFPDJ2yb4UPCOoPPuhWoIfyqFQMsRSwChKhBP/txzJSmnP6waM33uYnHArb3AIgBdUOsHHModn7KakdT/u6w7PTzTXfbvNZxzH945XOfBAmu/GMXLVwcdbMwkUrFg3KkFKQqYn7MDOJzOQMs2iV4PB8WuKzjG4nsQFwrj2hyswxjYTJnYYVylfe9SV4x4Y1Oce0SEt/YdO/H5tQsjuVN4pyQs84X25ovyM6x6QAtJWmciYKz5EnyATea/yBa4WI/xzjVPyeITdjnn5qY6i/ihCv+kaj0u3xTsu53VlQoiZYjNXBtmoB2h/N5sSdS/Zw/F+t1DSM2gzJ9O1JLkE5mbDGJ5MlzLM8jJgevETFEyTrgkv5lrWWeV8h+uWw6+TofLHmppiEOo9xkA7+M6AultWxAOQ9LgQCRmab9OW+2bH58k35R7JKjvIykqbHqpzVOcMbpquhDw9U1IYs9Qq/Ai+k3dkXh3ULMUxJdRKdg4XqJV3COvH1APWnj1SpijhrxvTGPrP7ApXKK3jOiKzhfbJ6605GyQozysxf64hRCrEFO//zVUrxu8bZDh89KQC73+HnCNBl2oMERW2PGrOZML/VsVKQ+u0vLPODZIsMtDngKvgl/OLhjWIimV8GZqSpxpsWaHWgHvt8OUmZYHzsgs0AEWgQpAY+Qvbq2xW+VmtYaH+2Gq49/TomE5mODIHZR4nrjqbS8j28G8gcXW1MA0uQEHruP6GDQfYLdGrSDcJmlzEYT6mPQoQ90gu/9UWyn6FjKfDV/TFesJbL29185umVnhY3o28nR/+B2n2AGjkn1lgDQCU7if0nrA==
  • Organization: GeometryFactory

We have it in 3D but not in 2D.
What you can do is project the point onto the supporting line,
check whether the point is inside the segment and if not pick
the endpoint of the segment that is the closest to the
projected point.

Something like this (I did not try to compile it):

typedef CGAL::EPECK K;
K::Segment_2 s;
K::Point_2 query;

K::Construct_projected_point_2 project;
K::Point_3 proj = project(s.supporting_line(), query);

if (!s.has_on(proj))
{
proj = CGAL::compare_distance_to_point(proj, s[0], s[1]) == CGAL::SMALLER ? s[0]:s[1];
}


Sebastien.



On 03/10/2017 12:34 AM, Renato Silveira wrote:
Is there a function that returns the closest point (2D) on a segment
(2D) to a given point (2D)?

Thank you in advance,
Renato

--
*/Renato Silveira
/*
Ph.D. in Computer Science
Informatics Institute - UFRGS
Porto Alegre - RS - Brazil
http://www.inf.ufrgs.br/~rsilveira




Archive powered by MHonArc 2.6.18.

Top of Page