I made the following ellipse in Inkscape
But I would like to draw it within TikZ environment.My final goal is to put this ellipse inside a coordinate system. Using the image from Inkscape, here is my try
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,shapes.geometric,shadows.blur}
\usepackage{graphicx}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
\def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
\def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
\def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
\tikz@canvas@is@plane}
\makeatother
\begin{document}
\tdplotsetmaincoords{60}{130}
\begin{tikzpicture}[scale=3.2,tdplot_main_coords,>=latex,line join=bevel]
\coordinate (O) at (0,0,0);
\draw[thick,->] (O) -- (1.2,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (O) -- (0,1.2,0) node[anchor=north west]{$y$};
\draw[thick,->] (O) -- (0,0,1.2) node[anchor=south]{$z$};
\draw[dashed] (O) -- (-1.2,0,0);
\pgfmathsetmacro{\rvec}{1.5}
\pgfmathsetmacro{\thetavec}{40}
\pgfmathsetmacro{\phivec}{60}
\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
\node[anchor=south west,color=red] at (P) {$B$};
\draw[-stealth,color=red,very thick] (O) -- (P);
\begin{scope}[canvas is yz plane at x=0]
\node[] (elliL) at (0,0) {\includegraphics[width=.1\textwidth]{image.eps}};
\end{scope}
\end{tikzpicture}
\end{document}
Using Tikz my best attempt was
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,shapes.geometric,shadows.blur}
\usepackage{graphicx}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
\def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
\def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
\def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
\tikz@canvas@is@plane}
\makeatother
\begin{document}
\tdplotsetmaincoords{60}{130}
\begin{tikzpicture}[scale=3.2,tdplot_main_coords,>=latex,line join=bevel]
\coordinate (O) at (0,0,0);
\draw[thick,->] (O) -- (1.2,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (O) -- (0,1.2,0) node[anchor=north west]{$y$};
\draw[thick,->] (O) -- (0,0,1.2) node[anchor=south]{$z$};
\draw[dashed] (O) -- (-1.2,0,0);
\pgfmathsetmacro{\rvec}{1.5}
\pgfmathsetmacro{\thetavec}{40}
\pgfmathsetmacro{\phivec}{60}
\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
\node[anchor=south west,color=red] at (P) {};
\draw[-stealth,color=red,very thick] (O) -- (P);
\begin{scope}[canvas is xz plane at y=0]
\node[ellipse,fill=gray,fill opacity=0.3,draw,minimum width=2cm,minimum height=1cm,rotate=90] (elliL) at (0,0) {};
\end{scope}
\end{tikzpicture}
\end{document}
Best Answer
This problem is actually less innocent than it might seem. The visible part of the ellipse is not obtained by just drawing an ellipse of the dimensions of the ellipsoid in the screen coordinates or, say, the xy plane. The problem as AFAIK only been used for the sphere, see e.g. the nice macros by Alain Matthes provided for a sphere and, in particular, this great answer by Fritz. Let me start by providing a brute force way to shade the relevant area.
A somewhat more analytic variant thereof is
This is an ellipsoid in perspective, see e.g.
to note that you view on the ellipsoid from the top, as dictated by the angle
theta=60
in\tdplotsetmaincoords{60}{130}
.