在 TikZ 中绘制一个带有圆形底座的楔子

在 TikZ 中绘制一个带有圆形底座的楔子

我想在 TikZ 中绘制下图。 图1

当然,我能够画出它的大部分组件,但我无法画出圆柱形部分。这是我迄今为止的努力成果。

梅威瑟:

\documentclass[14pt]{memoir}
\usepackage{tikz, tikz-3dplot}
\usetikzlibrary{arrows.meta}
\begin{document}
\tdplotsetmaincoords{60}{-30}
\begin{tikzpicture}[tdplot_main_coords, scale=0.9]
\tdplotsetrotatedcoords{0}{45}{0}
\pgfmathsetmacro{\r}{3}
\pgfmathsetmacro{\x}{1.25}
\pgfmathsetmacro{\y}{sqrt(\r^2-\x^2)}
\draw [thick, -Stealth] (-1,0,0) -- (5,0,0) node [right] {$x$};
\draw [thick, -Stealth] (0,-5,0) -- (0,5,0) node [left] {$y$};
\filldraw [fill=cyan!40, very thick, draw=blue, canvas is xy plane at z=0, opacity=0.5] (0,-\r) arc [start angle=-90, end angle=90, radius=\r] -- cycle;
\filldraw [fill=red!50, very thick, draw=red, canvas is yz plane at x=\x] (-\y,0) rectangle (\y,\x);

\begin{scope}[tdplot_rotated_coords]
\filldraw [fill=cyan!40, very thick, draw=blue, canvas is yz plane at x=0, opacity=0.5] (\r,0) arc [start angle=0, end angle=180, x radius=\r, y radius=\r*sqrt(2)] -- cycle;
\end{scope}

\begin{scope}[canvas is xz plane at y=0]
\draw [semithick] (\x-0.25,0) -- (\x-0.25,0.25) -- (\x,0.25);
\draw [semithick] (0.47,0) arc [start angle=0, end angle=45, radius=0.47];
\node [font=\small] at (22.5:0.65) {$\theta$};
\draw [red, very thick] (0,0) -- (\x,\x) -- (\x,0) (\x,0) -- (0,0);
\end{scope}

\draw [thick, -Stealth] (0,0,-1) -- (0,0,5) node [left] {$z$};
\fill (\x,-\y,0) circle [radius=3pt];
\node [right, font=\small] at (\x,-\y,0) {$(x,-\sqrt{r^2-x^2},0)$};
\draw [semithick, font=\small] (\x,1.25,\x) --++ (2,0,2) node [above, inner sep=1mm] {$2\sqrt{r^2-x^2}$};
\end{tikzpicture}
\end{document}

及其输出: 图2 我该如何完成这个图?任何帮助都将不胜感激!

我在@user241266 的回答中提到的照片

如图

答案1

在 tikz 中绘制 3D 旋转立体图形几乎总是很困难。但如果​​可以使用等距透视,圆柱体就是一个容易的例外。这是因为我们知道椭圆和其“极限”母线之间的切点在哪里。这些点(我示例中的 T1 和 T2)在坐标平面中相对于轴成 45 度角。

考虑到这一点,我们可以执行以下操作(点 P、T1 和 T2 仅作为参考绘制,可以删除或注释它们)。

\documentclass[border=2mm]{standalone}
\usepackage    {tikz}
\usetikzlibrary{3d}

\pgfmathsetmacro\ip{0.5*sqrt(3)} % isometric perspective factor
\tikzset%
{% styles
  cylinder/.style= {fill=cyan,fill opacity=0.5},
  rectangle/.style={fill=red!50,fill opacity=0.5},
  reclines/.style= {draw=red!75!black,dashed},
}

\begin{document}
\begin{tikzpicture}[scale=0.75,line cap=round,line join=round,semithick,%
                    x={({\ip cm,0.5 cm})},y={(-\ip cm,0.5 cm)},z={(0 cm,1cm)}]
% dimensions
\def\r{3}                                % radius
\def\h{3}                                % height
\pgfmathsetmacro\th{atan(\h/\r)}         % theta angle
\def\px{1.25}                            % point P, x
\pgfmathsetmacro\py{sqrt(\r*\r-\px*\px)} % point P, y
\pgfmathsetmacro\pz{\px*tan(\th)}        % point P, z
\pgfmathsetmacro\tx {\r*cos(45)}         % tangent points T1 and T2, x
\pgfmathsetmacro\ty{-\r*sin(45)}         % tangent points T1 and T2, y
\pgfmathsetmacro\tz{\tx*tan(\th)}        % tangent point  T2, z
\pgfmathsetmacro\a  {\r/sin(\th)}        % ellipse semimajor axis
% x, y axis
\draw[-latex] (-1,0,0)    -- (3.5,0,0)  node [above] {$x$};
\draw[-latex] (0,-\r-1,0) -- (0,\r+1,0) node [above] {$y$};
% bottom semicircle
\begin{scope}[canvas is xy plane at z=0]
  \fill[cylinder]    (0,\r)    arc  (90:-90:\r) -- cycle;
  \draw[blue,dashed] (0,\r)    arc  (90:-45:\r);
  \draw[blue]        (\tx,\ty) arc (-45:-90:\r);
