如何在圓柱體上畫一個正方形?

如何在圓柱體上畫一個正方形?

設一個圓柱體,其基圓的半徑等於3,圓柱體的高度等於2 ABCD。我試過A, BC, D

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,calc,backgrounds,patterns}
\begin{document}
\pgfmathsetmacro{\myr}{3}
\pgfmathsetmacro{\h}{2}
\def\angB{0}
\def\phi{120}
\def\angA{{\angB + \phi}}
\def\angC{\phi - 180}
\tdplotsetmaincoords{65}{100}
\begin{tikzpicture}[tdplot_main_coords,scale=1,line cap=butt,line join=round]
\begin{scope}[canvas is xy plane at z=0]
\draw[dashed] (\tdplotmainphi:\myr) arc(\tdplotmainphi:\tdplotmainphi+180:\myr);
\coordinate (O) at (0,0);
\coordinate (A) at (\angA:\myr);
\coordinate (B) at (\angB:\myr);
\draw[thick] (\tdplotmainphi:\myr) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\myr)
coordinate(BL);
\end{scope}
\begin{scope}[canvas is xy plane at z=\h]
\coordinate (O') at (0,0);
\coordinate (C) at (\angC:\myr);
\coordinate (D) at ($ (A) + (C) -(B) $);
\draw[thick]  (O') circle[radius=\myr];
\draw [thick](BR) -- (\tdplotmainphi:\myr) (BL) -- (\tdplotmainphi-180:\myr); 
\end{scope}
\fill (A) circle[radius=1pt] node[above] {$A$};
\fill (B) circle[radius=1pt] node[above] {$B$};
\fill (C) circle[radius=1pt] node[above] {$C$};
\fill (D) circle[radius=1pt] node[above] {$D$};
\draw[dashed]  (C) -- (B) --   (A)  -- (D) ;
\draw[] (C) -- (D);
\end{tikzpicture}
\end{document} 

在此輸入影像描述

\def\angB{0}當我更改為時,此程式碼不正確\def\angB{30}。如何獲得通用方法?

答案1

考慮正方形上的三個點,例如BCD。不失一般性,我們可以假設它們具有座標

 C = (r \cos \phi,r \sin\phi,h)
 D = (r \cos (180-\phi),r \sin(180-\phi),h)
 B = (r \cos \phi,-r \sin\phi,0)

它們形成正方形的條件意味著

 CD = BC

在哪裡

 CD = 2r \cos \phi
 BC = \sqrt{(2r \sin\phi)^2+h^2}

這產生

 \phi = \acos(h^2/(4r^2))/2

這證實了 hpechristiansens 的數值結果:

 CD = 2 r \cos \left(\frac{1}{2} \acos\left(\frac{h^2}{4 r^2}\right)\right)

微量元素

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,calc,backgrounds,patterns}
\begin{document}
\pgfmathsetmacro{\myr}{3}
\pgfmathsetmacro{\h}{2}
\pgfmathsetmacro{\angA}{acos(\h*\h/(4*\myr*\myr))/2}
\tdplotsetmaincoords{65}{100}
\begin{tikzpicture}[tdplot_main_coords,scale=1,line cap=butt,line join=round]
\begin{scope}[canvas is xy plane at z=0]
\draw[dashed] (\tdplotmainphi:\myr) arc(\tdplotmainphi:\tdplotmainphi+180:\myr);
\coordinate (O) at (0,0);
\coordinate (A) at (\angA:\myr);
\coordinate (B) at (180-\angA:\myr);
\draw[thick] (\tdplotmainphi:\myr) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\myr)
coordinate(BL);
\end{scope}
\begin{scope}[canvas is xy plane at z=\h]
\coordinate (O') at (0,0);
\coordinate (C) at (-180+\angA:\myr);
\coordinate (D) at (-\angA:\myr);
\draw[thick]  (O') circle[radius=\myr];
\draw [thick](BR) -- (\tdplotmainphi:\myr) (BL) -- (\tdplotmainphi-180:\myr); 
\end{scope}
\fill (A) circle[radius=1pt] node[above] {$A$};
\fill (B) circle[radius=1pt] node[above] {$B$};
\fill (C) circle[radius=1pt] node[above] {$C$};
\fill (D) circle[radius=1pt] node[above] {$D$};
\draw[dashed]  (C) -- (B) --   (A);
\draw[thick] (A) -- (D) -- (C);
\end{tikzpicture}
\end{document}

在此輸入影像描述

答案2

在這段程式碼中,該點B可以在圓上的任何地方運行。您可以更改它\def\angB{-20},然後您可以選擇正方形ABCD

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,calc,backgrounds,patterns}
\usepackage{fouriernc}
\begin{document}
    \pgfmathsetmacro{\myr}{3}
    \pgfmathsetmacro{\h}{2}
    \pgfmathsetmacro{\d}{sqrt(\h*\h+4*\myr*\myr)/sqrt(2)}
    \def\angB{-20}
    \def\angA{{\angB + acos((2*\myr*\myr-\d*\d)/(2*\myr*\myr)}}
    \tdplotsetmaincoords{65}{100}
    \begin{tikzpicture}[tdplot_main_coords,scale=1,line cap=butt,line join=round]
    \begin{scope}[canvas is xy plane at z=0]
    \draw[dashed] (\tdplotmainphi:\myr) arc(\tdplotmainphi:\tdplotmainphi+180:\myr);
    \coordinate (O) at (0,0);
    \coordinate (A) at (\angA:\myr);
    \coordinate (B) at (\angB:\myr);
    \coordinate (A') at ($ 2*(O) - (A) $);
    \coordinate (B') at ($ 2*(O) - (B) $);

    \draw[thick] (\tdplotmainphi:\myr) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\myr)
    coordinate(BL);
    \end{scope}
    \begin{scope}[canvas is xy plane at z=\h]
    \coordinate (O') at (0,0);
    \coordinate (C) at  ($ (O') - (O) +(A')$);
    \coordinate (D) at  ($ (O') - (O) +(B')$);
    \draw[thick]  (O') circle[radius=\myr];
    \draw [thick](BR) -- (\tdplotmainphi:\myr) (BL) -- (\tdplotmainphi-180:\myr); 
    \end{scope}
    \foreach \v/\position in { B/below,O/below,A/below,B'/above,A'/above,C/above,D/above} {\draw[draw =black, fill=black] (\v) circle (1pt) node [\position=0.2mm] {$\v$};
    }
    \draw[thick]    (C) -- (D) ;
    \draw[dashed] (A) -- (A') (B) -- (B') (A) -- (B) -- (A') -- (B') -- cycle (B') -- (D) (A') -- (C) (A) --  (D) (B) -- (C); 
    \end{tikzpicture}
\end{document} 

在此輸入影像描述

透過使用一些計算A, B, C, D,可以選擇 點的座標在此輸入影像描述

然後,程式碼

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\begin{document}
    \pgfmathsetmacro{\myr}{3}
    \pgfmathsetmacro{\h}{2}
    \tdplotsetmaincoords{65}{100}
    \begin{tikzpicture}[tdplot_main_coords,scale=1,line cap=butt,line join=round]
    \begin{scope}[canvas is xy plane at z=0]
    \draw[dashed] (\tdplotmainphi:\myr) arc(\tdplotmainphi:\tdplotmainphi+180:\myr);
    \coordinate (O) at (0,0);
    \coordinate (A) at ({1/4*sqrt(8*\myr*\myr-2*\h*\h)}, {sqrt(1/2*\myr*\myr+(1/8)*\h*\h)});
    \coordinate (B) at ({1/4*sqrt(8*\myr*\myr-2*\h*\h)}, -{sqrt(1/2*\myr*\myr+(1/8)*\h*\h)});
    \draw[thick] (\tdplotmainphi:\myr) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\myr)
    coordinate(BL);
    \end{scope}
    \begin{scope}[canvas is xy plane at z=\h]
    \coordinate (O') at (0,0);
    \coordinate (C) at ({-1/4*sqrt(8*\myr*\myr-2*\h*\h)}, -{sqrt(1/2*\myr*\myr+(1/8)*\h*\h)});
    \coordinate (D) at ({-1/4*sqrt(8*\myr*\myr-2*\h*\h)}, {sqrt(1/2*\myr*\myr+(1/8)*\h*\h)});
    \draw[thick]  (O') circle[radius=\myr];
    \draw [thick](BR) -- (\tdplotmainphi:\myr) (BL) -- (\tdplotmainphi-180:\myr); 
    \end{scope}
    \foreach \v/\position in { B/below,O/below,A/below,C/above,D/above} {\draw[draw =black, fill=black] (\v) circle (1pt) node [\position=0.2mm] {$\v$};
    }
    \draw[thick]    (C) -- (D) ;
    \draw[dashed]    (C) -- (B) -- (A) --  (D)  ; 
    \end{tikzpicture}
\end{document} 

答案3

這只是為了幫助/檢查真正的答案。我在 3D CAD(Fusion 360)中繪製了該圖,並根據您的描述添加了約束。這就是我得到的(比例(10:1)):

帶有方形的圓柱體

正方形的邊長是 4.4721

具有所有措施的氣缸

相關內容