在三角形内绘制旋转三角形

在三角形内绘制旋转三角形

三角形内有三角形

如何在三角形内绘制旋转三角形,如上图所示?我已经知道如何绘制一个三角形;但我无法绘制这个特定的图形。我在https://latexdraw.com/tikz-shapes-triangle/

\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}[thick,violet] 
\foreach \i in {-30,-28,...,0}{

\node[draw,
    fill=violet!10,
    isosceles triangle,
    isosceles triangle apex angle=60,
    minimum size=-2*\i mm, 
    rotate=\i,inner sep =0pt] at (0,0){};
}

\end{tikzpicture}

\end{document}

答案1

仅用于比较,编译时使用渐近线

在我所有的例子中,s都是一个尺度。

Thruston 的答案的类似代码。

size(300);
real s=1/8;
for (int m=3; m<=5; ++m){
  path[] a={polygon(m)};
  for (int i=1; i<= m/s; ++i){
    pair[] A;
    for (int j=0; j < size(a[i-1]); ++j)
    {
      A[j] = point(a[i-1],j+s);
    }
    a[i]=operator --(... A)--cycle;
  }
  picture P;
  for (int i=0; i<a.length; ++i)
    filldraw(P,a[i],interp(white,blue,(i+1)*s));
  add(shift((2*m,0))*P);
}

在此处输入图片描述

动画片:

settings.tex="pdflatex";
import animate;
size(300);
real s=1/8;
animation Ani;

path[] testpolygon(int m)
{
  path[] a={polygon(m)};
  for (int i=1; i<= m/s; ++i){
    pair[] A;
    for (int j=0; j < size(a[i-1]); ++j)
    {
      A[j] = point(a[i-1],j+s);
    }
    a[i]=operator --(... A)--cycle;
  }
  return a;
}
for (int n=3; n<=5; ++n){
  for (int i=0; i<testpolygon(n).length; ++i){
    save();
    filldraw(testpolygon(n)[i],interp(white,blue,(i+1)*s));
    Ani.add();
  }
  erase();
}
erase();
Ani.movie();

在此处输入图片描述

示例 1:

unitsize(3cm);

pair A=(0,0),B=(4,0),C=rotate(60,A)*B;
path d=A--B--C--cycle;
int n=15;
path pic(real s=0.2)
{
pair M=A;
A=relpoint(A--B,s);
B=relpoint(B--C,s);
C=relpoint(C--M,s);
return A--B--C--cycle;
}

for (int i=0; i < n; ++i)
{
if (i==0) draw(d,blue);
else draw(pic(0.2),(i%2 == 1) ? red : blue);
}

在此处输入图片描述

示例 2:

unitsize(3cm);

pair A=(0,0),B=(4,0),C=(4,4),D=(0,4);
path d=A--B--C--D--cycle;
int n=15;
path pic(real s=0.2)
{
pair M=A;
A=relpoint(A--B,s);
B=relpoint(B--C,s);
C=relpoint(C--D,s);
D=relpoint(D--M,s);
return A--B--C--D--cycle;
}

for (int i=0; i < n; ++i)
{
if (i==0) fill(d,blue);
else fill(pic(0.2),(i%2 == 1) ? red : blue);
}

在此处输入图片描述

示例 3:

unitsize(4cm);

path g=polygon(5);
pair A=point(g,0),B=point(g,1),C=point(g,2),D=point(g,3),E=point(g,4);
path d=A--B--C--D--E--cycle;
int n=35;
path pic(real s=0.2)
{
pair M=A;
A=relpoint(A--B,s);
B=relpoint(B--C,s);
C=relpoint(C--D,s);
D=relpoint(D--E,s);
E=relpoint(E--M,s);
return A--B--C--D--E--cycle;
}

for (int i=0; i < n; ++i)
{
if (i==0) fill(d,blue);
else fill(pic(0.2),(i%2 == 1) ? red : blue);
}

在此处输入图片描述

示例 4:

size(300);

void testpolygon(pair[] A, int n=3, real s=0.2, pen p1=green, pen p2=magenta)
{
  pair[] a=copy(A);
  guide g= operator --(... a)--cycle;
  guide pic()
  {
    pair M=a[0];
    for (int i=0; i<a.length; ++i)
    {
      if (i != (a.length-1))
      {
        a[i]=relpoint(a[i]--a[i+1],s);
      } else {
        a[i]=relpoint(a[i]--M,s);
      }
    }
    return operator --(... a)--cycle;
  }
  for (int i=0; i <= n; ++i)
  {
    if (i==0) filldraw(g,p1);
      else filldraw(pic(),(i%2==1) ? p2 : p1);
  }
}