\end{scope}
% rectangle
\begin{scope}[canvas is yz plane at x=\px]
  \fill[rectangle] (-\py,0) rectangle (\py,\pz);
  \draw[reclines]  (\py,\pz) -- (\py,0) -- (-\py,0);
\end{scope}
% triangle
\begin{scope}[canvas is xz plane at y=0]
  \draw[reclines]   (0,0) -- (\px,0) -- (\px,\pz);
  \draw[thin] (\px-0.2,0) |- (\px,0.2);
  \draw(0.3,0) arc (0:\th:0.3) node [right,yshift=0.15cm] {$\theta$};
\end{scope}
% cylindric surface
\fill[cylinder]
     {[canvas is xy plane at z=0] (0,-\r) arc (-90:-45:\r)} -- (\tx,\ty,\tz)
     {[rotate around y=-\th,canvas is xy plane at z=0] arc (-45:-90:\a cm and \r cm)};
\draw[blue] (\tx,\ty,0) -- (\tx,\ty,\tz);
% top semiellipse
\draw[blue,cylinder,rotate around y=-\th,canvas is xy plane at z=0]
     (0,\r) arc (90:-90:\a cm and \r cm) -- cycle;
\draw[red!75!black] (0,0,0)      -- (\px,0,\pz);
\draw[red!75!black] (\px,-\py,0) -- (\px,-\py,\pz) -- (\px,\py,\pz);
% points (for reference), erase or comment them
\fill (\px,\py,\pz) circle (1.5pt) node [left]  {$P$};
\fill (\tx,\ty,0)   circle (1.5pt) node [right] {$T_1$};
\fill (\tx,\ty,\tz) circle (1.5pt) node [right] {$T_2$};
% z axes
\draw[-latex] (0,0,-1) -- (0,0,\h) node [above] {$z$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您可以使用它fillbetween在穿过最右边点的垂直线之间构建一些交叉段。

\documentclass[14pt]{memoir}
\usepackage{tikz, tikz-3dplot,pgfplots}
\usetikzlibrary{arrows.meta,bbox}
\usepgfplotslibrary{fillbetween}
\begin{document}
\tdplotsetmaincoords{60}{-30}
\begin{tikzpicture}[tdplot_main_coords, scale=0.9]
\tdplotsetrotatedcoords{0}{45}{0}
\pgfmathsetmacro{\r}{3}
\pgfmathsetmacro{\x}{1.25}
\pgfmathsetmacro{\y}{sqrt(\r^2-\x^2)}
\draw [thick, -Stealth] (-1,0,0) -- (5,0,0) node [right] {$x$};
\draw [thick, -Stealth] (0,-5,0) -- (0,5,0) node [left] {$y$};
\filldraw[local bounding box=bb1,bezier bounding box,
    name path=lower,
    fill=cyan!40, very thick, draw=blue, canvas is xy plane at z=0, opacity=0.5] (0,-\r) arc [start angle=-90, end angle=90, radius=\r] -- cycle;
\filldraw [fill=red!50, very thick, draw=red, canvas is yz plane at x=\x] (-\y,0) rectangle (\y,\x);

\begin{scope}[tdplot_rotated_coords,local bounding box=bb2,bezier bounding box]
\filldraw [fill=cyan!40, very thick, draw=blue, canvas is yz plane at x=0, 
    name path global=upper,opacity=0.5] (\r,0) arc [start angle=0, end angle=180, x radius=\r, y radius=\r*sqrt(2)] -- cycle;
\end{scope}
\path[name path=aux1] (bb1.south east) -- (bb2.north east);

\path[%draw=magenta,thick,->,
        intersection segments={
                of=lower and aux1,
                sequence={L1--R2}
              },name path=lowarc];

\path[%draw=orange,thick,->,
    fill=blue!60,opacity=0.5,
        intersection segments={
                of=lowarc and upper,
                sequence={L*--R2}
              },name path=lowarc];


\begin{scope}[canvas is xz plane at y=0]
\draw [semithick] (\x-0.25,0) -- (\x-0.25,0.25) -- (\x,0.25);
\draw [semithick] (0.47,0) arc [start angle=0, end angle=45, radius=0.47];
\node [font=\small] at (22.5:0.65) {$\theta$};
\draw [red, very thick] (0,0) -- (\x,\x) -- (\x,0) (\x,0) -- (0,0);
\end{scope}

\draw [thick, -Stealth] (0,0,-1) -- (0,0,5) node [left] {$z$};
\fill (\x,-\y,0) circle [radius=3pt];
\node [right, font=\small] at (\x,-\y,0) {$(x,-\sqrt{r^2-x^2},0)$};
\draw [semithick, font=\small] (\x,1.25,\x) --++ (2,0,2) node [above, inner sep=1mm] {$2\sqrt{r^2-x^2}$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

感谢@Juan Castaño 和@user241266 的回答,我能够找到另一种方法来绘制圆柱截面,即使用 TikZ 手册第 137 页上的圆柱坐标定义,

% definition of cylindrical coordinates
\makeatletter
\define@key{cylindricalkeys}{angle}{\def\myangle{#1}}
\define@key{cylindricalkeys}{radius}{\def\myradius{#1}}
\define@key{cylindricalkeys}{z}{\def\myz{#1}}
\tikzdeclarecoordinatesystem{cylindrical}%
{%
\setkeys{cylindricalkeys}{#1}%
\pgfpointadd{\pgfpointxyz{0}{0}{\myz}}{\pgfpointpolarxy{\myangle}{\myradius}}
}

我用的是\foreach梅威瑟:

\documentclass[12pt, border=1mm]{standalone}
\usepackage{tikz, tikz-3dplot}
\usetikzlibrary{arrows.meta}
\makeatletter
\define@key{cylindricalkeys}{angle}{\def\myangle{#1}}
\define@key{cylindricalkeys}{radius}{\def\myradius{#1}}
\define@key{cylindricalkeys}{z}{\def\myz{#1}}
\tikzdeclarecoordinatesystem{cylindrical}%
{%
\setkeys{cylindricalkeys}{#1}%
\pgfpointadd{\pgfpointxyz{0}{0}{\myz}}{\pgfpointpolarxy{\myangle}{\myradius}}
}
\begin{document}
\tdplotsetmaincoords{60}{-30}
\begin{tikzpicture}[tdplot_main_coords, scale=0.9, line cap=round, line join=round]
\tdplotsetrotatedcoords{0}{45}{0}
\pgfmathsetmacro{\r}{3}
\pgfmathsetmacro{\x}{1.25}
\pgfmathsetmacro{\y}{sqrt(\r^2-\x^2)}
\draw [thick, -Stealth] (-1,0,0) -- (5,0,0) node [right] {$x$};
\draw [thick, -Stealth] (0,-5,0) -- (0,5,0) node [left] {$y$};
\filldraw [fill=cyan!40, very thick, draw=blue, canvas is xy plane at z=0, opacity=0.5] (0,-\r) arc [start angle=-90, end angle=90, radius=\r] -- cycle;
\foreach \a in {-90,-88,...,88}
\fill [cyan!67, opacity=2/3] (cylindrical cs:angle=\a, radius=\r, z=0) -- (cylindrical cs:angle=\a+2, radius=\r, z=0) -- (cylindrical cs:angle=\a+2, radius=\r, z={3*abs(cos(\a+2))}) -- (cylindrical cs:angle=\a, radius=\r, z={3*abs(cos(\a))}) -- (cylindrical cs:angle=\a, radius=\r, z=0);
\filldraw [fill=red!50, very thick, draw=red, canvas is yz plane at x=\x] (-\y,0) rectangle (\y,\x);
\draw [thick, -Latex, canvas is xy plane at z=0] (0,0) -- (\x,-\y);
\node [left, font=\small] at (0,\r,0) {$r$};
\node [left, font=\small] at (0,-\r,0) {$-r$};

\begin{scope}[tdplot_rotated_coords]
\filldraw [fill=cyan!40, very thick, draw=blue, canvas is yz plane at x=0, opacity=0.5] (\r,0) arc [start angle=0, end angle=180, x radius=\r, y radius=\r*sqrt(2)] -- cycle;
\end{scope}

\begin{scope}[canvas is xz plane at y=0]
\draw [semithick] (\x-0.25,0) -- (\x-0.25,0.25) -- (\x,0.25);
\draw [semithick] (0.47,0) arc [start angle=0, end angle=45, radius=0.47];
\node [font=\small] at (22.5:0.65) {$\alpha$};
\draw [red, very thick] (0,0) -- (\x,\x) -- (\x,0) (\x,0) -- (0,0);
\end{scope}

\draw [thick, -Stealth] (0,0,-1) -- (0,0,5) node [left] {$z$};
\fill (\x,-\y,0) circle [radius=2.75pt];
\node [right, font=\small] at (\x,-\y,0) {$(x,-\sqrt{r^2-x^2},0)$};
\draw [semithick, font=\small] (\x,1.25,\x) --++ (2,0,2) node [above, inner sep=1mm] {$2\sqrt{r^2-x^2}$};
\path [canvas is xy plane at z=0, font=\small] (0,0) -- node [sloped,midway, above, inner sep=1mm] {$r$} (\x,-\y);
\path [thick, -Latex, canvas is xy plane at z=0, font=\small] (0,0) -- node [sloped, midway, below, inner sep=1mm] {$x$} (1.3*\x,0);
\end{tikzpicture}
\end{document}

输出:

楔

相关内容