2

我正在尝试制作 3d 图形(大十二面体,小星状十二面体),直到现在我在乳胶中使用 tikz 包。使用\coordinate\draw函数我设法为这些模型生成精确的模板。

现在我没有制作多面体,而是尝试仅使用 tikz 为其添加花卉图案,因为我不擅长素描。

那就是将 jpg 图像(带有花卉图案)导入使用 tikz 绘制的三角形中,以便为多面体制作模板,例如:

图片

我知道如何在乳胶中导入图形以及如何使用 tikz 制作几何图案,但不知道如何将 jpg 文件“裁剪”为三角形或任何其他在 tikz 中指定坐标的多边形。

例如,下面是我用来制作一个包含 10 个三角形的表面的代码。

\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}

这是它生成的图像: 在此处输入图像描述

问题是图像中的图案也是由tex生成的,我想要的是给定任何花卉/非花卉图案(我选择)我可以在三角形内裁剪(三角形位于tex图中的某个特定位置) .

任何帮助将不胜感激。

谢谢。

4

1 回答 1

0

阅读PGF Manual的第 1062-1072 页,我编写了以下测试代码:

\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}

在我.tex使用上述代码保存文件的同一文件夹中,我还将 这张图片保存为sample.png. 这是编译后的 tex 输出的屏幕截图:

输出截图

它显示了使用命令\pgftext\pgfpoint带有或不带有属性28mm0.8cm.

请在评论中添加您的反馈,以便我们更深入地了解它。此外,将您的代码添加到问题中将有助于更精确!


附录

以下是我如何将上面代码中的想法应用于您添加到问题中的代码:

\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}

为了包含来自外部文件的图形,我选择了一个\foreach循环,但只是为了使用五次相同的图像。关键是该行:

\pgftext[at=\pgfpoint{2cm*cos(\i)}{2cm*sin(\i)},left,base,rotate=\i]
{\pgfimage[interpolate=true,width=1cm,height=1cm]{sample}}

应该允许您使用属性2cm*cos(\i)2cm*sin(\i)left和onlybase来定位外部图形。rotate=\i

您可以避免\foreach循环并使用一个

\pgftext[at=\pgfpoint ... ] {\pgfimage[ ... ]{filename}}

对于您的每个外部文件。如果您可以为您的三角形图形生成透明背景图像,那么您可能会喜欢这个解决方案。

我的输出:

输出 2 的屏幕截图

于 2018-01-28T16:51:49.620 回答