3

I would like to shade (with a darker shade) a triangle on the surface of a sphere. Take one of the samples at TeXample

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fadings,decorations.pathreplacing}

\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/.style={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/.style={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);
}

\begin{document}

\begin{tikzpicture}

\def\R{2.5} % sphere radius
\def\angEl{35} % elevation angle
\filldraw[ball color=white] (0,0) circle (\R);
\foreach \t in {0} { \DrawLatitudeCircle[\R]{\t} }
\foreach \t in {-5,-35,...,-175} { \DrawLongitudeCircle[\R]{\t} }

\end{tikzpicture}

\end{document}

which produces several surface triangle sectors as in:

Sphere with 3-gons

Is it possible to shade a particular 3-gon (with a different shade) on the surface of the sphere instead of the 3-space where they live in? Is it possible to shade or color a "triangle" that is not made out of straight lines and the region that it bound is NOT contained on a plane?

The question is different from How to draw spherical triangles because it is specific about TikZ and the way Tikz shades areas limited by arcs. The answers to the above named are in Asymptote and PSTricks.

  • 2
    Possible duplicate of How to draw spherical triangles? – Cragfelt Nov 20 '17 at 19:03
  • 2
    @Cragfelt, I would say - not! The answers there are on Asymptote and PSTricks. This question is about TikZ specifically. – Alberto G. Nov 20 '17 at 20:16
  • Maybe the information on this article could be useful. (See the links at the bottom) eclecticcats.wordpress.com/2016/06/23/… – Cragfelt Nov 20 '17 at 22:31
  • @Cragfelt, the reference does touch on the issue of sketching the triangles on the sphere, but not of shading it, or coloring it any different from the whole sphere. – Alberto G. Nov 20 '17 at 22:53
  • 1
    What have you tried? So far you have just pasted the code from TeXample here and asked us to do the work for you. Sorry, but it's “unclear what you are asking.” – Henri Menke Nov 21 '17 at 2:42

Browse other questions tagged or ask your own question.