I would like to ask, how to place ellipse into any object, so that the length of the main arm is defined by line1
(point A, B) in my code:
- calculate the coordinates of the ellipse midpoint
- rotation angle of the ellipse
- length of the main arm of the ellipse.
Code is:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections, calc}
\begin{document}
\begin{figure}[hb!]
\centering
\begin{tikzpicture}
\draw[xstep=0.5, ystep=0.5, dashed, color=gray] (-1,-1) grid (5,5);
\draw[->] (0,0) -- (7,0) node[right] {$x$};
\draw[->] (0,0) -- (0,7) node[above] {$y$};
\coordinate (dS) at (2,0.5);
\shade[name path=teleso,ball color=blue!10!white,opacity=0.50,line width=1,draw=black] plot [smooth cycle] coordinates
{(0,0) (1,-1) (3,0) (2.5,2) (3,3) (3,4) (2,5) (-1,3) };
\draw (3,4) node[right]{S};
% ploska dS
\shade[bottom color=black,top color=black!50!blue!35](dS) node[below]{$dS$} rectangle +(0.5,0.5);
\draw[->] (dS) ++ (0.25,0.25) -- +(1,0.5) node[right]{$\vec{n}$};
\draw[->] (dS) ++ (0.25,0.25) -- +(2,1.5) node[right]{$\vec{h}$};
\draw[fill=black] (2,3) circle (0.05) node[above, black]{$objem$};
\draw[name path=line1](-1.5,3.5) -- (3,1.5);
% Intersections
\path [name intersections={of=teleso and line1, name=cross}] ;
\foreach \i in {1,2}
\fill [color=red] (cross-\i) circle (2pt) ;
% ellipse
\coordinate [label=left:$A$] (A) at (cross-1);
\coordinate [label=right:$B$] (B) at (cross-2);
\draw[red,line width=1mm]
let \p1 = ($(B)-(A)$) in (A) -- ++(45:({veclen(\x1,\y1)}););
\fill [color=cyan, opacity=0.25]
($ (A)!0.5!(B) $) ellipse (2cm and 1cm);
\end{tikzpicture}
\end{figure}
\end{document}
Picture still looks as follows: