TikZ: 서로 다른 평면에 있는 두 개의 타원

TikZ: 서로 다른 평면에 있는 두 개의 타원

두 개의 타원이 서로 다른 평면에 있다는 것을 어떻게 보여줄 수 있습니까?

\documentclass[convert = false, border = 1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  \pgfmathsetmacro{\as}{2};
  \pgfmathsetmacro{\bs}{1.95};
  \pgfmathsetmacro{\cs}{sqrt(\as^2 - \bs^2)}
  \pgfmathsetmacro{\al}{3};
  \pgfmathsetmacro{\bl}{2.25};
  \pgfmathsetmacro{\cl}{sqrt(\al^2 - \bl^2)}
  \pgfmathsetmacro{\xs}{abs(\cs - \cl)}

  \draw (0, 0) ellipse [x radius = \as cm, y radius = \bs cm];
  \draw (\xs, 0) ellipse [x radius = \al cm, y radius = \bl cm];

  \filldraw[black] (-\cs, 0) circle [radius = .1cm];

  \filldraw[black] (-\cl + \xs, 0) circle [radius = .1cm];
\end{tikzpicture}
\end{document}

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

이미지에서 우리는 두 타원이 같은 평면에 있다는 것을 알 수 있습니다. 작은 타원이 다른 평면에 있는 것처럼 보이도록 작은 타원을 회전하려면 어떻게 해야 합니까?

사용하면 rotate around그 모양이 달성되지 않습니다.

편집 2:

나는 타원이 이동되고 늘어나는 것처럼 보이기 때문에 사용 xslant에 대해 조금 주저합니다 .yslant

여기 서로 다른 평면에 있는 두 타원의 형편없는 사진이 있습니다(제 휴대폰 카메라 플래시는 작동을 거부했습니다).

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

작은 타원을 조정하면 타원이 늘어나고 극적으로 이동하는 것처럼 보입니다.

아래 이미지에서 초점은 이제 더 작은 타원의 중앙에 있는 것처럼 보이며 길어졌습니다.

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

편집하다:

그래서 이 글을 발견했습니다Tait-Bryan 규칙에서 tikz-3dplot을 사용하여 좋은 평면에 호가 그려지지 않는 이유는 무엇입니까?하지만 코드를 완전히 이해하지 못합니다. 그러나 포스터는 타원을 회전할 수 있어 더 나은 시각적 매력을 가질 수 있었고 포스터는 xy, yz, 와 같은 평면을 정의할 수 있었습니다 xz. 이 코드를 내 상황에 어떻게 적용할 수 있나요?

답변1

한 가지 가능성은 xslant, yslant; 포함하는 평면을 그리는 것이 효과가 더 좋습니다.

\documentclass[convert = false, border = 1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  \pgfmathsetmacro{\as}{2};
  \pgfmathsetmacro{\bs}{1.95};
  \pgfmathsetmacro{\cs}{sqrt(\as^2 - \bs^2)}
  \pgfmathsetmacro{\al}{3};
  \pgfmathsetmacro{\bl}{2.25};
  \pgfmathsetmacro{\cl}{sqrt(\al^2 - \bl^2)}
  \pgfmathsetmacro{\xs}{abs(\cs - \cl)}

\begin{scope}[xslant=1,yslant=-1.2]
  \draw (0, 0) ellipse [x radius = \as cm, y radius = \bs cm];
  \draw[blue] (-2.5,-2.5) rectangle (3,2.5);
\end{scope}
\begin{scope}[xslant=0.2,yslant=-1.2]
  \draw[red] (\xs, 0) ellipse [x radius = \al cm, y radius = \bl cm];
  \draw[green] (-3,-2.5) rectangle (5.5,2.5);
\end{scope}
  \filldraw[black] (-\cs, 0) circle [radius = .1cm];

  \filldraw[black] (-\cl + \xs, 0) circle [radius = .1cm];
\end{tikzpicture}
\end{document}

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

xslant및 에 대한 간략한 설명 yslant:

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{amsmath}

\begin{document}

\verb|xslant| is the high-level version of \verb|\pgftransformxslant|. In \verb|pgfcoretransformations.code.tex| one finds
\begin{verbatim}
\def\pgftransformxslant#1{\pgftransformcm{1.0}{0}{#1}{1.0}{\pgfpointorigin}}
\end{verbatim}
where \verb|\pgftransformcm{<a>}{<b>}{<c>}{<d>}{<coordinate>}| is the low-level equivalent to
\begin{verbatim}
cm={<a>,<b>,<c>,<d>,<coordinate>}
\end{verbatim}
which has the following effect: if \verb|<coordinate>| specifies the point $(t_x,t_y)$, a given point $(x,y)$ will be transformed in $(x',y')$, where
\[
\begin{bmatrix}
x' \\ y'
\end{bmatrix} =
\begin{bmatrix}
a & c \\
b & d
\end{bmatrix}
\begin{bmatrix}
x \\ y
\end{bmatrix}
+
\begin{bmatrix}
t_x \\ t_y
\end{bmatrix}.
\]
In particular, for \verb|xslant=k|, we have
\[
\begin{bmatrix}
x' \\ y'
\end{bmatrix} =
\begin{bmatrix}
1 & k \\
0 & 1
\end{bmatrix}
\begin{bmatrix}
x \\ y
\end{bmatrix}
+
\begin{bmatrix}
t_x \\ t_y
\end{bmatrix}
\]
and from here,
\begin{align*}
x' &= x + ky + t_x, \\
y' &= y + t_y.
\end{align*}

Analogously, one can ontain the transformation associated to \verb|yslant|, taking into account the following definition:
\begin{verbatim}
\def\pgftransformyslant#1{\pgftransformcm{1.0}{#1}{0}{1.0}{\pgfpointorigin}}
\end{verbatim}

\end{document}

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

답변2

이 솔루션을 사용하려면 두 개의 타원을 지정하고 "교차선"을 지정해야 합니다. 처음에는 3D로 하려고 했으나TikZ그건 별로에요. 솔루션은 다음을 사용합니다.pgfkeys유효한 키-값 인터페이스의 경우.

표준 구성을 사용하면 다음과 같습니다.

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

매크로는 그림을 "오른쪽 부분"과 "왼쪽 부분"으로 나누므로 교차선은 두 타원 외부에서 시작하고 끝나야 합니다.

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

그런 다음 "뒷부분"을 먼저 그리고 나중에 "앞 부분"을 그립니다.

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

암호

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

\begin{document}

\tikzset{%
    threedellipsesopt/.is family,%
    threedellipsesopt,%
    intersection start/.initial={-0.5,-2},%
    intersection end/.initial={1,4},%
    ellipse one center/.initial={-1,1},%
    ellipse two center/.initial={1,2},%
    ellipse one radius a/.initial={4},%
    ellipse two radius a/.initial={5},%
    ellipse one radius b/.initial={2},%
    ellipse two radius b/.initial={1.8},%
    ellipse one rotation/.initial=30,%
    ellipse two rotation/.initial=-50,%
    ellipse one fill/.initial=blue!50!cyan,%
    ellipse two fill/.initial=orange!50!yellow,%
    ellipse one draw/.initial=blue!50!black,%
    ellipse two draw/.initial=orange!50!black,%
    opacity/.initial=0.5,%
}

\newcommand{\ellkey}[1]% access a specific key by name
{\pgfkeysvalueof{/tikz/threedellipsesopt/#1}}

\newcommand{\threedellipses}[1]{
  \tikzset{threedellipsesopt,#1} % Process Keys passed to command
  \path (\ellkey{intersection start}) -- (\ellkey{intersection end});
    \path[opacity=\ellkey{opacity},draw=\ellkey{ellipse one draw},rotate=\ellkey{ellipse one rotation}] (\ellkey{ellipse one center}) circle (\ellkey{ellipse one radius a} and \ellkey{ellipse one radius b});
    \path[opacity=\ellkey{opacity},draw=\ellkey{ellipse two draw},rotate=\ellkey{ellipse two rotation}] (\ellkey{ellipse two center}) circle (\ellkey{ellipse two radius a} and \ellkey{ellipse two radius b});
    \begin{scope}
        \clip (current bounding box.north west) -| (\ellkey{intersection end}) -- (\ellkey{intersection start}) |- (current bounding box.south west) -- cycle;
        \clip[rotate=\ellkey{ellipse one rotation}] (\ellkey{ellipse one center}) circle (\ellkey{ellipse one radius a}*1cm-0.2pt and \ellkey{ellipse one radius b}*1cm-0.2pt);
        \fill[opacity=\ellkey{opacity},\ellkey{ellipse one fill}] (current bounding box.north east) rectangle (current bounding box.south west);
    \end{scope}
    \begin{scope}
        \clip (current bounding box.north east) -| (\ellkey{intersection end}) -- (\ellkey{intersection start}) |- (current bounding box.south east) -- cycle;
        \clip[rotate=\ellkey{ellipse two rotation}] (\ellkey{ellipse two center}) circle (\ellkey{ellipse two radius a}*1cm-0.2pt and \ellkey{ellipse two radius b}*1cm-0.2pt);
        \fill[opacity=\ellkey{opacity},\ellkey{ellipse two fill}] (current bounding box.north east) rectangle (current bounding box.south west);
    \end{scope}
    \begin{scope}
        \clip (current bounding box.north west) -| (\ellkey{intersection end}) -- (\ellkey{intersection start}) |- (current bounding box.south west) -- cycle;
        \clip[rotate=\ellkey{ellipse two rotation}] (\ellkey{ellipse two center}) circle (\ellkey{ellipse two radius a}*1cm-0.2pt and \ellkey{ellipse two radius b}*1cm-0.2pt);
        \fill[opacity=\ellkey{opacity},\ellkey{ellipse two fill}] (current bounding box.north east) rectangle (current bounding box.south west);
    \end{scope}
    \begin{scope}
        \clip (current bounding box.north east) -| (\ellkey{intersection end}) -- (\ellkey{intersection start}) |- (current bounding box.south east) -- cycle;
        \clip[rotate=\ellkey{ellipse one rotation}] (\ellkey{ellipse one center}) circle (\ellkey{ellipse one radius a}*1cm-0.2pt and \ellkey{ellipse one radius b}*1cm-0.2pt);
        \fill[opacity=\ellkey{opacity},\ellkey{ellipse one fill}] (current bounding box.north east) rectangle (current bounding box.south west);
    \end{scope}
}

\begin{tikzpicture}
    \threedellipses{}
\end{tikzpicture}

\begin{tikzpicture}
    \threedellipses{ellipse one draw=black,ellipse two draw=black,ellipse one fill=red,ellipse two fill=green,ellipse one center={0,0},ellipse two center={0,0},ellipse one rotation=45,ellipse two rotation=-45}
\end{tikzpicture}

\end{document}

산출

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


편집 1:rotate around이제 대신에 를 사용하여 코드를 변경했습니다 rotate. 그러면 타원을 더 쉽게 지정할 수 있습니다. 귀하의 요청을 올바르게 이해했다면 교차선 변경과 같은 것을 원할 것입니다.

암호

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

\begin{document}

\tikzset{%
    threedellipsesopt/.is family,%
    threedellipsesopt,%
    intersection start/.initial={-0.5,-2},%
    intersection end/.initial={1,4},%
    ellipse one center/.initial={-1,1},%
    ellipse two center/.initial={1,2},%
    ellipse one radius a/.initial={4},%
    ellipse two radius a/.initial={5},%
    ellipse one radius b/.initial={2},%
    ellipse two radius b/.initial={1.8},%
    ellipse one rotation/.initial=30,%
    ellipse two rotation/.initial=-50,%
    ellipse one fill/.initial=blue!50!cyan,%
    ellipse two fill/.initial=orange!50!yellow,%
    ellipse one draw/.initial=blue!50!black,%
    ellipse two draw/.initial=orange!50!black,%
    opacity/.initial=0.5,%
}

\newcommand{\ellkey}[1]% access a specific key by name
{\pgfkeysvalueof{/tikz/threedellipsesopt/#1}}

\newcommand{\threedellipses}[1]{
  \tikzset{threedellipsesopt,#1} % Process Keys passed to command
  \path (\ellkey{intersection start}) -- (\ellkey{intersection end});
    \path[opacity=\ellkey{opacity},draw=\ellkey{ellipse one draw},rotate around={\ellkey{ellipse one rotation}:(\ellkey{ellipse one center})}] (\ellkey{ellipse one center}) circle (\ellkey{ellipse one radius a} and \ellkey{ellipse one radius b});
    \path[opacity=\ellkey{opacity},draw=\ellkey{ellipse two draw},rotate around={\ellkey{ellipse two rotation}:(\ellkey{ellipse two center})}] (\ellkey{ellipse two center}) circle (\ellkey{ellipse two radius a} and \ellkey{ellipse two radius b});
    \begin{scope}
        \clip (current bounding box.north west) -| (\ellkey{intersection end}) -- (\ellkey{intersection start}) |- (current bounding box.south west) -- cycle;
        \clip[rotate around={\ellkey{ellipse one rotation}:(\ellkey{ellipse one center})}] (\ellkey{ellipse one center}) circle (\ellkey{ellipse one radius a}*1cm-0.2pt and \ellkey{ellipse one radius b}*1cm-0.2pt);
        \fill[opacity=\ellkey{opacity},\ellkey{ellipse one fill}] (current bounding box.north east) rectangle (current bounding box.south west);
    \end{scope}
    \begin{scope}
        \clip (current bounding box.north east) -| (\ellkey{intersection end}) -- (\ellkey{intersection start}) |- (current bounding box.south east) -- cycle;
        \clip[rotate around={\ellkey{ellipse two rotation}:(\ellkey{ellipse two center})}] (\ellkey{ellipse two center}) circle (\ellkey{ellipse two radius a}*1cm-0.2pt and \ellkey{ellipse two radius b}*1cm-0.2pt);
        \fill[opacity=\ellkey{opacity},\ellkey{ellipse two fill}] (current bounding box.north east) rectangle (current bounding box.south west);
    \end{scope}
    \begin{scope}
        \clip (current bounding box.north west) -| (\ellkey{intersection end}) -- (\ellkey{intersection start}) |- (current bounding box.south west) -- cycle;
        \clip[rotate around={\ellkey{ellipse two rotation}:(\ellkey{ellipse two center})}] (\ellkey{ellipse two center}) circle (\ellkey{ellipse two radius a}*1cm-0.2pt and \ellkey{ellipse two radius b}*1cm-0.2pt);
        \fill[opacity=\ellkey{opacity},\ellkey{ellipse two fill}] (current bounding box.north east) rectangle (current bounding box.south west);
    \end{scope}
    \begin{scope}
        \clip (current bounding box.north east) -| (\ellkey{intersection end}) -- (\ellkey{intersection start}) |- (current bounding box.south east) -- cycle;
        \clip[rotate around={\ellkey{ellipse one rotation}:(\ellkey{ellipse one center})}] (\ellkey{ellipse one center}) circle (\ellkey{ellipse one radius a}*1cm-0.2pt and \ellkey{ellipse one radius b}*1cm-0.2pt);
        \fill[opacity=\ellkey{opacity},\ellkey{ellipse one fill}] (current bounding box.north east) rectangle (current bounding box.south west);
    \end{scope}
}

\begin{tikzpicture}
    \threedellipses
    {   ellipse one center={-1,1},
        ellipse two center={-1,2},
        ellipse one radius a=2,
        ellipse two radius a=1.95,
        ellipse one radius b=1.5,
        ellipse two radius b=2.25,
        ellipse one rotation=-30,
        ellipse two rotation=-50,
        intersection start={-5,0},
        intersection end={5,2},
    }
\end{tikzpicture}

\end{document}

산출

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

답변3

패키지를 사용하는 솔루션이 있습니다 tikz-3dplot. 실제로 3D 회전을 위해 만들어졌습니다. 내 제안은 다음과 같습니다.

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\begin{document}

\def\roll{30}
\def\pitch{40}
\def\yaw{30}
\def\xMainRot{100}
\def\zMainRot{30}
%Setting the main coords
\tdplotsetmaincoords{\xMainRot}{\zMainRot}
\begin{tikzpicture}[tdplot_main_coords,]
%%%%%%%%%%%%%%%%%%%%%
%%%The second ellipse
%%%%%%%%%%%%%%%%%%%%%
\begin{scope}[canvas is yx plane at z=0]
\draw[red]  (0,0) ellipse (1cm and 2cm);
%I don't know exactly why, but I guess the "transform shape" command messes up with the position of the node, so I have to shift it.
\end{scope}
\begin{scope}[canvas is yx plane at z=0]
\node[yshift=-30,xshift=1,rotate=90,red,transform shape,sloped] (0,0) {first ellipse};
\end{scope}

%%%%%%%%%%%%%%%%%%%%%
%%%The second ellipse
%%%%%%%%%%%%%%%%%%%%%
%you can set the rotated ellipse in the rotation you want
%this is added to the main coords
\tdplotsetrotatedcoords{0}{\pitch}{0}

%you can set an offset with the x=offset option
\begin{scope}[tdplot_rotated_coords,canvas is yz plane at x=0]
  \draw[blue,dashed] (0,-2) -- (0,2);
  \draw[blue,dashed] (-2,0) -- (2,0);
\draw[blue,dashed]  (0,0) ellipse (1cm and 2cm);
%In case it's written upside down, change yscale to -1
\node[yshift=-20,xshift=10,yscale=1,rotate=90,blue,transform shape,sloped] (0,0) {second ellipse};
\end{scope}    
\end{tikzpicture}
\end{document}

이는 다음과 같은 출력을 제공합니다여기에 이미지 설명을 입력하세요

죄송합니다. Tom의 아름다운 색상 교차점을 어떻게 넣을지 모르겠습니다 :)

관련 정보