상대 좌표 사용 시 음영 중심점 이동 방지

상대 좌표 사용 시 음영 중심점 이동 방지

\foreach나는 루프 에서 임의의 방식으로 공 모양을 그릴 수 있는 몇 가지 매크로를 작성 중입니다 .

\documentclass[tikz, border=0.5in]{standalone}
\newcommand{\ball}[3][0,0]{%\ball[basepoint]{point}{diameter}
    \shadedraw[ball color=blue!15!white, draw=blue!50] (#1) +(#2) circle (#3);
}

\begin{document}
\begin{tikzpicture}
    \foreach \t in {10, 20, ..., 360}{
        \ball{\t:6}{0.5}
    }
    \ball{0,0}{0.5}

    \foreach \t in {10, 20, ..., 360}{
        \ball[14,0]{\t:6}{0.5}
    }
    \ball{14,0}{0.5}
\end{tikzpicture}
\end{document}

산출

위에서 볼 수 있듯이 원점을 중심으로 하지 않는 극좌표를 사용할 수 있도록 상대 좌표를 사용하고 있습니다. 불행히도 내 음영 처리가 예상대로 작동하지 않습니다.

다음과 같은 결과를 얻고 싶지만 상대 좌표를 사용하면 다음과 같습니다.

\documentclass[tikz, border=0.5in]{standalone}
\begin{document}
\begin{tikzpicture}
    \foreach \t in {10, 20, ..., 360}{
        \shadedraw[ball color=blue!15!white, draw=blue!50] (\t:6) circle (0.5);
    }
    \shadedraw[ball color=blue!15!white, draw=blue!50] (0,0) circle (0.5)
\end{tikzpicture}
\end{document}

예상 출력

셰이딩 알고리즘은 (0,0)을 기준으로 이동되는 그려진 원의 중심을 고려하지 않는 것 같습니다. 음영의 원점을 다시 정의할 수 있습니까?

답변1

음영 처리된 경로의 경계 상자를 제한하려면 기준점이 이 경로에 표시되어서는 안 됩니다.

네 가지 솔루션은 다음과 같습니다.

  • \ballshift: shift센터에서 작업을 사용하고,
  • \ballscope: 원점 scope이 변경된 로컬을 사용합니다.
  • \ballcalc: calc중심을 이동하는 데 사용합니다.
  • \ballnode: 음영이 있는 원 노드를 사용합니다.

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

\documentclass[tikz, border=0.5in]{standalone}
\usetikzlibrary{calc}
\newcommand{\ballshift}[3][0,0]{%\ball[basepoint]{point}{diameter}
    \shadedraw[ball color=blue!15!white, draw=blue!50] ([shift={(#1)}]#2) circle (#3);
}
\newcommand{\ballscope}[3][0,0]{%\ball[basepoint]{point}{diameter}
  \begin{scope}[shift={(#1)}]
    \shadedraw[ball color=red!15!white, draw=red!50] (#2) circle (#3);
  \end{scope}
}
\newcommand{\ballcalc}[3][0,0]{%\ball[basepoint]{point}{diameter}
    \shadedraw[ball color=orange!15!white, draw=orange!50] ($(#1)+(#2)$) circle (#3);
}
\newcommand{\ballnode}[3][0,0]{%\ball[basepoint]{point}{diameter}
    \path (#1) ++(#2) node[inner sep=0,circle,minimum size=2cm*#3,
    ball color=lime!50!white,draw=lime]{};
}

\begin{document}
\begin{tikzpicture}
    \foreach \t in {10, 20, ..., 360}{
        \ballshift{\t:6}{0.5}
        \ballscope{\t:5}{0.4}
        \ballcalc{\t:4}{0.3}
        \ballnode{\t:3}{0.2}
    }
    \ballshift{0,0}{0.5}

    \foreach \t in {10, 20, ..., 360}{
        \ballshift[14,0]{\t:6}{0.5}
        \ballscope[14,0]{\t:5}{0.4}
        \ballcalc[14,0]{\t:4}{0.3}
        \ballnode[14,0]{\t:3}{0.2}
    }
    \ballshift{14,0}{0.5}
\end{tikzpicture}
\end{document}

관련 정보