I am trying to make 3d figures (great dodecahedron, small stellated dodecahedron) for which till now I was using tikz package in latex. Using \coordinate and \draw functions I managed to generate exact stencil for these models.
Now instead of making polyhedrons, I am trying to add floral patterns to it using tikz only, as I am not good at sketching.
That is importing jpg images (with floral patterns) into triangles drawn using tikz so as to make stencil for polyhedrons, like:
I know how to import graphics in latex and how to make make geometric patterns using tikz, but do not know how to "crop" jpg file into triangle or any other polygon whose coordinates are specified in tikz.
For example following is the code I am using to make one surface containing 10 triangles.
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz,ifthen}
\usetikzlibrary{calc,intersections,patterns}
\usepackage[paper=a4paper,dvips,top=.7cm,left=1.5cm,right=1.5cm, foot=1.2cm,bottom=1cm]{geometry}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[scale=0.95,thin,rotate=0]
\coordinate (O) at (0cm,0cm);
\coordinate (A) at ($(O) + (36:3cm)$);
\coordinate (B) at ($(A) + (-36:3cm)$);
\coordinate (C) at ($(O) + (-36:3cm)$);
\coordinate (X) at ($(O) + (4.78mm,1.56mm)$);
\coordinate (Y) at ($(A) + (0mm,-1.9mm)$);
\coordinate (Z) at ($(B) + (-4.78mm,1.56mm)$);
\coordinate (X1) at ($(O) + (4.78mm,-1.56mm)$);
\coordinate (Y1) at ($(O) + (-36:3cm) + (0mm,1.9mm)$);
\coordinate (Z1) at ($(B) + (-4.78mm,-1.56mm)$);
\foreach \i in {0,72,...,360}{
\draw[gray, thin] let \p0=(O), \p1=(A), \p2=(B), \p3=(C) in
[rotate around={\i:(O)}] (\p2)--(\p1)--(\p0)--(\p2)--(\p3);
\draw[gray,thin,dashed] let \p1=(X), \p2=(Y), \p3=(Z) in
[rotate around={\i:(O)}] (\p1)--(\p2)--(\p3)--cycle;
\draw[gray,thin,dashed] let \p1=(X1), \p2=(Y1), \p3=(Z1) in
[rotate around={\i:(O)}] (\p1)--(\p2)--(\p3)--cycle;
}
\foreach \density in {20,30,...,160}{
\foreach \i in {0,72,...,360}{
\draw[fill=Magenta!\density] let \p1=(X), \p2=(Y), \p3=(Z) in
[rotate around={\i:(O)}] (\p1)--(\p2)--(\p3)--cycle;
}
\path
(X) coordinate (X1)
-- (Y) coordinate[pos=.15](X)
-- (Z) coordinate[pos=.15](Y)
-- (X1) coordinate[pos=.15](Z);
}
\end{tikzpicture}
\end{document}
This is the image it generates:
The problem is that the pattern in the image is also generated by tex, what I want is given any floral/non-floral pattern (that I choose) can I crop inside a triangle (the triangle is at some specific location in tex figure).
Any help would be greatly appreciated.
Thanks.
Reading pages 1062-1072 of the PGF Manual, I wrote the following test code:
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\filldraw [red] (0,0) rectangle (4,2);
\pgftext {\pgfimage[interpolate=true,width=1cm,height=1cm]{sample}}
\pgftext[at=\pgfpoint{28mm}{0.8cm},left,base] {\pgfimage[interpolate=true,width=1cm,height=1cm]{sample}}
\end{tikzpicture}
\end{document}
In the same folder where I saved a .tex file with the code above, I also saved this picture as sample.png. Here is a screenshot of the output of the tex compiled:
It shows the effect of positioning the png graphic using the commands \pgftext and \pgfpoint with or without attributes 28mm and 0.8cm.
Please add your feedback in a comment so we can watch deeper into it. Also, to have your code added to the question would help being more precise!
Addendum
Here is how I applied the idea in my code above to the code you added to the question:
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz,ifthen}
\usetikzlibrary{calc,intersections,patterns}
\usepackage[paper=a4paper,dvips,top=.7cm,left=1.5cm,right=1.5cm, foot=1.2cm,bottom=1cm]{geometry}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[scale=0.95,thin,rotate=0]
\coordinate (O) at (0cm,0cm);
\coordinate (A) at ($(O) + (36:3cm)$);
\coordinate (B) at ($(A) + (-36:3cm)$);
\coordinate (C) at ($(O) + (-36:3cm)$);
\coordinate (X) at ($(O) + (4.78mm,1.56mm)$);
\coordinate (Y) at ($(A) + (0mm,-1.9mm)$);
\coordinate (Z) at ($(B) + (-4.78mm,1.56mm)$);
\coordinate (X1) at ($(O) + (4.78mm,-1.56mm)$);
\coordinate (Y1) at ($(O) + (-36:3cm) + (0mm,1.9mm)$);
\coordinate (Z1) at ($(B) + (-4.78mm,-1.56mm)$);
\foreach \i in {0,72,...,360}{
\draw[gray, thin] let \p0=(O), \p1=(A), \p2=(B), \p3=(C) in
[rotate around={\i:(O)}] (\p2)--(\p1)--(\p0)--(\p2)--(\p3);
\draw[gray,thin,dashed] let \p1=(X), \p2=(Y), \p3=(Z) in
[rotate around={\i:(O)}] (\p1)--(\p2)--(\p3)--cycle;
\draw[gray,thin,dashed] let \p1=(X1), \p2=(Y1), \p3=(Z1) in
[rotate around={\i:(O)}] (\p1)--(\p2)--(\p3)--cycle;
}
\foreach \density in {20,30,...,160}{
\path
(X) coordinate (X1)
-- (Y) coordinate[pos=.15](X)
-- (Z) coordinate[pos=.15](Y)
-- (X1) coordinate[pos=.15](Z);
}
% including graphics from external file:
\foreach \i in {0,72,...,360}{
\pgftext[at=\pgfpoint{2cm*cos(\i)}{2cm*sin(\i)},left,base,rotate=\i]
{\pgfimage[interpolate=true,width=1cm,height=1cm]{sample}}
}
\end{tikzpicture}
\end{document}
To include the graphics from external file, I chose a \foreach loop, but only for the sake of using five times the same image. The key point is that the line:
\pgftext[at=\pgfpoint{2cm*cos(\i)}{2cm*sin(\i)},left,base,rotate=\i]
{\pgfimage[interpolate=true,width=1cm,height=1cm]{sample}}
should allow you to position the external graphics using the attributes 2cm*cos(\i), 2cm*sin(\i), left, base and rotate=\i only.
You may avoid the \foreach loop and use one single
\pgftext[at=\pgfpoint ... ] {\pgfimage[ ... ]{filename}}
for each of your external files. If you can generate transparent-background images for your triangle graphics, you may then enjoy this solution.
The output of mine:
Related
I'm trying to draw a curve using two seperate paths.
The Line I want to draw should use path=\pathX and use path=\pathY
but I don't want it to draw the entire paths which is why I helped myself clipping both paths. I'd also like to join both path segments with lines on either end which I somehow
achieved. Yet I would like all four segments to be drawn as one continuous curve unlike
what you see in the graphic I attached.
My MWE is as follows.
\documentclass[tikz]{standalone}
\usepackage[]{tikz}
\usetikzlibrary{%
calc,%
intersections,%
}%
\begin{document}
\def\dimx{5}
\def\dimy{5}
\begin{tikzpicture}[]
\path [name path=I, save path=\pathI] ($.25*(\dimx,0)$) rectangle ($.75*(\dimx,0) + .85*(0,\dimy)$);
\coordinate [] (p11) at ($0.1*(0,\dimy) + .1*(\dimx,0)$);
\coordinate [] (p12) at ($0.65*(0,\dimy) + .9*(\dimx,0)$);
\coordinate [] (p21) at ($0.2*(0,\dimy) + .1*(\dimx,0)$);
\coordinate [] (p22) at ($0.95*(0,\dimy) + .9*(\dimx,0)$);
\draw [name path=p1, save path=\pathC]
(p11) to [out=25, in=220] node [at end, anchor=west] {$p_1$} (p12);
\draw [name path=p2, save path=\pathA]
(p21) to [out=35, in=230] node [at end, anchor=west] {$p_2$} (p22);
\path [name intersections={of=p1 and I}] coordinate (4) at (intersection-2);
\path [name intersections={of=p1 and I}] coordinate (1) at (intersection-1);
\path [name intersections={of=p2 and I}] coordinate (3) at (intersection-2);
\path [name intersections={of=p2 and I}] coordinate (2) at (intersection-1);
\begin{scope}[]
\path [clip, use path=\pathI];
\path [name path=p1, save path=\pathX]
(p21) to [out=35, in=230]
node [at end, anchor=west] {$p_1$}
coordinate [pos=0.15] (A)
coordinate [pos=0.7] (B)
(p22);
\path [name path=p3, save path=\pathY]
(p11) to [out=25, in=220]
node [at end, anchor=west] {$p_3$}
(p12);
\draw [thick, blue] edge [use path=\pathY] edge [use path=\pathX];
\end{scope}
\draw [thick, blue] (1) -- (2) (3) -- (4);
\end{tikzpicture}
\end{document}
I might be using a completely wrong approach here but that's as far as google and the pgf manual got me.
Any suggestions I'll greatly appreciate. Thanks in advance.
Here is the diagram I am trying to make using tikz. Blocks A, B and C are inside a block (here, block with red background) and blocks E and F are inside another block. The two huge blocks (with red background) have labels on top (LabA and LabB). Moreover, I would like block E to be right and in the middle of the blocks A and B. And arrows going to block E should have some bending angle; so, not like in the one I have tried.
Here is my code.
\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\tikzstyle{block} = [draw=black, thick, text width=2cm, minimum height=1cm, align=center]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}
\node[block] (a) {a};
\node[block, below=of a, yshift=0.7cm] (b) {b};
\node[block, below=of b, yshift=0.7cm] (c) {c};
\node[block, right=of c, xshift=0.7cm] (d) {d};
\node[block, right=of a, xshift=0.7cm, yshift=-0.4cm] (e) {e};
\draw [arrow] (a) -- (e);
\draw [arrow] (b) -- (e);
\draw [arrow] (c) -- (d);
\end{tikzpicture}
\end{document}
How could I add a rectangle over some nodes and write a label on top of it.
How to have the arrows here with a certain angle of inclination (not straight), and also to have the E block in the middle and in right of the A and B blocks. I though I could get the arrows with \draw [arrow] (a) -|- (e);, but it does not work.
Thank you in advance
I gave it a try in the hope of getting the requirements right:
\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\tikzstyle{block} = [draw=none, thick, text width=.4cm, minimum height=.5cm, align=center, fill=blue!50]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}
\Large
%red rectangles
\node (r1) [draw=none, fill=red, minimum width=1.2cm,minimum height=3.5cm]{};
\node (r2) [right=2cm of r1.center, anchor=center, draw=none, fill=red, minimum width=1.2cm,minimum height=3.5cm]{};
\node (r1Label)[above=0cm of r1] {\textbf{LabA}};
\node (r2Label)[above=0cm of r2]{\textbf{LabB}};
%nodes
\node[block, below=3mm of r1.north, anchor=north] (a) {\color{white}A};
\node[block, below=4mm of a] (b) {\color{white}B};
\node[block, below=4mm of b] (c) {\color{white}C};
\node[block, right=2cm of c.center, anchor=center] (d) {\color{white}D};
\node at ($(a.south)+(2,-.2)$) [block] (e) {\color{white}E};
%arrows
\draw [arrow, rounded corners=2] (a) -- ($(a)+(1,0)$) |- ($(e.west)+(0,.1)$);
\draw [arrow, rounded corners=2] (b) -- ($(b)+(1,0)$) |- ($(e.west)+(0,-.1)$);
\draw [arrow] (c) -- (d);
\end{tikzpicture}
\end{document}
With this result:
Some explanations:
You can just draw rectangles in the back by defining them before the other nodes. There are more sophisticated ways using layers, but I think in this example it suffices.
I mostly used absolute distances like in the given example code. You may have to adjust... However, using these you can easily find out the middle between A and B (distance 4mm) to find the y-Position of E (a.south+ 2mm). Using ($(node1)+(node2)$) you can calculate node positions.
The -|- option you mentioned works in two steps. First draw -- to some anchor point (otherwise this is ambiguous), then |- to the target node.
The rounded corners option for draw takes the rounding radius as a parameter.
How does one goes at trying to render such diagram with Latex.
Europe’s many alliances, reimagined as a Metro system European
countries are bound together in many ways
https://www.washingtonpost.com/graphics/world/how-european-countries-are-bound-together/?noredirect=on
Is there a package for such type of "Metro Line" diagrams ?
Maybe the following tikz code could be a starting point:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (Norway) at (0,1);
\coordinate (Belgium) at (2,0);
\draw[ultra thick, red] (Norway) -- (1:0.9599) -- (Belgium);
\draw[ultra thick, blue] ($(Norway) + (0,-0.1)$) -- ($(1:0.9599) + (-0.03,-0.065)$) -- ($(Belgium) + (0,-0.065)$);
\node[rotate=45,anchor=west] at (Norway) {Norway};
\draw[fill=white] (Norway) circle (0.03);
\draw[fill=white] ($(Norway) + (0,-0.1)$) circle (0.03);
\node[rotate=45,anchor=west] at (Belgium) {Belgium};
\draw[fill=white] (Belgium) circle (0.03);
\draw[fill=white] ($(Belgium) + (0,-0.065)$) circle (0.03);
\end{tikzpicture}
\end{document}
I'm trying to draw this in latex.
Anyone know how?
Use the calc-library and do the following:
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node[draw=black, circle, fill=green] (A) at (0,0) {A};
\draw let \p1=(A) in (A) -- (\x1+40,\y1+10);
\end{tikzpicture}
\end{document}
Using the let-statement it allows you to specify a reference point (or even more) to use it's coordinates for further calculation.
Say I want to construct a circulant graph in TikZ, with a variable number of nodes, labelled v0, v1, ..., v_n-1 for some n of my choice (say, 5).
I'd like to be able to use the \foreach command in TikZ to iteratively (1) define the nodes, and (2) connect the nodes. I'd like to be able to connect v_i to v_(i+1) and v_i to v_{i+2}, say.
\foreach \i in {0, ..., 4}
{\path (\i*72:3) node (v\i) {};}
constructs the nodes perfectly. But then when I want to draw some lines,
\foreach \i \in {0, ..., 3}
{ \draw (v\i) -- (v{\i+1}); } ????
doesn't work. Nor does
\foreach \i / \j in {0/1, ..., 3/4}
{ \draw (v\i) -- (v{\j}); }
I get an error "no such shape v0" or something like that.
I know this must be totally easy to do, but I can't figure out how. Any suggestions?
As a followup, it would be nice to be able to connect v_i and v_{i+4} or something, with a single \foreach command, and have TikZ/pgf do the modular arithmetic for me without having to worry about spilling over.
This worked for me:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,fit,arrows,positioning}
\tikzstyle{vertex} = [circle, draw, thick, text centered]
\tikzstyle{edge} = [draw, thick,->]
\begin{document}
\begin{tikzpicture}[scale=1]
\foreach \x in {0,...,6}
\node[vertex] (\x) at (\x*360/7:3) {v\x};
\foreach \x/\y in {0/1,1/2,2/3,3/4,4/5,5/6,6/0}
\draw[edge] (\x) to (\y);
\end{tikzpicture}
\end{document}
The syntax {0/1,...,5/6} did not work for me. But I admit, I spent a bit of time trying to find a good solution, and I'm still not totally satisfied.
Another solution, achieved editing the code by Steve Tjoa:
\documentclass[tikz,border=1mm]{standalone}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[thick]
\foreach \x in {0,...,4}{%
\node [circle, draw] at (\x*72:3) {$v_{\x}$};
\draw [->] (\x*72+10:3) arc (\x*72+10:\x*72+62:3);
}
\end{tikzpicture}
\end{document}