I want to draw something like this using TikZ:
I can probably make the curve using controls but that wouldn't allow me to draw the points on it.
tikz-pgf
I want to draw something like this using TikZ:
I can probably make the curve using controls but that wouldn't allow me to draw the points on it.
The starting point is the head, here at (0,0)
, and the body a triangle with some bended lines and rounded corners. For simplicity I added some coordinates for the triangle as well.
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (head-center) at (0,0);
\coordinate (top) at ([yshift=-2mm]head-center);
\coordinate (left) at ([yshift=-10mm,xshift=-7mm]head-center);
\coordinate (right) at ([yshift=-10mm,xshift=7mm]head-center);
%%
\draw[rounded corners=1.5mm,fill=blue!30]
(top) to [out=-10,in=100]
(right) to [bend left=15]
(left) to [out=80,in=190]
(top);
\draw[fill=yellow,opacity=1] (head-center) circle (0.35);
\end{tikzpicture}
\end{document}
Edit
To get bended lines an easy way is to say to [bend left]
instead of --
in the path. In this case the reference line is a straight line between the starting and ending coordinates. The drawn line starts 30 degrees left of the reference line and enter the target coordinate 30 degrees from left. See lines 1 and 2 below. You can change the default bending angle of 30 degrees by stating e.g. to [bend left]
as in the figure above.
However, if you want different angles at the start and end of the line it is possible to assign any angles with to [out=30,in=30]
, where it is set to 30 degrees for both. As can be seen in line 3 below these angles are not relative the straight line as before, it is relative the unit circle. So 30 degrees point up to the left for both ends.
To get the same bend as before we need to derive the right values of the angles. As the outgoing angle of the straight line is 45 degrees (in this case) we need to add 30 degrees. The ending angle of straight line is 180+45=225 degrees, and having the line coming in from left gives 225-30. See line 4.
Then back to the silhouette figure. The bend of the lower line is just 15 degrees in each end, which is easiest done by stating to [bend left=15]
. The others look better if they have different bending angles in start and end. For the left side of the triangle (the body) it set to 80 degrees at the start and 180+10 degrees at the end, that is in both ends 10 degrees from right angles.
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0) -- (1,1) node [above]{1};
\draw[->,xshift=1cm] (0,0) to [bend left] (1,1) node [above]{2}; % bend 30 degree
\draw[->,xshift=2cm] (0,0) to [out=30,in=30] (1,1) node [above]{3};
\draw[->,xshift=3cm] (0,0) to [out=45+30,in=225-30] (1,1) node [above]{4};
\end{tikzpicture}
\end{document}
The parabola
path command makes only parabolas of the kind y=a*x+b
, still you're free to rotate, scale, slant it or whatever. So you want to mirrow it, the question remains: Can we mirror a part in tikz? Oh yes we can:
\documentclass{standalone}
\usepackage{tikz}
% Code from user Qrrbrbirlbel (https://tex.stackexchange.com/a/142491/81905)
\usetikzlibrary{backgrounds}
\makeatletter
\tikzset{
mirror/.code={\pgfutil@in@{--}{#1}\ifpgfutil@in@\tikz@trans@mirror#1\@nil
\else\tikz@scan@one@point\pgftransformmirror#1\relax\fi},
ymirror/.code={\pgfutil@ifnextchar(\tikz@trans@ymirror@coordinate\tikz@trans@ymirror@simple#1\@nil},
xmirror/.code={\pgfutil@ifnextchar(\tikz@trans@xmirror@coordinate\tikz@trans@xmirror@simple#1\@nil}}
\def\tikz@trans@mirror#1--#2\@nil{%
\pgfextract@process\pgf@trans@mirror@A{\tikz@scan@one@point\pgfutil@firstofone#1}%
\pgfextract@process\pgf@trans@mirror@B{\tikz@scan@one@point\pgfutil@firstofone#2}%
\pgftransformMirror{\pgf@trans@mirror@A}{\pgf@trans@mirror@B}}
\def\pgftransformxmirror#1{\pgfmathparse{2*(#1)}\pgftransformcm{-1}{0}{0}{1}{\pgfqpoint{+\pgfmathresult pt}{+0pt}}}
\def\pgftransformymirror#1{\pgfmathparse{2*(#1)}\pgftransformcm{1}{0}{0}{-1}{\pgfqpoint{+0pt}{+\pgfmathresult pt}}}
\def\tikz@trans@ymirror@simple#1\@nil{
\pgfmathparse{#1}\let\tikz@temp\pgfmathresult
\ifpgfmathunitsdeclared
\pgftransformymirror{\tikz@temp pt}%
\else
\pgf@process{\pgfpointxy{0}{\tikz@temp}}%
\pgftransformymirror{+\the\pgf@y}%
\fi}
\def\tikz@trans@xmirror@simple#1\@nil{
\pgfmathparse{#1}\let\tikz@temp\pgfmathresult
\ifpgfmathunitsdeclared
\pgftransformxmirror{\tikz@temp pt}%
\else
\pgf@process{\pgfpointxy{\tikz@temp}{0}}%
\pgftransformxmirror{+\the\pgf@x}%
\fi}
\def\tikz@trans@xmirror@coordinate#1\@nil{\tikz@scan@one@point\pgfutil@firstofone#1\pgftransformxmirror{+\the\pgf@x}}
\def\tikz@trans@ymirror@coordinate#1\@nil{\tikz@scan@one@point\pgfutil@firstofone#1\pgftransformymirror{+\the\pgf@y}}
\def\pgftransformmirror#1{%
\pgfpointnormalised{#1}%
\pgf@xa=\pgf@sys@tonumber\pgf@y\pgf@x
\pgf@xb=\pgf@sys@tonumber\pgf@x\pgf@x
\pgf@yb=\pgf@sys@tonumber\pgf@y\pgf@y
\multiply\pgf@xa2\relax
\pgf@xc=-\pgf@yb\advance\pgf@xc\pgf@xb
\pgf@yc=-\pgf@xb\advance\pgf@yc\pgf@yb
\edef\pgf@temp{{\the\pgf@xc}{+\the\pgf@xa}{+\the\pgf@xa}{+\the\pgf@yc}}%
\expandafter\pgf@transformcm\pgf@temp{\pgfpointorigin}}
\def\pgftransformMirror#1#2{%
\pgfextract@process\pgf@trans@mirror@A{#1}%
\pgfextract@process\pgf@trans@mirror@B{#2}%
\pgfextract@process\pgf@trans@mirror@g{\pgfpointdiff{\pgf@trans@mirror@A}{\pgf@trans@mirror@B}}%
\pgftransformshift{\pgf@trans@mirror@A}%
\pgftransformmirror{\pgf@trans@mirror@g}%
\pgftransformshift{\pgfpointscale{-1}{\pgf@trans@mirror@A}}}
\makeatother
%End of code from Qrrbrbirlbel
\begin{document}
\begin{tikzpicture}
\draw (-3,4) parabola bend (0,-.5) (3,4);
\draw[thick, <->] (-3,0) -- (3,0);
\draw[thick, <->] (0,-3) -- (0,4);
\coordinate (1) at (-3,-3);
\coordinate (2) at (3,3);
\draw[dashed,very thin] (1)--(2);
\draw[mirror=(1)--(2),red] (-3,4) parabola bend (0,-.5) (3,4);
\end{tikzpicture}
\end{document}
Best Answer
You could use the intersections library. Here is a modified version of one of the examples from the pgfmanual (TikZ 2.0). It's reasonable close to your figure and you should be able to modify it.
This might be better?