如何用 Tikz 绘制圆柱体并取其表面的一个点?

如何用 Tikz 绘制圆柱体并取其表面的一个点?

我正在尝试绘制与此图类似的图形,但当我已经绘制好后,我不知道如何将点 A 和 B 放在椭圆弧上?有人能帮我吗?

在此处输入图片描述

这是我的代码

\documentclass[border=3mm]{standalone}
\usepackage[utf8]{vietnam}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\a{3} 
\def\b{1} 
\def\h{6} 
\draw (0,\h)--(\a,\h) node[midway, above]{$r$};
\filldraw (0,\h) circle(1pt);
\draw[<->, xshift=1cm] (\a,0)--(\a,\h) node[midway, right] {$h$};
\draw[gray] (\a,0) ++(0.5cm,0)--+(0.75cm,0)
(\a,\h) ++(0.5cm,0)--+(0.75cm,0);
\draw[cyan, thick] (\a,0)--(\a,\h) (-\a,0)--(-\a,\h);
\draw[dashed, cyan, thick] (\a,0) arc [x radius=\a, y radius=\b, start angle=0, end angle=180];
\draw[cyan, thick] (-\a,0) arc [x radius=\a, y radius=\b, start angle=180, end angle=360];
\draw[cyan, thick] (0,\h) ellipse (\a cm and \b cm);
\end{tikzpicture}
\end{document}

答案1

给你!

在此处输入图片描述

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[cyan,thick]
\def\a{2} 
\def\b{1} 
\def\h{4} 
\def\t{50}
\path (\t:{\a} and {\b}) 
+(90:\h) coordinate (Bt)
+(90:.8*\h) coordinate (B);
\path (180+\t:{\a} and {\b}) 
+(90:\h) coordinate (At)
+(90:.8*\h) coordinate (A);
\draw (\a,0)--(\a,\h) (-\a,0)--(-\a,\h);
\draw[dashed] (\a,0) arc(0:180:{\a} and {\b});
\draw (\a,0) arc(0:-180:{\a} and {\b});
\draw (0,\h) circle({\a} and {\b});

\draw (A) node[below,black]{A}--(At)--(Bt)--(B) node[black,right]{B};
\foreach \p in {A,B,At,Bt,{0,\h}}
\fill[black] (\p) circle(1.5pt);
\end{tikzpicture}
\end{document}

更新:稍微好一点的代码,用于declare function定义常量。

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[cyan,thick]
\tikzset{declare function={a=2;b=1;h=4;t=50;}}
\path (t:a and b) 
+(90:h) coordinate (Bt)
+(90:.8*h) coordinate (B);
\path (180+t:a and b) 
+(90:h) coordinate (At)
+(90:.8*h) coordinate (A);
\draw[dashed] (a,0) arc(0:180:a and b);
\draw 
(a,0)--(a,h) (-a,0)--(-a,h)
(a,0) arc(0:-180:a and b)
(0,h) circle(a and b)
(A) node[below,black]{A}--(At)--(Bt)--(B) node[black,right]{B};
\foreach \p in {A,B,At,Bt,{0,h}}
\fill[black] (\p) circle(1.5pt);
\end{tikzpicture}
\end{document}

答案2

只需添加一些(移位的)极坐标。

\documentclass[border=3mm]{standalone}
\usepackage[utf8]{vietnam}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[dot/.style={circle,fill,inner sep=1.2pt}]
\def\a{3} 
\def\b{1} 
\def\h{6} 
\draw (0,\h)--(\a,\h) node[midway, above]{$r$};
\filldraw (0,\h) circle(1pt);
\draw[<->, xshift=1cm] (\a,0)--(\a,\h) node[midway, right] {$h$};
\draw[gray] (\a,0) ++(0.5cm,0)--+(0.75cm,0)
(\a,\h) ++(0.5cm,0)--+(0.75cm,0);
\draw[cyan, thick] (\a,0)--(\a,\h) (-\a,0)--(-\a,\h);
\draw[dashed, cyan, thick] (\a,0) arc [x radius=\a, y radius=\b, start angle=0, end angle=180];
\draw[cyan, thick] (-\a,0) arc [x radius=\a, y radius=\b, start angle=180, end angle=360];
\draw[cyan, thick] (0,\h) ellipse (\a cm and \b cm);
\def\myangle{120}
\draw ([yshift=\h cm-2cm]-\myangle:\a cm and \b cm) node[dot,label=below:$A$](A){}
-- ([yshift=\h cm]-\myangle:\a cm and \b cm) -- ([yshift=\h cm]180-\myangle:\a cm and \b cm) --
([yshift=\h cm-2cm]180-\myangle:\a cm and \b cm) node[dot,label=below:$B$](B){};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

您可以使用该intersections库来计算上椭圆与 45 度线之间的两个交点。

\documentclass[border=3mm]{standalone}
\usepackage[utf8]{vietnam}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}[dot/.style={circle,fill,inner sep=1pt}]
\def\a{3} 
\def\b{1} 
\def\h{6} 
\draw (0,\h)--(\a,\h) node[midway, above]{$r$};
\filldraw (0,\h) circle(1pt);
\draw[<->, xshift=1cm] (\a,0)--(\a,\h) node[midway, right] {$h$};
\draw[gray] (\a,0) ++(0.5cm,0)--+(0.75cm,0) (\a,\h) ++(0.5cm,0)--+(0.75cm,0);
\draw[cyan, thick] (\a,0)--(\a,\h) (-\a,0)--(-\a,\h);
\draw[dashed, cyan, thick] (\a,0) arc [x radius=\a, y radius=\b, start angle=0, end angle=180];
\draw[cyan, thick] (-\a,0) arc [x radius=\a, y radius=\b, start angle=180, end angle=360];    
\draw[cyan, thick, name path=ell] (0,\h) ellipse (\a cm and \b cm);
% Using intersections library:
\path[name path=line] ([shift={(-2cm,-2cm)}]0,\h) -- ([shift={(2cm,2cm)}]0,\h);
\path[name intersections={of=ell and line}] (intersection-1) coordinate(b) (intersection-2) coordinate(a);
\draw ([yshift=-1.2cm]a)node[dot,label={below:$A$}]{} -- (a) -- (b) -- ([yshift=-1.2cm]b)node[dot,label={below:$B$}]{};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容