在我之前的帖子中转移球体,我有两个球体,它们被从texexamples.net
在左下方,有一个球体,有一条射线从球体中心到球体的半径。
我不知道代码是什么。我想在更大的球体(左侧)上生成一条射线。
我不确定该怎么做,因为那个代码对我来说有点多。
答案1
我不确定这是否是所需的射线:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,fadings,decorations.pathreplacing}
%% helper macros
\newcommand\pgfmathsinandcos[3]{%
\pgfmathsetmacro#1{sin(#3)}%
\pgfmathsetmacro#2{cos(#3)}%
}
\newcommand\LongitudePlane[3][current plane]{%
\pgfmathsinandcos\sinEl\cosEl{#2} % elevation
\pgfmathsinandcos\sint\cost{#3} % azimuth
\tikzset{#1/.estyle={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
}
\newcommand\LatitudePlane[3][current plane]{%
\pgfmathsinandcos\sinEl\cosEl{#2} % elevation
\pgfmathsinandcos\sint\cost{#3} % latitude
\pgfmathsetmacro\yshift{\cosEl*\sint}
\tikzset{#1/.estyle={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} %
}
\newcommand\DrawLongitudeCircle[2][1]{
\LongitudePlane{\angEl}{#2}
\tikzset{current plane/.prefix style={scale=#1}}
% angle of "visibility"
\pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
\draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
\draw[current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
}
\newcommand\DrawLatitudeCircle[2][1]{
\LatitudePlane{\angEl}{#2}
\tikzset{current plane/.prefix style={scale=#1}}
\pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
% angle of "visibility"
\pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
\draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1);
\draw[current plane,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}
%% document-wide tikz options and styles
\tikzset{%
>=latex, % option for nice arrows
inner sep=0pt,%
outer sep=2pt,%
mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt,
fill=black,circle}%
}
\begin{document}
\begin{tikzpicture} % "THE GLOBE" showcase
\def\R{2.5} % sphere radius
\def\angEl{35} % elevation angle
\def\angPhi{-48} % longitude of point P
\def\angBeta{-164} % latitude of point P
\filldraw[ball color=white] (0,0) circle (\R);
\foreach \t in {-80,-60,...,80} { \DrawLatitudeCircle[\R]{\t} }
\foreach \t in {-5,-35,...,-175} { \DrawLongitudeCircle[\R]{\t} }
\pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
\LongitudePlane[pzplane]{\angEl}{\angPhi}
\node[label=above:$\mathbf{O}$] (O) at (0,0) {};
\path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P);
\draw[->] (O) -- (P) node[above right] {$\mathbf{P}$};
\end{tikzpicture}
\end{document}
答案2
您可以使用以下tikz-3dplot-circleofsphere
包这里
\documentclass[tikz,border=1mm, 12 pt]{standalone}
\usepackage{tikz-3dplot-circleofsphere}
\begin{document}
\def\r{3}
\tdplotsetmaincoords{60}{125}
\begin{tikzpicture}[tdplot_main_coords]
\path
(0,0,0) coordinate (O)
({\r*sin(80)}, {\r*cos(80)},\r) coordinate (A) ;
\fill[ball color=gray!10,tdplot_screen_coords] (O) circle (\r);
\foreach \a in {-75,-60,...,75}
{\tdplotCsDrawLatCircle[]{\r}{\a}}
\foreach \a in {0,15,...,165}
{\tdplotCsDrawLonCircle[]{\r}{\a}}
\draw[->,thick, blue] (O) -- (A);
\foreach \p in {A,O}
\draw[fill=black] (\p) circle (1.5pt);
\foreach \p/\g in {A/135,O/-90}
\path (\p)+(\g:3mm) node{$\p$};
\end{tikzpicture}
\end{document}