2

I'm having some problems drawing ellipse in tikz. Can someone help(show) me, how I can make a graph like this?

The graph

I hope someone. could lead me on the way.

  1. I can not find out to make some area a color, like between "a" and "b".
  2. And the cylinder between "x_0" and "x" with the Oblique lines.
  3. I can not find out to make half of the ellipse dashed like around "a"

My code so far:

\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}

SebGlav
  • 19,186
Jakob Kruse
  • 229
  • 1
  • 10

1 Answers1

1

I would recommend not setting the font size explicitly, but use e.g. \large or variants. -not setting line width explicitly, but use thick or variants. -not using color=black as black is default color. ellipse always draws a full ellipse to draw a part, you can use arc. To \fill an area, it needs to be a fully closed curve. -first make a closed curve with \draw and then replace \draw with \fill. Here is a start:

\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}

Graph

  • Hey, and thank you so far. What does it mean when you write fx [out=10, in=190] – Jakob Kruse Jul 03 '21 at 21:12
  • \draw (0,0) to[out=10, in=190] (1,1); makes a curve going from (0,0) to (1,1). Leaving (0,0) at an angle of 10 deg and going into (1,1) at an angle of 200. You can read about different ways of making curves in TikZ including to here: https://tex.stackexchange.com/questions/33607/easy-curves-in-tikz – hpekristiansen Jul 03 '21 at 21:51
  • 190 - not 200.. – hpekristiansen Jul 03 '21 at 21:57