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

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

tikz find the closest point to a defined point

Post by melondolphin »

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

\begin{tikzpicture}

\coordinate (North) at (0,5);

\path let
  \p1 = ($(North)-(node_1)$), \n1 = {veclen(\x1,\y1)}
, \p2 = ($(North)-(node_2)$), \n2 = {veclen(\x2,\y2)}
, \p3 = ($(North)-(node_3)$), \n3 = {veclen(\x3,\y3)}
, \p4 = ($(North)-(node_4)$), \n4 = {veclen(\x4,\y4)}
in coordinate (dummy1) at (\x1, \y1)
coordinate (dummy2) at (\x2, \y2)
coordinate (dummy3) at (\x3, \y3)
coordinate (dummy4) at (\x4, \y4);

\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)
elseif...

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 me...so Im looking forward to any suggestions or help :roll: :roll: ...

I also asked this question here in German: https://golatex.de/viewtopic,p,106794.html#106794
and here in English: https://tex.stackexchange.com/questions ... ther-point

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

tikz find the closest point to a defined point

Post by Stefan Kottwitz »

Hello,

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
LaTeX.org admin
Post Reply