2

In my previous post shifting a sphere, I have two spheres which were lifted from texexamples.net

On the left bottom side, there is a sphere with a ray from the center to the radius of the sphere.

I can't figure out what the code was for that. I would like to generate a ray on my bigger sphere (left side).

I am not sure how though since that code is a little much for me.

7
  • @GonzaloMedina I had the wrong link up for texexamples.
    – dustin
    Commented Apr 26, 2013 at 1:54
  • Are you referring to the line NP? Commented Apr 26, 2013 at 1:57
  • @GonzaloMedina the line from the origin that forms the angle beta. bottom left picture
    – dustin
    Commented Apr 26, 2013 at 2:01
  • It's the line OP, I think. \draw[->] (O) -- (P); in the linked texamples.net post.
    – hpesoj626
    Commented Apr 26, 2013 at 2:06
  • @hpesoj626 that is the bottom right picture that has O to P.
    – dustin
    Commented Apr 26, 2013 at 2:10

2 Answers 2

2

I am not sure if this is the desired ray:

\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}

enter image description here

10
  • what piece of code are speaking of? Isn't that the whole code from the page?
    – dustin
    Commented Apr 26, 2013 at 2:18
  • @dustin Sorry about that. I pasted the wrong code. Fixed now. Commented Apr 26, 2013 at 2:21
  • how can rotate arrow head along the latitude axis -180?
    – dustin
    Commented Apr 26, 2013 at 2:23
  • @dustin change the value of \angBeta, for example: \def\angBeta{-171}. (I hope this is what you wanted). Commented Apr 26, 2013 at 2:29
  • 1
    @dustin replace \path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P); with \path[pzplane] (\angBeta:\R) coordinate (P); Commented Apr 26, 2013 at 2:50
3

You can use package tikz-3dplot-circleofsphere at here

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .