4

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
  • 2
    @Cragfelt, I would say - not! The answers there are on Asymptote and PSTricks. This question is about TikZ specifically. – user148677 Nov 20 '17 at 20:16
  • Maybe the information on this article could be useful. (See the links at the bottom) https://eclecticcats.wordpress.com/2016/06/23/tikzpgf-part-3-drawing-a-sphere/ – 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. – user148677 Nov 20 '17 at 22:53
  • If you add a scope, set the clip path to be the arcs, then draw a new ball shading... – John Kormylo Nov 20 '17 at 23:52
  • @JohnKormylo, I tried that, it would be the natural thing to do, but I am not sure a clip path can live outside of a plane. – user148677 Nov 21 '17 at 00:58
  • As far as I can tell, you are not using 3D coordinates, just a bunch of very confusing transformations. – John Kormylo Nov 21 '17 at 01:08
  • 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 02:42
  • @HenriMenke Unclear! You ought to be kidding, no? I am going to add to the main text, but the question seems very clear - Is it possible and how to, shade a triangle that is not made out of straight lines and does not lie on a plane - like for example, lying on the surface of a sphere. – user148677 Nov 21 '17 at 16:26
  • I think the main idea on Henri Menke's comment was to state the importance of showing the work you have done so far, not only waiting for us to solve it. You can try to clarify your question (it was clear at the very beginning), however it is difficult to design this such of figure without any starting point besides a pasted code with no additional effort. – Cragfelt Nov 21 '17 at 18:57
  • Well, it is not so easy to show work for something that I am starting to believe it is - impossible - at least with the standard tools provided by TikZ. You see... a closed circuit encloses one area in the plane, but not on general surfaces - take two parallel collar circles on the torus and it is easy to see there are two distinct regions limited by them... and so the region to be shaded will depend on the ambient topology of the surface. – user148677 Nov 21 '17 at 19:35
  • I found this question. It may help you https://tex.stackexchange.com/questions/380316/gray-shaded-sphere-with-tikz-3dplot – Cragfelt Dec 15 '17 at 23:47

0 Answers0