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:

我對使用有點猶豫xslantyslant因為橢圓似乎正在移動和拉伸。

這是一張在不同平面上的兩個橢圓的糟糕圖片(我的手機相機閃光燈無法工作)。

在此輸入影像描述

如果調整我的較小的橢圓,它會拉伸並且看起來會發生巨大的變化。

從下圖中,焦點現在似乎位於較小橢圓的中心,並且已經拉長。

在此輸入影像描述

編輯:

所以我找到了這個帖子為什麼沒有在 Tait-Bryan 約定中使用 tikz-3dplot 在好的平面上繪製圓弧但我不完全理解程式碼。然而,海報能夠旋轉橢圓並具有更好的視覺吸引力,並且海報可以定義其所在的平面,例如xyyz、 和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 來做這個,但是蒂克茲對此並不擅長。該解決方案使用pgf鍵一個方便的鍵值介面。

使用標準配置,它看起來像這樣:

在此輸入影像描述

該巨集將圖片分為“右部分”和“左部分”,因此相交線必須在兩個橢圓之外開始和結束:

在此輸入影像描述

然後它首先繪製“後部”,然後繪製“前部”:

在此輸入影像描述

程式碼

\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}

這給出了以下輸出在此輸入影像描述

抱歉,不知道如何放置湯姆美麗的顏色交叉點:)

相關內容