Function Repository Resource:

SphericalPolygon

Source Notebook

Represent a spherical polygon

Contributed by: Jan Mangaldan

ResourceFunction["SphericalPolygon"][{p1,,pn}]

represents a filled spherical polygon with points pi on a sphere centered at the origin.

ResourceFunction["SphericalPolygon"][c,{p1,,pn}]

represents a filled spherical polygon on a sphere centered at the point c.

Details and Options

ResourceFunction["SphericalPolygon"] can be used as a graphics primitive.
ResourceFunction["SphericalPolygon"] returns a GraphicsComplex object and not a Polygon.
The points pi must all have dimension 3 and must all lie in a sphere centered at c.
The following options can be given:
"EdgeStyle"Blackstyle to use for edges
"ShowEdges"Falsewhether to show the edges

Examples

Basic Examples (2) 

A spherical triangle:

In[1]:=
spt = ResourceFunction[
   "SphericalPolygon"][{{Sqrt[2], -Sqrt[6], 1}, {Sqrt[2], Sqrt[6], 1}, {-2 Sqrt[2], 0, 1}}];

Show the spherical triangle:

In[2]:=
Graphics3D[spt]
Out[2]=

A spherical rectangle:

In[3]:=
spr = ResourceFunction[
   "SphericalPolygon"][{{0, -1, 0}, {1, 0, 0}, {Sqrt[3]/2, 0, 1/
     2}, {0, -(Sqrt[3]/2), 1/2}}];

Show the spherical rectangle:

In[4]:=
Graphics3D[spr]
Out[4]=

Scope (2) 

A spherical polygon with a specified sphere center:

In[5]:=
sp = ResourceFunction[
   "SphericalPolygon"][{1., -2., 3.}, {{2.5, -2., 3.}, {1., -2., 4.5}, {1., -3.5, 3.}}];

Show the polygon on a sphere:

In[6]:=
Graphics3D[{{Opacity[0.4], Sphere[{1., -2., 3.}, 1.5]}, sp}]
Out[6]=

Use directives to specify the face colors:

In[7]:=
Graphics3D[{Blue, ResourceFunction[
   "SphericalPolygon"][{{1., 0., 0.}, {0., 0., 1.}, {0., -1., 0.}}]}]
Out[7]=
In[8]:=
Graphics3D[{FaceForm[Blue, Yellow], ResourceFunction[
   "SphericalPolygon"][{{0., 1., 0.}, {-1., 0., 0.}, {0., 0., 1.}}]}]
Out[8]=

Options (3) 

EdgeStyle (2) 

Specify the style of the edges:

In[9]:=
Graphics3D[
 ResourceFunction[
  "SphericalPolygon"][{{0, -1, 0}, {1, 0, 0}, {Sqrt[3]/2, 0, 1/
    2}, {0, -(Sqrt[3]/2), 1/2}}, "EdgeStyle" -> Directive[Thick, Pink], "ShowEdges" -> True]]
Out[9]=

Specify face and edge styling:

In[10]:=
Graphics3D[{Brown, ResourceFunction[
   "SphericalPolygon"][{{0, -1, 0}, {1, 0, 0}, {Sqrt[3]/2, 0, 1/
     2}, {0, -(Sqrt[3]/2), 1/2}}, "EdgeStyle" -> Directive[Thick, Pink], "ShowEdges" -> True]}]
Out[10]=

ShowEdges (1) 

Show the edges of the spherical polygon:

In[11]:=
Graphics3D[
 ResourceFunction[
  "SphericalPolygon"][{{0, -1, 0}, {1, 0, 0}, {Sqrt[3]/2, 0, 1/
    2}, {0, -(Sqrt[3]/2), 1/2}}, "ShowEdges" -> True]]
Out[11]=

Properties and Relations (1) 

SphericalPolygon returns a GraphicsComplex object:

In[12]:=
ResourceFunction[
  "SphericalPolygon"][{{1., 0., 0.}, {0., 0., 1.}, {0., -1., 0.}}] // Head
Out[12]=

Possible Issues (3) 

Consecutive vertices of SphericalPolygon cannot be antipodal points:

In[13]:=
ResourceFunction[
 "SphericalPolygon"][{{-1., 0., 0.}, {1., 0., 0.}, {0., 0., 1.}}]
Out[13]=

SphericalPolygon does not directly support spherical digons:

In[14]:=
ResourceFunction["SphericalPolygon"][{{-1., 0., 0.}, {1., 0., 0.}}]
Out[14]=

To render a spherical digon, add the midpoints of the edges:

In[15]:=
Graphics3D[{ResourceFunction[
   "SphericalPolygon"][{{-1., 0., 0.}, {0., -1., 0.}, {1., 0., 0.}, {0., -1/Sqrt[2.], 1/Sqrt[2.]}}]}]
Out[15]=

SphericalPolygon is best used for convex spherical polygons. Concave polygons might display artifacts:

In[16]:=
Graphics3D[{ResourceFunction["SphericalPolygon"][
   N@{{0, -1, 0}, {2/Sqrt[17], -(2/Sqrt[17]), 3/Sqrt[17]}, {1, 0, 0}, {0, 0, 1}}]}]
Out[16]=

Split the concave spherical polygon into two spherical triangles:

In[17]:=
Graphics3D[{{ResourceFunction["SphericalPolygon"][
    N@{{0, -1, 0}, {2/Sqrt[17], -(2/Sqrt[17]), 3/Sqrt[17]}, {0, 0, 1}}], ResourceFunction["SphericalPolygon"][
    N@{{2/Sqrt[17], -(2/Sqrt[17]), 3/Sqrt[17]}, {1, 0, 0}, {0, 0, 1}}]}}]
Out[17]=

Neat Examples (2) 

Random triangulation of a sphere:

In[18]:=
pts = Normalize /@ RandomVariate[NormalDistribution[], {24, 3}];
tris = MeshCells[ConvexHullMesh[pts], 2][[All, 1]];
In[19]:=
Graphics3D[
 MapIndexed[{ColorData[97] @@ #2, ResourceFunction["SphericalPolygon"][pts[[#]], "ShowEdges" -> True]} &, tris], Boxed -> False, Lighting -> "Neutral"]
Out[19]=

Use SphericalPolygon to depict a soccer ball:

In[20]:=
tricFacs = First /@ First[
    Normal[MapAt[Map[Normalize, #] &, N[PolyhedronData["TruncatedIcosahedron", "GraphicsComplex"]], 1]]];
In[21]:=
Graphics3D[
 Map[{GrayLevel[If[Length[#] == 5, 0, 0.8]], ResourceFunction["SphericalPolygon"][#, "EdgeStyle" -> GrayLevel[0.4], "ShowEdges" -> True]} &, tricFacs], Boxed -> False, Lighting -> "Neutral"]
Out[21]=

Version History

  • 1.1.0 – 14 June 2021
  • 1.0.0 – 02 February 2021

Related Resources

Author Notes

Support for spherical coordinates will be added later.

License Information