LaTeX forum ⇒ Graphics, Figures & Tablestikz find the closest point to a defined point

Information and discussion about graphics, figures & tables in LaTeX documents.
Posts: 1
Joined: Fri Jun 14, 2019 5:20 pm

tikz find the closest point to a defined point

Postby melondolphin » Fri Jun 14, 2019 5:50 pm

Dear all,

At the moment, I try to learn automation of graphic drawing with latex (tikz) and R.

I need to determine the coordinates of the point with the smallest distance to a defined point "North"

Thats what I found out so far:

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \begin{tikzpicture}
  3. \coordinate (North) at (0,5);
  5. \path let
  6. \p1 = ($(North)-(node_1)$), \n1 = {veclen(\x1,\y1)}
  7. , \p2 = ($(North)-(node_2)$), \n2 = {veclen(\x2,\y2)}
  8. , \p3 = ($(North)-(node_3)$), \n3 = {veclen(\x3,\y3)}
  9. , \p4 = ($(North)-(node_4)$), \n4 = {veclen(\x4,\y4)}
  10. in coordinate (dummy1) at (\x1, \y1)
  11. coordinate (dummy2) at (\x2, \y2)
  12. coordinate (dummy3) at (\x3, \y3)
  13. coordinate (dummy4) at (\x4, \y4);
  15. \end{tikzpicture}

The points node_1 to node_4 are determined in advance.
My basic idea was to implement something like an if loop:

if \n1 == min(n1, \n2, \n3,\n4) then coordinate (nearest_to_north) at (node_1)
elseif \n2 == min(n1, \n2, \n3,\n4) then coordinate (nearest_to_north) at (node_2)

The whole Latex-codes is embedded in an *.Rnw-File so it would also be possibel to implement the loop in R-code but I also dont understand how to transfair the latex commands \n1, \x1, \y1 to R.

The tikz syntax is very confusing to Im looking forward to any suggestions or help :roll: :roll: ...

I also asked this question here in German:,p,106794.html#106794
and here in English:

User avatar
Stefan Kottwitz
Site Admin
Posts: 9567
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Fri Jun 14, 2019 8:16 pm


welcome to the forum!

Than you for providing the links to the other sites. I saw there is already a solution. Also I like TikZ and the great results we can achieve with TikZ: I would be happy to see an example of the drawings you create.

Best regards,

Stefan admin

Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 2 guests