TikZ: x, y 크기가 다르지만 모양이 해당 측면을 유지합니다.

TikZ: x, y 크기가 다르지만 모양이 해당 측면을 유지합니다.

TikZ로 다시 수행 중인 오래된 pstricks 코드가 있습니다. 현재 그림에서는 x와 y 스케일이 다릅니다.

\begin{tikzpicture}[xscale=1.8,yscale=4]

그러나 이는 원이 타원으로 그려지고 y 방향으로 더 늘어나는 문제가 있습니다. 나도 시도해 봤어

\begin{tikzpicture}[x=1.8cm,y=4cm]

그러나 이것은 원을 타원으로 늘리는 것과 동일한 효과를 갖습니다.

그렇다면 개체 모양에 영향을 주지 않는 TikZ에서만 좌표 크기를 조정하는 방법이 있습니까?

답변1

나는 다음과 같이 해결책을 발견했습니다

\draw (1,1) circle(0.1cm);

일을 합니다. 나는 사용하고 있었다

\draw (1,1) circle(0.1);

개별 스케일링을 선택합니다.

답변2

PSTricks는 \psrunit그림을 그릴 때 사용합니다 \pscircle.

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

\documentclass[tikz,border=12pt]{standalone}

\newlength\runit
\runit=1cm

\edef\Radius#1{#1\runit}

\begin{document}
\begin{tikzpicture}[x=3cm,y=2cm]
    \draw[fill=red] (0,0) circle (\Radius{2});
    \draw (-2,-2) rectangle (2,2);
\end{tikzpicture}
\end{document}

참고: 방사형 단위를 전역적으로 선언하면 원 반지름의 모든 단위를 한 곳에서 변경할 수 있다는 이점이 있습니다.


또한 이 방사형 단위에 더 쉽게 액세스할 수 있도록 새 키를 선언할 수도 있습니다.

\documentclass[tikz,border=12pt]{standalone}

\makeatletter
\newlength\tikz@runit
\tikzset{
    r/.code=\pgfmathsetlength\tikz@runit{#1},
    r=+1cm, % setting a default value
    r radius/.style={radius={(#1)*\tikz@runit}},
    xr radius/.style={x radius={(#1)*\tikz@runit}},
    yr radius/.style={y radius={(#1)*\tikz@runit}}
}
\makeatother

\begin{document}
\begin{tikzpicture}[x=3cm,y=2cm]
    \fill[fill=red] (0,0) circle [r radius=1+1];
    \fill[fill=green] (-1,1) circle [xr radius=1+3/4, yr radius=1-1/3]
                      (1,1)  circle [xr radius=1+3/4, yr radius=1-1/3];
    \draw (-2,-2) rectangle (2,2);
\end{tikzpicture}
\end{document}

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

답변3

제안된 모든 솔루션의 핵심 아이디어는 x=및 단위를 변경하는 것입니다 y=. 이것은 잘 작동합니다.

xscale=그러나 내 코드에서는 and 를 사용하는 것이 매우 바람직합니다 yscale=. 따라서 저는 매우 간단한 매크로를 설정했습니다.

\newcommand{\pnt}[3][black]{%
\begin{scope}[shift={#2}];
\fill[color=#1,shift only] (0,0) circle(#3);
\end{scope}}

다음과 함께 사용됩니다:

\pnt[red]{(3,4)}{0.06}

배치하다회보(3,4) 위치에 반경 1.5pt의 빨간색 점.

관련 정보