In tikz/pgf I would like to draw two lines that cross a coordinate system's Y axis at the same point. I have no clue how to start it. I only know how to draw X and Y axes.
I attach an image what I would like to achieve.
Thanks,
bcsikos
Draw two lines in tikz that cross an axis at the same point
tikz-pgf
Related Solutions
The arc
operation can be used here. The general syntax as recommended by the TikZ/PGF manual (thanks to @Tobi for the comment) is
\draw (<starting point>) arc [<options>];
with these options:
radius=<dim>
x radius=<dim>
y radius=<dim>
start angle=<deg>
end angle=<deg>
delta angle=<deg>
or a less readable version
\draw (<starting point>) arc (<start angle>:<end angle>:<radius>);
where <radius>
can be a single length or <dim> and <dim>
for different radii.
Code
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ticks=none,
axis lines = middle,
axis line style={->},
ymin=-1.5, ymax=1.5,
xmin=-1.5, xmax=1.5,
axis equal]
\addplot[black, domain=0:0.7071] {x};
\draw[black] (axis cs:0,0) circle [radius=1];
\draw (axis cs:.125,0)arc[radius=.25cm,start angle=0,end angle=45];
% \draw (axis cs:.125,0)arc(0:45:.25cm); % same as above with different syntax
\end{axis}
\end{tikzpicture}
\end{document}
Output
The trick is to reset the transformation angle using \pgftransformresetnontranslations
, I had the same problem and I only found it by digging through <tex-installation-path>/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
. Only once I knew the command I discovered it in section 75.2 of the pgfmanual.
If you want to draw a straight line at a set angle the polar coordinate system is the way to go. You can then specify the angle at which the line should be drawn, and this is parsed by the mathematical engine so you can simply say 20*\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}
for example. The second argument is then the distance to the origin of the coordinate system. So if you want a constant line length relative to a point other than the origin you need to specify a relative coordinate like (0,-0.2) -- +(20:4mm)
.
Edit If you want the midpoints of these lines on the curve the easiest way is to draw to halve lines, the second one either with the same angle +180, or a negative radius. The second option is probably safer since angles should be provided as a value between -360 and +720 degrees, and adding 180 degrees is then a significant portion of the range.
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[
decoration={
markings,
mark=between positions 0.125 and 0.90 step 0.0625 with {
\pgftransformresetnontranslations
\draw[thin] (0,-0.2)--(0,0.2);},
}
]
\draw[thick,postaction={decorate}] (-2.5,-1) to (-2,-0.5)
to [out=45,in=180] (0,-1.5)
to [out=0,in=180] (2,-1)
to [out=0,in=-90] (2.5,0)
to [out=90,in=0] (1.5,1.5)
to [out=170,in=0] (0,1.5)
to [out=180,in=45] (-2,-0.2)
to [out=220,in=45] (-2.5,-1);
\end{tikzpicture}
\begin{tikzpicture}[
decoration={
markings,
mark=between positions 0.125 and 0.90 step 0.0625 with {
\pgftransformresetnontranslations
\draw[thin] (0,0)--+(canvas polar cs:angle=20*\pgfkeysvalueof{/pgf/decoration/mark info/sequence number},radius=2mm);
\draw[thin] (0,0)--+(canvas polar cs:angle=20*\pgfkeysvalueof{/pgf/decoration/mark info/sequence number},radius=-2mm);},
}
]
\draw[thick,postaction={decorate}] (-2.5,-1) to (-2,-0.5)
to [out=45,in=180] (0,-1.5)
to [out=0,in=180] (2,-1)
to [out=0,in=-90] (2.5,0)
to [out=90,in=0] (1.5,1.5)
to [out=170,in=0] (0,1.5)
to [out=180,in=45] (-2,-0.2)
to [out=220,in=45] (-2.5,-1);
\end{tikzpicture}
\end{document}
Best Answer
Here's a solution without any math, except the simple use of the
calc
library: