我画了这幅画
\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{tikz-3dplot}
\usepackage{hyperref}
\usepackage{ifthen}
\usepackage{pgfplots}
\usetikzlibrary{calc,3d,intersections, positioning,intersections,shapes}
\pgfplotsset{compat=1.11}
\newcommand\DrawVect[5]
{
\def\xt{#1}
\def\yt{#2}
\def\zt{#3}
\def\mycolor{#4}
\def\myR{#5}
% end of vector
\pgfmathsetmacro{\xte}{\myR*\xt}
\pgfmathsetmacro{\yte}{\myR*\yt}
\pgfmathsetmacro{\zte}{\myR*\zt}
\pgfmathsetmacro{\xtet}{\myR*\xt + \xt/\myR}
\pgfmathsetmacro{\ytet}{\myR*\yt + \yt/\myR}
\pgfmathsetmacro{\ztet}{\myR*\zt + \zt/\myR}
\draw[-latex, color=\mycolor, line width=1] (\xte,\yte,\zte) -- (\xtet , \ytet ,\ztet);
}
\newcommand\getEquator[2]
{
\def\yt{#1}
\def\zt{#2}
\pgfmathsetmacro{\betav}{acos(\zt)};
\def\gammav{0}
\ifthenelse{\equal{\betav}{0.0}}
{
\def\alphav{0}
}
{
\pgfmathsetmacro{\alphav}{asin(\yt/(sin(\betav))}
};
}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.0]
\tdplotsetmaincoords{80}{110}
\pgfmathsetmacro\R{sqrt(3)}
\coordinate (O) at (0,0,0);
\fill[ball color=white!10, opacity=0.2] (O) circle (\R); % 3D lighting effect
\begin{scope}[tdplot_main_coords, shift={(0,0)}]
\pgfmathsetmacro\R{sqrt(3)}
\pgfmathsetmacro{\thetavec}{0};
\pgfmathsetmacro{\phivec}{0};
\pgfmathsetmacro{\gammav}{0};
\tdplotsetrotatedcoords{\phivec}{\thetavec}{\gammav};
\def\x{0};
\def\y{0};
\def\z{1};
\def\colr{red}
\DrawVect{\x}{\y}{\z}{\colr}{\R};
\getEquator{\y}{\z};
\tdplotsetrotatedcoords{\alphav}{\betav}{\gammav};
\tdplotdrawarc[tdplot_rotated_coords,color=\colr]{(O)}{\R}{0}{360}{}{};
%axis
\coordinate (X) at (5,0,0) ;
\coordinate (Y) at (0,3,0) ;
\coordinate (Z) at (0,0,3) ;
\draw[-latex] (O) -- (X) node[anchor=west] {$X$};
\draw[-latex] (O) -- (Y) node[anchor=north] {$Y$};
\draw[-latex] (O) -- (Z) node[anchor=south west] {$Z$};
% compute the equator in a different way.
\end{scope}
\end{tikzpicture}
\end{center}
\end{document}
看起来像这样
我希望红线现在沿着赤道,并且带有一些标签。我该怎么做?
它看起来应该是这样的:
答案1
只要你在 xy 平面上,只需画一个具有适当中心和半径的圆。
\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{tikz-3dplot}
\usepackage{hyperref}
\usepackage{ifthen}
\usepackage{pgfplots}
\usetikzlibrary{calc,3d,intersections, positioning,intersections,shapes}
\pgfplotsset{compat=1.11}
\newcommand\DrawVect[5]
{
\def\xt{#1}
\def\yt{#2}
\def\zt{#3}
\def\mycolor{#4}
\def\myR{#5}
% end of vector
\pgfmathsetmacro{\xte}{\myR*\xt}
\pgfmathsetmacro{\yte}{\myR*\yt}
\pgfmathsetmacro{\zte}{\myR*\zt}
\pgfmathsetmacro{\xtet}{\myR*\xt + \xt/\myR}
\pgfmathsetmacro{\ytet}{\myR*\yt + \yt/\myR}
\pgfmathsetmacro{\ztet}{\myR*\zt + \zt/\myR}
\draw[-latex, color=\mycolor, line width=1] (\xte,\yte,\zte) -- (\xtet , \ytet ,\ztet);
}
\newcommand\getEquator[2]
{
\def\yt{#1}
\def\zt{#2}
\pgfmathsetmacro{\betav}{acos(\zt)};
\def\gammav{0}
\ifthenelse{\equal{\betav}{0.0}}
{
\def\alphav{0}
}
{
\pgfmathsetmacro{\alphav}{asin(\yt/(sin(\betav))}
};
}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.0]
\tdplotsetmaincoords{80}{110}
\pgfmathsetmacro\R{sqrt(3)}
\coordinate (O) at (0,0,0);
\fill[ball color=white!10, opacity=0.2] (O) circle (\R); % 3D lighting effect
\begin{scope}[tdplot_main_coords, shift={(0,0)}]
\pgfmathsetmacro\R{sqrt(3)}
\pgfmathsetmacro{\thetavec}{0};
\pgfmathsetmacro{\phivec}{0};
\pgfmathsetmacro{\gammav}{0};
\tdplotsetrotatedcoords{\phivec}{\thetavec}{\gammav};
\def\x{0};
\def\y{0};
\def\z{1};
\def\colr{red}
\DrawVect{\x}{\y}{\z}{\colr}{\R};
\getEquator{\y}{\z};
%\tdplotsetrotatedcoords{\alphav}{\betav}{\gammav};
%\tdplotdrawarc[tdplot_rotated_coords,color=\colr]{(O)}{\R}{0}{360}{}{};
\draw[\colr] (0,0,0) circle[radius=\R];
\def\latitude{30}
\pgfmathsetmacro{\Rl}{\R*cos(\latitude)}
\pgfmathsetmacro{\zl}{\R*sin(\latitude)}
\draw[green] (0,0,\zl) circle[radius=\Rl];
%axis
\coordinate (X) at (5,0,0) ;
\coordinate (Y) at (0,3,0) ;
\coordinate (Z) at (0,0,3) ;
\draw[-latex] (O) -- (X) node[anchor=west] {$X$};
\draw[-latex] (O) -- (Y) node[anchor=north] {$Y$};
\draw[-latex] (O) -- (Z) node[anchor=south west] {$Z$};
% compute the equator in a different way.
\end{scope}
\end{tikzpicture}
\end{center}
\end{document}