Graphics, Figures & Tables ⇒ Is there a way to "trace" a path and define a coordinate?
Is there a way to "trace" a path and define a coordinate?
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
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
Is there a way to "trace" a path and define a coordinate?
you could put
coordinate[at end, ...]
in the path, or use \pgfpointlineattime
from Points Traveling along Lines and Curves.Stefan
Is there a way to "trace" a path and define a coordinate?
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.Stefan Kottwitz wrote:Hi Dan,
you could putcoordinate[at end, ...]
in the path, or use\pgfpointlineattime
from Points Traveling along Lines and Curves.
Stefan
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?
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.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:
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.Code: Select all
\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}
Thanks again!
-Dan
Is there a way to "trace" a path and define a coordinate?
well,topsquark wrote: I tried
\coordinate[at end] (A) (0,0) arc(0:90:2);
\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 :
Code: Select all
\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}
Code: Select all
\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}

KR
Rainer
Is there a way to "trace" a path and define a coordinate?
Ah! I see now. Honestly, I should have seen that. Thank you!rais wrote:Hi Dan,well,topsquark wrote: I tried
\coordinate[at end] (A) (0,0) arc(0:90:2);\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 :If you just want to get to the end of your arc, you don't even need `at end' or `pos=1':Code: Select all
\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}
See also inCode: Select all
\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}
pgfmanual section `Placing Nodes on a Line or Curve Explicitly'.
KR
Rainer
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?
Thank you again!
-Dan
Just for the record:
Code: Select all
\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:{(\s-1)*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({(\s-1)*10}:{\s*10}:\R) arc({\s*5}:{\s*5-10}:\rad) arc(-10:0:\R);
}
\end{scope}
}
\end{tikzpicture}
\end{document}