곡선으로 이루어진 도형에 그리드를 그리는 방법은 무엇입니까?

곡선으로 이루어진 도형에 그리드를 그리는 방법은 무엇입니까?

저는 Tikz 패키지의 새로운 사용자이며 논문에 이 패키지를 사용하여 아래 이미지를 그리고 싶습니다.여기에 이미지 설명을 입력하세요

선이 직선이기 때문에 첫 번째 그리드(왼쪽)를 만들 수 있을 것 같은데, 변형된 막대의 두 번째 그리드는 어떻게 그릴 수 있나요? 첫 번째 것을 '변형'하거나 변형된 선에서 그리드를 만드는 방법이 있습니까? 또한 '확대된' 세부 사항과 관련하여 Tikz를 사용하여 그리는 '자동' 방법이 있습니까(그림의 실제 확대와 같은 의미)? 아니면 따로 만들어야 하나요? 도움을 주셔서 미리 감사드립니다!

답변1

비선형 변환 작업을 수행하는 것은 약간 까다롭지만 라이브러리 pgf와 함께 필요한 작업을 어느 정도 수행할 수 있습니다 spy.

\documentclass[tikz,margin=5]{standalone}
\usepgfmodule{nonlineartransformations}
\usepgflibrary{curvilinear}
\usetikzlibrary{spy,calc}
\tikzset{pics/grid/.style={code={%
  \tikzset{x=10pt, y=10pt, step=10pt}
  \draw [thin] (-2, 0) grid ++(4, 20);
  \draw [thick] (-2, 0) rectangle ++(4, 20) (-4, 0) -- (4, 0);
  \draw [thick, fill=gray!50] (0,14) rectangle ++(1,1)
   ++(-.5,-.5) coordinate (-square);
  \draw [<->, thin, gray] (0,14) -- ++(1,1); 
  \coordinate (-corner) at (-2, 20);
}}}
\begin{document}
\begin{tikzpicture}[>=stealth,
  spy using outlines={circle, magnification=3, size=2.5cm, connect spies}]
\pic (a) {grid};
\draw [->, thick, shorten >=5] (a-corner) ++(-1,0)  -- (a-corner);
\spy [red] on (a-square) in node at ($(a-square)+(2.5,0)$);
\scoped{
  \pgfsetcurvilinearbeziercurve
    {\pgfpointxy{5}{0}}{\pgfpointxy{5}{10}}
    {\pgfpointxy{25}{15}}{\pgfpointxy{25}{20}}
  \pgftransformnonlinear{\pgfgetlastxy\x\y%
    \pgfpointcurvilinearbezierorthogonal{\y}{-\x}}%
  \pic (b) {grid};
}
\draw [->, thick, shorten >=5] (b-corner) ++(-1,0) -- (b-corner);
\spy [red] on (b-square) in node at ($(b-square)+(2.5,0)$);
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

답변2

다음은 시도입니다.메타포스트. 에 싸여 있으므로 luamplib로 컴파일하십시오 lualatex.

여기에 이미지 설명을 입력하세요

아래 두 번째 버전에 콜아웃을 추가했습니다.

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);

    numeric u, x, y; 
    u = 5mm;
    x = 4;
    y = 17;
    path base;
    base = (left--right) scaled (2x*u);
    picture p[];

    p1 = image(
        path tower;
        tower = unitsquare shifted 1/2 left xscaled x yscaled y scaled u;

        path hh[], vv[];
        for i=1 upto x-1:
            vv[i] = point i/x of tower -- point 3-i/x of tower;
        endfor
        for i=1 upto y-1:
            hh[i] = point 1+i/y of tower -- point 4-i/y of tower;
        endfor

        path sq; sq = buildcycle(hh[14],vv[3],hh[15],vv[2]);
        fill sq withcolor 7/8[red,white];

        for i=1 upto x-1: draw vv[i]; endfor
        for i=1 upto y-1: draw hh[i]; endfor

        drawoptions(withpen pencircle scaled 1.2);
        drawarrow point 3 of tower shifted (-4u,0) -- point 3 of tower shifted (-3,0);
        draw tower;
        draw base ;
        drawoptions();
    );
    p2 = image(
        path tower;
        tower = subpath (4,3) of fullcircle scaled 40u shifted (22u,0)
             -- subpath (3,4) of fullcircle scaled 48u shifted (22u,0)
             -- cycle;

        path hh[], vv[];
        for i=1 upto x-1:
            vv[i] = interpath(i/x,subpath(3,2) of tower, subpath (0,1) of tower);
        endfor
        for i=1 upto y-1:
            hh[i] = point i/y of tower -- point 3-i/y of tower;
        endfor

        path sq; sq = buildcycle(hh[14],vv[3],hh[15],vv[2]);
        fill sq withcolor 7/8[red,white];

        for i=1 upto x-1: draw vv[i]; endfor
        for i=1 upto y-1: draw hh[i]; endfor

        drawoptions(withpen pencircle scaled 1.2);
        drawarrow point 2 of tower shifted (-4u,0) -- point 2 of tower shifted (-3,0);
        draw tower;
        draw base ;
        drawoptions();
    );

    draw p1 shifted (-10u,0);
    draw p2 shifted (+10u,0);

