大家好,下图中的帽子是怎么画的?我想从大椭圆与圆锥的起点线的第一个交点到第二个交点画一条虚线。但是我必须估算要画的尺寸。
\begin{tikzpicture}[line join=round,line cap=round, >=stealth, font=\footnotesize]
\def\a{1.5}
\def\b{.6}
\def\h{3.5}
\pgfmathsetmacro\g{asin(\b/\h)}
\pgfmathsetmacro\xo{\a *cos(\g)}
\pgfmathsetmacro\yo{\b *sin(\g)}
\draw[dashed] (\xo,\yo) coordinate (M) arc (\g:180-\g:{\a} and {\b}) coordinate(N) (180:\a) (90:\h) coordinate(S) --(0:0);
\draw (-\xo,\yo) arc (180-\g:360+\g:{\a} and {\b}) (M)--(S)--(N);
\pgfmathsetmacro\aa{2*\a}
\pgfmathsetmacro\bb{2*\b}
\pgfmathsetmacro\gg{atan(\a/\h)}
% \path[name path=SM] (S)--(M);
% \path[name path=ellipseB] (0:\aa) arc (0:180:{\aa} and {\bb});
% \path[name intersections={of=SM and ellipseB}] (intersection-1) coordinate(I) node{I};
% \path (0:0) coordinate(O) node{O} (0:\aa) coordinate(C) ($(O)!(I)!(C)$) coordinate(H) node{H};
% \draw let \p1=($(H)-(O)$), \p2=($(I)-(H)$) in (0:\aa) arc (0:atan(divide(veclen(\x2,\y2),veclen(\x1,\y1))):{\aa} and {\bb});
\draw (0:\aa) arc (0:70:{\aa} and {\bb}) coordinate(P) (0:\aa) arc (0:-250:{\aa} and {\bb});
\draw[dashed] (P) arc (70:110:{\aa} and {\bb});
\end{tikzpicture}
答案1
您可以使用由(加载)fillbetween
提供的库:pgfplots
tikz
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{fillbetween}
\begin{document}
\begin{tikzpicture}[line join=round, line cap=round, >=stealth, font=\footnotesize]
\pgfmathsetmacro{\a}{1.5}
\pgfmathsetmacro{\b}{.6}
\pgfmathsetmacro{\h}{3.5}
\pgfmathsetmacro{\g}{asin(\b/\h)}
\pgfmathsetmacro{\xo}{\a*cos(\g)}
\pgfmathsetmacro{\yo}{\b*sin(\g)}
\draw[dashed]
(\xo,\yo) coordinate (M)
arc[start angle={\g}, end angle={180-\g}, x radius={\a}, y radius={\b}] coordinate (N)
(180:\a)
(90:\h) coordinate(S) -- (0:0);
\draw[name path=SM]
(-\xo,\yo)
arc[start angle={180-\g}, end angle={360+\g}, x radius={\a}, y radius={\b}]
(M) -- (S) -- (N);
\pgfmathsetmacro{\aa}{2*\a}
\pgfmathsetmacro{\bb}{2*\b}
\pgfmathsetmacro{\gg}{atan(\a/\h)}
\path[name path=ellipseB]
(0:{\aa})
arc[start angle={0}, end angle={180}, x radius={\aa}, y radius={\bb}];
\draw[intersection segments={of=SM and ellipseB, sequence={R2}}, dashed];
\draw[intersection segments={of=SM and ellipseB, sequence={R1 R3}}];
\draw
(0:{\aa})
arc[start angle={360}, end angle={180}, x radius={\aa}, y radius={\bb}];
\end{tikzpicture}
\end{document}
答案2
这是另一种选择元帖子方法使用复制当前图片并将其剪辑到路径的能力。
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
beginfig(1);
path brim, band, cone, apex;
band = fullcircle scaled 10mm yscaled 1/2;
brim = band scaled 3;
apex = (40mm +-+ length point 0 of band) * up;
numeric r; r = 1/8; % allow a little perspective...
cone = subpath (4-r, 8+r) of band -- apex -- cycle;
draw band;
draw brim;
draw point 4 of band -- point 0 of brim;
picture hidden; hidden = currentpicture;
clip hidden to cone; unfill cone;
draw hidden dashed evenly scaled 1/2 withcolor 3/4;
draw cone;
endfig;
\end{mplibcode}
\end{document}
编译此文件lualatex
可获得如下 PDF:
它确实看起来有点奇怪,因为它太高了,但我使用了 OP 图片上写的尺寸。