
2 つの軸を中心に円を回転させようとしています。円は赤いベクトルに対して垂直に配置する必要があります。
コード:
\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% xyz axes
\draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,5,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,5) node[anchor=north west]{$z$};
% vector
\draw[->,red] (0,0,0) -- (4,4,4);
% center of circle
\fill (3,3,3) circle (1pt);
% circle
\draw (3,3,3) circle (3); % rotation?
\end{tikzpicture}
\end{document}
出力:
赤いベクトルと円が互いに垂直になるように円を回転させる方法を知りたいです。y軸を中心に45°、z軸を中心に45°回転すると思いますが、これをtikzを使用してどのように実現できるでしょうか?
答え1
使用することをお勧めしますtikz-3dplot
もしTikZ は、2D で描画するように設計されたパッケージで 3D を偽装するために必要な計算の多くを処理するため、実際に使用することをお勧めします。
例えば:
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\tdplotsetrotatedcoords{180}{-90}{-90}
\begin{tikzpicture}[tdplot_main_coords]
\begin{scope}[tdplot_rotated_coords]
\draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,5,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,5) node[anchor=north west]{$z$};
\draw[->,red] (0,0,0) -- (4,4,4);
\path [fill] (3,3,3) coordinate (c) circle (1pt);
\tdplotdrawarc[tdplot_rotated_coords]{(c)}{3}{0}{360}{}{}
\end{scope}
\end{tikzpicture}
\end{document}
円に陰影を付けて奥行き感を出したい場合は、ライブラリを使用してbackgrounds
描画順序に注意します。例:
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds}
\begin{document}
\tdplotsetmaincoords{70}{110}
\tdplotsetrotatedcoords{180}{-90}{-90}
\begin{tikzpicture}[tdplot_main_coords]
\begin{scope}[tdplot_rotated_coords]
\draw[thick,->] (0,0,0) coordinate (o) -- (5,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (o) -- (0,5,0) node[anchor=north west]{$y$};
\draw[thick,->] (o) -- (0,0,5) node[anchor=north west]{$z$};
\draw[red] (o) -- (3,3,3) coordinate (c);
\path [fill] (c) circle (1pt);
\begin{scope}[on background layer]
\draw[->,red] (c) -- (4,4,4);
\tdplotdrawarc[tdplot_rotated_coords, right color=blue!50!cyan, left color=blue!50!cyan!15!white, fill opacity=.25, postaction={top color=blue!50!cyan!15!white, bottom color=blue!50!cyan, fill opacity=.25}]{(c)}{3}{0}{360}{}{}
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}