I've been wondering this for a while, and I haven't found anything so I figured it wasn't possible.
But why not ask anyway, just to be sure?
I have a rather complicated set of equations that is bogging down even Mathematica. But, you know, if I could just start at a point, move down this path, then along another, I'll get to the point I want to define. TikZ could do the numerical work by following simple path instructions and not have to solve the equations that are messing me up.
So, to keep this simple (and to give an explicit example):
Start at the coordinate (A)=(3,0). Move along the arc[start angle=0, end angle=90, radius=2], then move along the arc[start angle=45, end angle=180, radius=3.2]. Define coordinate (B).
Can this be done?
Thanks!
Dan
LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Is there a way to "trace" a path and define a coordinate?
 Stefan Kottwitz
 Site Admin
 Posts: 10050
 Joined: Mon Mar 10, 2008 9:44 pm
Is there a way to "trace" a path and define a coordinate?
Hi Dan,
you could put
Stefan
you could put
coordinate[at end, ...]
in the path, or use \pgfpointlineattime
from Points Traveling along Lines and Curves.Stefan
LaTeX.org admin

 Posts: 2
 Joined: Thu Sep 14, 2023 1:18 pm
Is there a way to "trace" a path and define a coordinate?
Yes, you can achieve this in TikZ by using the calc library to calculate the positions of points along the specified paths without explicitly solving the equations. Here's how you can define the coordinate (B) based on your description:
In this code, we start by defining the coordinate (A). Then, we draw the first arc using 'arc' command and calculate the endpoint of this arc using the 'calc' library. Next, we draw the second arc from the endpoint of the first arc to its endpoint, and finally, we define the coordinate (B) at the endpoint of the second arc. The result is a TikZ diagram with points A and B connected by the specified arcs.
\documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} % Define starting point A \coordinate (A) at (3,0); % Draw the first arc \draw ($(A) + (0:2)$) arc (0:90:2); % Calculate the end point of the first arc \coordinate (temp) at ($(A) + (45:2)$); % Draw the second arc \draw ($(temp) + (45:3.2)$) arc (45:180:3.2); % Define point B \coordinate (B) at ($(temp) + (180:3.2)$); % Just for visualization, draw lines from A to B \draw (A)  (B); % Mark points A and B \filldraw (A) circle (2pt) node[below] {A}; \filldraw (B) circle (2pt) node[below] {B}; \end{tikzpicture} \end{document}
In this code, we start by defining the coordinate (A). Then, we draw the first arc using 'arc' command and calculate the endpoint of this arc using the 'calc' library. Next, we draw the second arc from the endpoint of the first arc to its endpoint, and finally, we define the coordinate (B) at the endpoint of the second arc. The result is a TikZ diagram with points A and B connected by the specified arcs.
Is there a way to "trace" a path and define a coordinate?
Stefan Kottwitz wrote:Hi Dan,
you could putcoordinate[at end, ...]
in the path, or use\pgfpointlineattime
from Points Traveling along Lines and Curves.
Stefan
Thank you. I had seen the PGF/TikZ package section, but as I might be using irregular paths, this isn't going to work that well.
I tried
\coordinate[at end] (A) (0,0) arc(0:90:2);
for example. Clearly my guess at the syntax is wrong, and I can't find anything on the net about it.
(If I do something, more correctly to my mind, like
\coordinate[at end] (A) at (0,0) arc(0:90:2);
it defines (A) to be the origin.)
How do you structure the command? Or is there yet another online manual that I might have missed that would address something like this?
Thanks again!
Dan
Is there a way to "trace" a path and define a coordinate?
FlorElbert wrote:Yes, you can achieve this in TikZ by using the calc library to calculate the positions of points along the specified paths without explicitly solving the equations. Here's how you can define the coordinate (B) based on your description:\documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} % Define starting point A \coordinate (A) at (3,0); % Draw the first arc \draw ($(A) + (0:2)$) arc (0:90:2); % Calculate the end point of the first arc \coordinate (temp) at ($(A) + (45:2)$); % Draw the second arc \draw ($(temp) + (45:3.2)$) arc (45:180:3.2); % Define point B \coordinate (B) at ($(temp) + (180:3.2)$); % Just for visualization, draw lines from A to B \draw (A)  (B); % Mark points A and B \filldraw (A) circle (2pt) node[below] {A}; \filldraw (B) circle (2pt) node[below] {B}; \end{tikzpicture} \end{document}
In this code, we start by defining the coordinate (A). Then, we draw the first arc using 'arc' command and calculate the endpoint of this arc using the 'calc' library. Next, we draw the second arc from the endpoint of the first arc to its endpoint, and finally, we define the coordinate (B) at the endpoint of the second arc. The result is a TikZ diagram with points A and B connected by the specified arcs.
Thanks for the input. I honestly hadn't considered defining the intermediate points (so thank you for that!) but it won't do my any good, in general. I was able to find a solution via geometry in the case I mentioned I was working on (not the simple example I posted in the OP) but I would like to find a way to do this if I can't calculate the intermediate points. For example, if I wanted to trace along an ellipse or something.
Thanks again!
Dan
Is there a way to "trace" a path and define a coordinate?
Hi Dan,
well,
For getting points along the arc (or whatever curve you have), you can use options like `at start', `near end', etc, or its `pos=..' counterpart :
If you just want to get to the end of your arc, you don't even need `at end' or `pos=1':
See also in pgfmanual section `Placing Nodes on a Line or Curve Explicitly'.
KR
Rainer
topsquark wrote:I tried
\coordinate[at end] (A) (0,0) arc(0:90:2);
well,
\coordinate
is basically a node without a size of its own, hence the arc will be put into nothing, so to speak.For getting points along the arc (or whatever curve you have), you can use options like `at start', `near end', etc, or its `pos=..' counterpart :
\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \coordinate (P) at (1,1); \draw[black!30] (0,0) arc(0:90:2) coordinate[at start] (A)% or pos=0 coordinate[pos=0.25] (B)% or near start coordinate[midway] (C)% or pos=0.5 coordinate[pos=0.75] (D)% or near end coordinate[at end] (E)% or pos=1 arc(30:120:1) coordinate[midway] (F) coordinate[at end] (G); \draw[blue] (P) node[left]{P}  (A); \draw[blue!50] (P)  (B); \draw[blue!10] (P)  (C); \draw[black!10] (P)  (D); \draw[red!10] (P)  (E); \draw[red!50] (P)  (F); \draw[red] (P)  (G); \end{tikzpicture} \end{document}
If you just want to get to the end of your arc, you don't even need `at end' or `pos=1':
\begin{tikzpicture} \coordinate (P) at (1,1); \draw[black!30] (0,0) arc(0:90:2) coordinate (Y) arc(30:120:1) coordinate (Z) ; \draw[blue] (P) node[left]{P}  (Y); \draw[red] (P)  (Z); \end{tikzpicture}
See also in pgfmanual section `Placing Nodes on a Line or Curve Explicitly'.
KR
Rainer
Is there a way to "trace" a path and define a coordinate?
rais wrote:Hi Dan,topsquark wrote:I tried
\coordinate[at end] (A) (0,0) arc(0:90:2);
well,\coordinate
is basically a node without a size of its own, hence the arc will be put into nothing, so to speak.
For getting points along the arc (or whatever curve you have), you can use options like `at start', `near end', etc, or its `pos=..' counterpart :\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \coordinate (P) at (1,1); \draw[black!30] (0,0) arc(0:90:2) coordinate[at start] (A)% or pos=0 coordinate[pos=0.25] (B)% or near start coordinate[midway] (C)% or pos=0.5 coordinate[pos=0.75] (D)% or near end coordinate[at end] (E)% or pos=1 arc(30:120:1) coordinate[midway] (F) coordinate[at end] (G); \draw[blue] (P) node[left]{P}  (A); \draw[blue!50] (P)  (B); \draw[blue!10] (P)  (C); \draw[black!10] (P)  (D); \draw[red!10] (P)  (E); \draw[red!50] (P)  (F); \draw[red] (P)  (G); \end{tikzpicture} \end{document}
If you just want to get to the end of your arc, you don't even need `at end' or `pos=1':\begin{tikzpicture} \coordinate (P) at (1,1); \draw[black!30] (0,0) arc(0:90:2) coordinate (Y) arc(30:120:1) coordinate (Z) ; \draw[blue] (P) node[left]{P}  (Y); \draw[red] (P)  (Z); \end{tikzpicture}
See also in pgfmanual section `Placing Nodes on a Line or Curve Explicitly'.
KR
Rainer
Ah! I see now. Honestly, I should have seen that. Thank you!
And thank you for the pdf of the manual. The search system for the pdf works incredibly better than the online version.
Thanks again to Stefan as well!
Dan
Is there a way to "trace" a path and define a coordinate?
OMG! I was able to use that to not only eliminate the 14 path intersections I was taking, but I was also able to collapse some two pages of code into 10 lines. And not only is the code more efficient, it runs much much faster.
Thank you again!
Dan
Just for the record:
Thank you again!
Dan
Just for the record:
\documentclass{article} \usepackage{tikz} \begin{document} \def\R{2} \begin{tikzpicture} \foreach \t in {0,...,35}{ \begin{scope}[rotate=\t*10] \foreach \s in {1,...,14}{ \path (0:2*\R) arc(0:{(\s1)*10}:\R) coordinate[at end] (A); \path (0:2*\R) arc(0:{\s*10}:\R) coordinate[at end] (B); \path[transform canvas] (B); \pgfgetlastxy{\xcoord}{\ycoord} \pgfmathsetmacro{\Xcoord}{scalar{\xcoord}/28.452756} \pgfmathsetmacro{\Ycoord}{scalar{\ycoord}/28.452756} \pgfmathsetmacro{\rad}{sqrt((\Xcoord)^2+(\Ycoord)^2)} \filldraw (A) arc({(\s1)*10}:{\s*10}:\R) arc({\s*5}:{\s*510}:\rad) arc(10:0:\R); } \end{scope} } \end{tikzpicture} \end{document}

 Posts: 2
 Joined: Thu Sep 14, 2023 1:18 pm
Is there a way to "trace" a path and define a coordinate?
Yes, you can achieve this with TikZ, a powerful tool for creating graphics in LaTeX. You can use the "calc" library to compute coordinates along a path without solving equations manually. If you're looking to make the most of your assignment help choices, then this article on Europeanbusinessreview is for you! For more info visit this. It's not just a resource, it's a guide to academic excellence. It looks at 5 of the best assignment help websites and goes into detail about their strengths and advantages. If you want to make sure your academic journey is smooth and successful, then this article is a mustread!
Return to “Graphics, Figures & Tables”
Who is online
Users browsing this forum: No registered users and 14 guests