Search code examples
latexdrawingtikz

Including floral pattern into triangles for making great dodecahedron


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:

image

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: enter image description here

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.


Solution

  • 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:

    screenshot of output

    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:

    screenshot of output 2