int n=25;
path g=rotate(-60)*polygon(6);
testpolygon(new pair[]{(0,0),point(g,0),point(g,1)},n,0.1);
testpolygon(new pair[]{(0,0),point(g,1),point(g,2)},n,0.1);
testpolygon(new pair[]{(0,0),point(g,2),point(g,3)},n,0.1);
testpolygon(new pair[]{(0,0),point(g,3),point(g,4)},n,0.1);
testpolygon(new pair[]{(0,0),point(g,4),point(g,5)},n,0.1);
testpolygon(new pair[]{(0,0),point(g,5),point(g,0)},n,0.1);

在此处输入图片描述

最终代码:

\documentclass[12pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage[inline]{asymptote}
\usepackage{graphicx}
\usepackage{subcaption} % https://latex-tutorial.com/tutorials/figures/

\begin{document}

In TeXstudio, Options $\rightarrow$ Configure TeXstudio... $\rightarrow$ Build $\rightarrow$ Build \& View is txs:///asy-pdf-chain $\rightarrow$ OK. Then press Build \& View, processing... (Compile two times)

\begin{figure}[h!]
    \centering
    \begin{subfigure}[b]{0.4\linewidth}
        \centering
        \begin{asy}
        unitsize(1.5cm);
        
        pair A=(0,0),B=(4,0),C=rotate(60,A)*B;
        path d=A--B--C--cycle;
        int n=10;
        path pic(real s=0.2)
        {
            pair M=A;
            A=relpoint(A--B,s);
            B=relpoint(B--C,s);
            C=relpoint(C--M,s);
            return A--B--C--cycle;
        }
        
        for (int i=0; i < n; ++i)
        {
            if (i==0) filldraw(d,blue,green+0.8bp);
            else filldraw(pic(0.2),(i%2 == 1) ? red : blue,green+0.8bp);
        }
        \end{asy}
        \caption{Picture 1}
    \end{subfigure}
    \begin{subfigure}[b]{0.4\linewidth}
        \centering
        \begin{asy}
        unitsize(1.25cm);
        
        pair A=(0,0),B=(4,0),C=(4,4),D=(0,4);
        path d=A--B--C--D--cycle;
        int n=10;
        path pic(real s=0.2)
        {
            pair M=A;
            A=relpoint(A--B,s);
            B=relpoint(B--C,s);
            C=relpoint(C--D,s);
            D=relpoint(D--M,s);
            return A--B--C--D--cycle;
        }
        
        for (int i=0; i < n; ++i)
        {
            if (i==0) filldraw(d,blue,green+0.8bp);
            else filldraw(pic(0.2),(i%2 == 1) ? red : blue,green+0.8bp);
        }
        \end{asy}
        \caption{Picture 2}
    \end{subfigure}
    \begin{subfigure}[b]{\linewidth}
        \centering
        \begin{asy}[width=10cm]
        size(300);
        
        void testpolygon(pair[] A, int n=3, real s=0.2, pen p1=green, pen p2=magenta)
        {
        pair[] a=copy(A);
        guide g= operator --(... a)--cycle;
        guide pic()
        {
        pair M=a[0];
        for (int i=0; i<a.length; ++i)
        {
        if (i != (a.length-1))
        {
        a[i]=relpoint(a[i]--a[i+1],s);
        } else {
        a[i]=relpoint(a[i]--M,s);
        }
        }
        return operator --(... a)--cycle;
        }
        for (int i=0; i <= n; ++i)
        {
        if (i==0) filldraw(g,p1);
        else filldraw(pic(),(i%2==1) ? p2 : p1);
        }
        }
        
        int n=25;
        path g=rotate(-60)*polygon(6);
        testpolygon(new pair[]{(0,0),point(g,0),point(g,1)},n,0.1);
        testpolygon(new pair[]{(0,0),point(g,1),point(g,2)},n,0.1);
        testpolygon(new pair[]{(0,0),point(g,2),point(g,3)},n,0.1);
        testpolygon(new pair[]{(0,0),point(g,3),point(g,4)},n,0.1);
        testpolygon(new pair[]{(0,0),point(g,4),point(g,5)},n,0.1);
        testpolygon(new pair[]{(0,0),point(g,5),point(g,0)},n,0.1);
        \end{asy}
    \caption{Picture 3}
\end{subfigure}
\end{figure}
Done!
\end{document}

在此处输入图片描述

答案2

元帖子您可以通过使任意三个非共线点相等来定义一般transform运算。这包含在中,luamplib因此请使用 进行编译lualatex

在此处输入图片描述

\documentclass{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
beginfig(1);
    numeric s; s = 1/8;
    for n=3 upto 5:
        path t; t = for i=0 upto n-1: 100 up rotated (360/n*i) -- endfor cycle;
        transform r;
        for i=0 upto 2:
            point i of t transformed r = point i + s of t;
        endfor
        picture P; P = image(
            for i=1 upto floor (n/s):
                draw t;
                fill t withcolor (i * s / n)[white, blue];
                t := t transformed r;
            endfor
        );
        draw P shifted (200n, 0);
    endfor
endfig;
\end{mplibcode}
\end{document}

借用缩放计算其他解决方案之一,您也可以使用 MPzscaled操作符执行此操作。这里有一个替代方案,可以让您更轻松地控制旋转角度a和圈数N

\documentclass{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
beginfig(1);
    numeric a, N; a = 12; N = 7;
    for n=3 upto 5:
        path t; t = for i=0 upto n-1: 100 up rotated (360/n*i) -- endfor cycle;
        numeric b, c; c = 180 - 360/n; b = 180 - c - a;
        pair r; r = dir a scaled (sind(c) / (sind(a) + sind(b)));
        picture P; P = image(
            for i=1 upto N:
                draw t;
                fill t withcolor (i / 2N)[white, blue];
                t := t zscaled r;
            endfor
        );
        draw P shifted (200n, 0);
    endfor
endfig;
\end{mplibcode}
\end{document}

这里我将转弯角度设置为12°,转弯次数设置为7。 笔记:为了使计算按预期进行,您需要将转弯角度保持在范围内0 < a < 360/n

编译第二个示例lualatex得到以下内容:

在此处输入图片描述

如果你想了解更多关于 Metapost 的信息,你可以在这里找到教程和示例Tug 上的 MP 页面

解释

这里解释了缩放的工作原理,以及为什么它可以推广到具有更多边的多边形。

在此处输入图片描述

对于给定的旋转角度α,需要将边长为 的原始多边形a+b缩小为边长为 的多边形c。因此所需的缩放比例为c/(a+b)。您无法测量长度,但可以测量角度: α是给定的;γ180-360/n其中n是边数;β180-α-γ

正弦定理告诉我们

sin α / a = sin β / b = sin γ / c = x

因此

ax = sin α, bx = sin β, and cx = sin γ

因此所需的缩放比例可以用正弦表示

c/(a+b) = cx / (ax+bx) = sin γ / (sin α + sin β)

从图中可以看出,这适用于任何正多边形n>2

答案3

一个简单的解决方案,不需要太多计算。只需将新顶点放置在前\p一条边的 % 处,然后绘制即可。

旋转模式

\documentclass[tikz,border=3.14mm]{standalone}

\begin{document}

\def\n{15}      % Number of triangles
\def\r{3}       % Radius of the larger triangle
\def\p{20}      % Percentage for positioning the next vertex on the edge
\def\col{violet}

    \begin{tikzpicture}
        \path (90:\r)  coordinate(A)
              (210:\r) coordinate(B)
              (330:\r) coordinate(C);
        \draw[\col,fill=\col!20] (A) -- (B) -- (C) -- cycle;
        \foreach \x in {1,...,\n}{%
            \path (A) coordinate(M);
            \path (A) -- (B) coordinate[pos=\p/100](A)
                      -- (C) coordinate[pos=\p/100](B)
                      -- (M) coordinate[pos=\p/100](C);
            \draw[\col,fill=\col!20] (A)--(B)--(C)--cycle;
        }
    \end{tikzpicture}
\end{document}

答案4

使用 OP MWE 中的三角形节点:并在math tikzlibrary

这个想法是适当地旋转和缩小所有三角形。可以发现比例因子s 和旋转角度A相关:

s=sin(60)/(sin(120-a)+sina)

\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,math}

\begin{document}

\begin{tikzpicture}[violet] 

\tikzmath{
\dangle=15; % angle variation  between two successive triangles
\scale=(sin(60)/(sin(120-\dangle)+sin(\dangle)); % reduction factor of the triangle sides (from elementary geometry)
\a=50;  % the size of the wider triangle
}


\foreach \i in {0,...,5}{ % (5+1) triangles to draw

\node[draw,line join=round,
    fill=violet!10,
    regular polygon,
    regular polygon sides=3,
    minimum size=\a*(\scale)^\i , 
    rotate=\i*\dangle,
    inner sep =0pt] at (0,0){};
}

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容