我在 tikz 中绘制椭圆时遇到了一些问题。有人能帮我(演示)如何绘制这样的图形吗?
我希望有人能引领我前行。
- 我无法找到使某些区域变色的方法,例如在“a”和“b”之间。
- 并且圆柱体位于“x_0”和“x”之间,带有斜线。
- 我找不到让椭圆的一半像“a”那样虚线
我迄今为止的代码:
\documentclass[a4paper,10pt,twoside]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{amsmath,amssymb}
\usetikzlibrary{arrows,tikzmark}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
decorations.pathreplacing,decorations.pathmorphing,shapes,%
matrix,shapes.symbols}
\begin{document}
\begin{center}
\begin{minipage}[t]{0,45\textwidth}\centering
%\vspace{1cm}
\definecolor{cqcqcq}{rgb}{0.55,0.55,0.9}
\definecolor{gitter}{rgb}{0.65,0.65,0.65}
\centering
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=0.5cm,y=0.5cm, scale=1]
%\draw [color=gitter, xstep=0.5cm,ystep=0.5cm] (-5,-1) grid (5,10); % Grid område
\draw[->,color=black, line width=1pt] (-5,0) -- (15,0); %X-akse
%\draw[color=black] (-2,0) node[below] {\fontsize{7}{7}$\textbf{-2}$}; % -2 på xaksen
\draw[color=black] (10,-0.4) node[below] {\fontsize{12}{12}$\textbf{b}$}; % b på xaksen
\draw[color=black] (-3,-0.4) node[below] {\fontsize{12}{12}$\textbf{a}$}; % a på xaksen
\draw[color=black] (15,0) node [anchor=west] {\fontsize{7}{7} \text{(1)}}; %Aksenanvn
\draw[->,color=black, line width=1pt] (0,-10) -- (0,10); %Y-akse
\draw[color=black] (0,11.3) node [anchor=north] {\fontsize{7}{7} \text{(2)}}; % Aksenavn
\clip(-5,-10) rectangle (15,10);
\draw[smooth,samples=100,domain=-5:15, line width=1pt, color=blue] plot(\x,{0.002*(\x)^3-0.02*(\x)+0.25*(\x)+4});
\draw[smooth,samples=100,domain=-3:10, line width=1pt, color=blue] plot(\x,{-0.002*(\x)^3+0.02*(\x)-0.25*(\x)-4});
\draw[color=red,line width=1pt] (10,0) ellipse (0.5cm and 4.1cm); %grænse b
\draw[color=red,line width=1pt] (-3,0) ellipse (0.5cm and 1.6cm); %Grænse a
\draw (6,0) ellipse (0.5cm and 2.9cm);
\draw (2,0) ellipse (0.5cm and 2.9cm);
\draw (2,5.812) -- (6,5.812);
\draw (2,-5.812) -- (6,-5.812);
\draw[-,color=black,dashed, line width=1pt] (6,5.812) -- (6,0);
\end{tikzpicture}
\end{minipage}
\end{center}
\end{document}
答案1
我建议不要明确设置字体大小,而是使用例如\large
或变体。-不明确设置线宽,而是使用thick
或变体。-不使用,color=black
因为黑色是默认颜色。ellipse
总是绘制一个完整的椭圆来绘制一部分,你可以使用arc
。对于\fill
一个区域,它需要是一条完全封闭的曲线。-首先用画一条封闭曲线\draw
,然后用替换\draw
。\fill
这是一个开始:
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[->] (-2,0) -- (4,0) node[right] {(1)};
\draw[->] (0,-3) -- (0,3) node[above] {(2)};
\draw[color=red!80!black] (-1,0.4) arc [x radius=0.2, y radius=0.4, start angle=90, end angle=270];
\draw[color=red!80!black, densely dotted] (-1,0.4) arc [x radius=0.2, y radius=0.4, start angle=90, end angle=-90];
\draw (-1,-0.2) node {a};
\draw[color=red!80!black] (3,0) ellipse [x radius=0.2, y radius=1];
\draw (3,-0.2) node {b};
\draw[blue, thick] (-1.4,0.3) to[out=10, in=190] (-1,0.4) to[out=10, in=210] (3,1) to[out=30, in=240] (4,1.5);
\fill[red!50!yellow, opacity=0.5] (-1,-0.4) arc [x radius=0.2, y radius=0.4, start angle=-90, end angle=-270] to[out=10, in=210] (3,1) arc [x radius=0.2, y radius=1, start angle=90, end angle=-90] to[out=150, in=-10] cycle;
\end{tikzpicture}
\end{document}