绘制顶部边缘为虚线、底部边缘为实线的填充椭圆的更简单的方法是什么?

绘制顶部边缘为虚线、底部边缘为实线的填充椭圆的更简单的方法是什么?

我想画一个椭圆,上半部分是虚线,下半部分是实线,但也填充了。有没有直接使用命令ellipse来做到这一点的方法\usetikzlibrary{shapes}

我现在做的,感觉像个小把戏,就是为上半部分和下半部分画两个圆弧,这样我就可以将一个圆弧设置为虚线,另一个不设置。然后在它们上面画一个椭圆,但没有边,只是填充。像这样

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}

\def\xR{1.25}; %x radius of ellipse
\def\yR{0.5};  %y radius of ellipse

\draw [dashed,domain=0:180] plot ({\xR*cos(\x)}, {\yR*sin(\x)}); %top half
\draw [domain=-180:0] plot ({\xR*cos(\x)}, {\yR*sin(\x)}); %bottom half

\fill[gray!20] (0,0) ellipse ({\xR} and {\yR}); %overlay with ellipse

\end{tikzpicture}

\end{document}

Mathematica 图形

有没有更好的方法呢?

答案1

使用弧线。我也会先填充该区域,这样看起来可能会更好一些。

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}

\def\xR{1.25}; %x radius of ellipse
\def\yR{0.5};  %y radius of ellipse

\fill[gray!20] (0,0) ellipse ({\xR} and {\yR}); %overlay with ellipse
\draw [dashed]  (-\xR,0) arc[start angle=180,end angle=0,x radius=1.25,y radius=0.5]; %top half
\draw (-\xR,0) arc[start angle=180,end angle=360,x radius=1.25,y radius=0.5]; %bottom half
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者使用两个命令“only”。

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\def\xR{1.25}; %x radius of ellipse
\def\yR{0.5};  %y radius of ellipse
\draw [dashed,fill=gray!20] (0,0) ellipse ({\xR} and {\yR});
\draw (-\xR,0) arc[start angle=180,end angle=360,x radius=1.25,y radius=0.5]; %bottom half
\end{tikzpicture}
\end{document}

您可以编写样式来划掉路径的前 50%(或任意%):

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[draw only after/.style={preaction={decorate,decoration={markings,mark=at
position 0 with {\pgfmathsetmacro\mypoff{\pgfdecoratedpathlength*#1}\xdef\mypoff{\mypoff}
\pgfmathsetmacro\mypl{\pgfdecoratedpathlength}\xdef\mypl{\mypl}}}},
postaction={draw,dash pattern=on 0pt off \mypoff on \mypl}}]
\draw [dashed,fill=gray!20,draw only after=1/2] (1.25,0)
arc[start angle=00,end angle=360,x radius=1.25,y radius=0.5]; 
\end{tikzpicture}
\end{document}

相关内容