endfig;
\end{mplibcode}
\end{document}

그리고 지금은 클로즈업...

Metapost에는 "스파이"나 돋보기 기능이 내장되어 있지 않지만 사진을 임의의 경로로 잘라낼 수 있으므로 직접 만드는 것이 어렵지 않습니다. 이와 같이:

스파이 구멍이 있는 쌍둥이 빌딩

그림의 두 번째 버전에 대한 코드는 다음과 같습니다.

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);

    numeric u, x, y; 
    u = 5mm;
    x = 4;
    y = 17;
    path base, loupe[];
    base = (left--right) scaled (2x*u);
    picture p[];

    p1 = image(
        path tower;
        tower = unitsquare shifted 1/2 left xscaled x yscaled y scaled u;

        path hh[], vv[];
        for i=1 upto x-1:
            vv[i] = point i/x of tower -- point 3-i/x of tower;
        endfor
        for i=1 upto y-1:
            hh[i] = point 1+i/y of tower -- point 4-i/y of tower;
        endfor

        path sq; sq = buildcycle(hh[14],vv[3],hh[15],vv[2]);
        fill sq withcolor 7/8[red,white];

        for i=1 upto x-1: draw vv[i]; endfor
        for i=1 upto y-1: draw hh[i]; endfor

        begingroup; interim ahangle := 24; interim ahlength := 2;
        drawdblarrow point 0 of sq -- point 3 of sq withcolor 1/2 white;
        label("$\scriptscriptstyle d\xi$", center sq + (2,-3));
        endgroup;

        drawoptions(withpen pencircle scaled 1.2);
        drawarrow point 3 of tower shifted (-4u,0) -- point 3 of tower shifted (-3,0);
        draw tower;
        draw base ;
        drawoptions();
    );

    loupe1 := fullcircle scaled 2u shifted center sq;
    loupe3 := fullcircle scaled 4u shifted center sq shifted (6u,u);
    p3 := p1;  
    clip p3 to loupe1;
    p3 := p3 shifted -center loupe1 scaled 2 shifted center loupe3;

    p5 = image(
        draw p1; draw p3;
        drawoptions(withcolor red);
        draw loupe1; draw loupe3;
        draw center loupe1 -- center loupe3
          cutbefore loupe1  cutafter loupe3;
        drawoptions();
    );

    p2 = image(
        path tower;
        tower = subpath (4,3) of fullcircle scaled 40u shifted (22u,0)
             -- subpath (3,4) of fullcircle scaled 48u shifted (22u,0)
             -- cycle;

        path hh[], vv[];
        for i=1 upto x-1:
            vv[i] = interpath(i/x,subpath(3,2) of tower, subpath (0,1) of tower);
        endfor
        for i=1 upto y-1:
            hh[i] = point i/y of tower -- point 3-i/y of tower;
        endfor

        path sq; sq = buildcycle(hh[14],vv[3],hh[15],vv[2]);
        fill sq withcolor 7/8[red,white];

        for i=1 upto x-1: draw vv[i]; endfor
        for i=1 upto y-1: draw hh[i]; endfor

        begingroup; interim ahangle := 24; interim ahlength := 2;
        drawdblarrow point 0 of sq -- point 3 of sq withcolor 1/2 white;
        endgroup;

        drawoptions(withpen pencircle scaled 1.2);
        drawarrow point 2 of tower shifted (-4u,0) -- point 2 of tower shifted (-3,0);
        draw tower;
        draw base ;
        drawoptions();
    );
    loupe2 := fullcircle scaled 2u shifted center sq;
    loupe4 := fullcircle scaled 4u shifted center sq shifted (-8u,2u);
    p4 := p2;  
    clip p4 to loupe2;
    p4 := p4 shifted -center loupe2 scaled 2 shifted center loupe4;

    p6 = image(
        draw p2; draw p4;
        drawoptions(withcolor red);
        draw loupe2; draw loupe4;
        draw center loupe2 -- center loupe4
          cutbefore loupe2  cutafter loupe4;
        drawoptions();
    );

    draw p5 shifted (-10u,0);
    draw p6 shifted (+10u,0);

endfig;
\end{mplibcode}
\end{document}

관련 정보