Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

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

1 Answer 1

up vote 2 down vote accepted

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.