0

I apologize if this has an answer elsewhere; I've looked at many questions and could not find a solution.

Here are some of the posts I looked at (maybe they do answer it and I'm just not smart enough to see it - that's always possible):

  1. Drawing simple 3D cylinders in TikZ
  2. 3D bodies in TikZ
  3. Draw a 3D sphere with radius with TikZ?
  4. Drawing a circle on a non xy-plane with TikZ

I even looked at the rotate= option described in this article to no avail: https://latexdraw.com/rotate-a-path-around-a-point-double-pendulum-case/

My question is this: How can you rotate a TikZ path in 3D? If this is impossible, then how can you fill a 3D sphere to achieve the same effect? If both of these ideas are impossible of execution, then how can I do this? For instance, do I need to "use a sledgehammer to crack a nut" and use TikZ-3Dplot? I'm willing to do whatever it takes. Thank you in advance for your help.

As you can see, the ellipse is parallel with the xy-plane. My goal is to rotate this ellipse - or just draw it as a sphere, if possible - so that it appears as a circle to the viewer.

enter image description here

MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{perspective}
\begin{document}
\begin{tikzpicture}[3d view={125}{30}, scale=4]
\draw[thick, -latex] (0,0,0) -- (2,0,0) node[pos=1,above left]{$x$};
\draw[thick, -latex] (0,0,0) -- (0,2,0) node[pos=1,below left]{$y$};
\draw[thick, -latex] (0,0,0) -- (0,0,2) node[pos=1,left]{$z$};
\node[above left] at (0,0,0) {$O$};
\draw[red,thick] (0,0,0) -- node[pos=0.5,above left] {\color{black}$a$} (0.65,0,0) -- node[pos=0.5,below left] {\color{black}$b$} (0.65,0.75,0) -- node[pos=0.5,right] {\color{black}$c$} (0.65,0.75,1.2);
\fill[red] (0.65,0.75,1.2) circle [radius=0.5];
\foreach \x in {0,0.05,...,2}{
\draw[thin] (\x,0,1.2) -- (\x,2,1.2);
\draw[thin] (0,\x,1.2) -- (2,\x,1.2);}
%\fill[red,3d view={0}{0}] (0.65,0.75,1.2) circle [radius=0.03]; % I would like to do something like this
\end{tikzpicture}
\end{document}

Thanks!

2 Answers2

0

This one could be a (simplified) answer to Your's question:

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{perspective}
\begin{document}
    \begin{tikzpicture}[3d view={125}{30}, scale=2]
        \draw[thick, -latex] (0,0,0) -- (4,0,0) node[pos=1,above left]{$x$};
        \draw[thick, -latex] (0,0,0) -- (0,4,0) node[pos=1,below left]{$y$};
        \draw[thick, -latex] (0,0,0) -- (0,0,4) node[pos=1,left]{$z$};
        \node[above left] at (0,0,0) {$O$};
%       \draw[red,thick] (0,0,0) -- node[pos=0.5,above left] {\color{black}$a$} (0.65,0,0) -- node[pos=0.5,below left] {\color{black}$b$} (0.65,0.75,0) -- node[pos=0.5,right] {\color{black}$c$} (0.65,0.75,1.2);
        \draw[blue] (0,0,0) circle [radius=2];
        \foreach \r in {-2,-1.9,...,2}{
        \pgfmathsetmacro{\raggio}{sqrt(4-\r*\r)}
        \fill[red,opacity=.1] (0,0,\r) circle [radius=\raggio];
        }

% \foreach \x in {0,0.05,...,2}{ % \draw[thin] (\x,0,1.2) -- (\x,2,1.2); % \draw[thin] (0,\x,1.2) -- (2,\x,1.2);} %\fill[red,3d view={0}{0}] (0.65,0.75,1.2) circle [radius=0.03]; % I would like to do something like this \end{tikzpicture} \end{document}

  • Thank you! I've been meaning to learn to interact with PGF one of these days - this is motivating me to get that fire lit under my chair :) –  Feb 09 '24 at 21:27
0

This is an answer I came up with, using spath3, and tikz-3dplot. Essentially, I make the shape around the origin, then translate it where I want. This problem reminded me of one that you guys helped me with a while back, and I was able to map the solution from that one onto this one. Here's the post I used as inspiration: How do you rotate paths made using the [use path=\name] option in TikZ?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{perspective,spath3}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{60}{135}
\begin{tikzpicture}[tdplot_main_coords, scale=4]
\draw[thick, -latex] (0,0,0) -- (2,0,0) node[pos=1,above left]{$x$};
\draw[thick, -latex] (0,0,0) -- (0,2,0) node[pos=1,below left]{$y$};
\draw[thick, -latex] (0,0,0) -- (0,0,2) node[pos=1,left]{$z$};
\node[above left] at (0,0,0) {$O$};
\draw[red,thick] (0,0,0) -- node[pos=0.5,above left] {\color{black}$a$} (0.65,0,0) -- node[pos=0.5,below left] {\color{black}$b$} (0.65,0.75,0) -- node[pos=0.5,right] {\color{black}$c$} (0.65,0.75,1.2);
\tdplotsetrotatedcoords{60}{60}{0}
\path[tdplot_rotated_coords,spath/save=name] (0,0,0) circle [radius=0.1];
\path[fill,red,spath/use={name, transform={shift={(4*0.65,4*0.75,4*1.2)}}}];
\end{tikzpicture}
\end{document}

enter image description here